2 # Tcl ignores the next line -*- tcl -*- \
3 if test "z$*" = zversion \
4 || test "z$*" = z--version; \
6 echo 'git-gui version @@GITGUI_VERSION@@'; \
10 exec wish "$argv0" -- "$@"
12 set appvers {@@GITGUI_VERSION@@}
14 Copyright © 2006, 2007 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]
41 -title [mc "git-gui: fatal error"] \
46 catch {rename send {}} ; # What an evil concept...
48 ######################################################################
52 set oguilib {@@GITGUI_LIBDIR@@}
53 set oguirel {@@GITGUI_RELATIVE@@}
54 if {$oguirel eq {1}} {
55 set oguilib [file dirname [file dirname [file normalize $argv0]]]
56 set oguilib [file join $oguilib share git-gui lib]
57 set oguimsg [file join $oguilib msgs]
58 } elseif {[string match @@* $oguirel]} {
59 set oguilib [file join [file dirname [file normalize $argv0]] lib]
60 set oguimsg [file join [file dirname [file normalize $argv0]] po]
62 set oguimsg [file join $oguilib msgs]
66 ######################################################################
68 ## enable verbose loading?
70 if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
72 rename auto_load real__auto_load
73 proc auto_load {name args} {
74 puts stderr "auto_load $name"
75 return [uplevel 1 real__auto_load $name $args]
77 rename source real__source
79 puts stderr "source $name"
80 uplevel 1 real__source $name
84 ######################################################################
86 ## Internationalization (i18n) through msgcat and gettext. See
87 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
89 package require msgcat
92 set fmt [::msgcat::mc $fmt]
93 set cmk [string first @@ $fmt]
95 set fmt [string range $fmt 0 [expr {$cmk - 1}]]
97 return [eval [list format $fmt] $args]
101 return [join $args {}]
104 ::msgcat::mcload $oguimsg
107 ######################################################################
111 set _appname {Git Gui}
128 return [eval [list file join $_gitdir] $args]
131 proc gitexec {args} {
133 if {$_gitexec eq {}} {
134 if {[catch {set _gitexec [git --exec-path]} err]} {
135 error "Git not installed?\n\n$err"
138 set _gitexec [exec cygpath \
143 set _gitexec [file normalize $_gitexec]
149 return [eval [list file join $_gitexec] $args]
157 if {[tk windowingsystem] eq {aqua}} {
164 if {$::tcl_platform(platform) eq {windows}} {
172 if {$_iscygwin eq {}} {
173 if {$::tcl_platform(platform) eq {windows}} {
174 if {[catch {set p [exec cygpath --windir]} err]} {
186 proc is_enabled {option} {
187 global enabled_options
188 if {[catch {set on $enabled_options($option)}]} {return 0}
192 proc enable_option {option} {
193 global enabled_options
194 set enabled_options($option) 1
197 proc disable_option {option} {
198 global enabled_options
199 set enabled_options($option) 0
202 ######################################################################
206 proc is_many_config {name} {
207 switch -glob -- $name {
216 proc is_config_true {name} {
218 if {[catch {set v $repo_config($name)}]} {
220 } elseif {$v eq {true} || $v eq {1} || $v eq {yes}} {
227 proc get_config {name} {
229 if {[catch {set v $repo_config($name)}]} {
236 ######################################################################
240 proc _git_cmd {name} {
243 if {[catch {set v $_git_cmd_path($name)}]} {
247 --exec-path { return [list $::_git $name] }
250 set p [gitexec git-$name$::_search_exe]
251 if {[file exists $p]} {
253 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
254 # Try to determine what sort of magic will make
255 # git-$name go and do its thing, because native
256 # Tcl on Windows doesn't know it.
258 set p [gitexec git-$name]
263 switch -glob -- [lindex $s 0] {
265 #!*perl { set i perl }
266 #!*python { set i python }
267 default { error "git-$name is not supported: $s" }
271 if {![info exists interp]} {
272 set interp [_which $i]
275 error "git-$name requires $i (not in PATH)"
277 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
279 # Assume it is builtin to git somehow and we
280 # aren't actually able to see a file for it.
282 set v [list $::_git $name]
284 set _git_cmd_path($name) $v
290 global env _search_exe _search_path
292 if {$_search_path eq {}} {
293 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
294 set _search_path [split [exec cygpath \
300 } elseif {[is_Windows]} {
301 set gitguidir [file dirname [info script]]
302 regsub -all ";" $gitguidir "\\;" gitguidir
303 set env(PATH) "$gitguidir;$env(PATH)"
304 set _search_path [split $env(PATH) {;}]
307 set _search_path [split $env(PATH) :]
312 foreach p $_search_path {
313 set p [file join $p $what$_search_exe]
314 if {[file exists $p]} {
315 return [file normalize $p]
321 proc _lappend_nice {cmd_var} {
325 if {![info exists _nice]} {
326 set _nice [_which nice]
337 switch -- [lindex $args 0] {
348 set args [lrange $args 1 end]
351 set cmdp [_git_cmd [lindex $args 0]]
352 set args [lrange $args 1 end]
354 return [eval $opt $cmdp $args]
357 proc _open_stdout_stderr {cmd} {
361 if { [lindex $cmd end] eq {2>@1}
362 && $err eq {can not find channel named "1"}
364 # Older versions of Tcl 8.4 don't have this 2>@1 IO
365 # redirect operator. Fallback to |& cat for those.
366 # The command was not actually started, so its safe
367 # to try to start it a second time.
369 set fd [open [concat \
370 [lrange $cmd 0 end-1] \
377 fconfigure $fd -eofchar {}
381 proc git_read {args} {
385 switch -- [lindex $args 0] {
400 set args [lrange $args 1 end]
403 set cmdp [_git_cmd [lindex $args 0]]
404 set args [lrange $args 1 end]
406 return [_open_stdout_stderr [concat $opt $cmdp $args]]
409 proc git_write {args} {
413 switch -- [lindex $args 0] {
424 set args [lrange $args 1 end]
427 set cmdp [_git_cmd [lindex $args 0]]
428 set args [lrange $args 1 end]
430 return [open [concat $opt $cmdp $args] w]
434 regsub -all ' $value "'\\''" value
438 proc load_current_branch {} {
439 global current_branch is_detached
441 set fd [open [gitdir HEAD] r]
442 if {[gets $fd ref] < 1} {
447 set pfx {ref: refs/heads/}
448 set len [string length $pfx]
449 if {[string equal -length $len $pfx $ref]} {
450 # We're on a branch. It might not exist. But
451 # HEAD looks good enough to be a branch.
453 set current_branch [string range $ref $len end]
456 # Assume this is a detached head.
458 set current_branch HEAD
463 auto_load tk_optionMenu
464 rename tk_optionMenu real__tkOptionMenu
465 proc tk_optionMenu {w varName args} {
466 set m [eval real__tkOptionMenu $w $varName $args]
467 $m configure -font font_ui
468 $w configure -font font_ui
472 proc rmsel_tag {text} {
474 -background [$text cget -background] \
475 -foreground [$text cget -foreground] \
477 $text tag conf in_sel -background lightgray
478 bind $text <Motion> break
483 bind . <Visibility> {
484 bind . <Visibility> {}
489 wm iconbitmap . -default $oguilib/git-gui.ico
492 ######################################################################
497 font create font_diff -family Courier -size 10
501 eval font configure font_ui [font actual [.dummy cget -font]]
505 font create font_uiitalic
506 font create font_uibold
507 font create font_diffbold
508 font create font_diffitalic
510 foreach class {Button Checkbutton Entry Label
511 Labelframe Listbox Menu Message
512 Radiobutton Spinbox Text} {
513 option add *$class.font font_ui
517 if {[is_Windows] || [is_MacOSX]} {
518 option add *Menu.tearOff 0
529 proc bind_button3 {w cmd} {
530 bind $w <Any-Button-3> $cmd
532 # Mac OS X sends Button-2 on right click through three-button mouse,
533 # or through trackpad right-clicking (two-finger touch + click).
534 bind $w <Any-Button-2> $cmd
535 bind $w <Control-Button-1> $cmd
539 proc apply_config {} {
540 global repo_config font_descs
542 foreach option $font_descs {
543 set name [lindex $option 0]
544 set font [lindex $option 1]
546 foreach {cn cv} $repo_config(gui.$name) {
547 font configure $font $cn $cv -weight normal
550 error_popup [strcat [mc "Invalid font specified in %s:" "gui.$name"] "\n\n$err"]
552 foreach {cn cv} [font configure $font] {
553 font configure ${font}bold $cn $cv
554 font configure ${font}italic $cn $cv
556 font configure ${font}bold -weight bold
557 font configure ${font}italic -slant italic
561 set default_config(merge.diffstat) true
562 set default_config(merge.summary) false
563 set default_config(merge.verbosity) 2
564 set default_config(user.name) {}
565 set default_config(user.email) {}
567 set default_config(gui.matchtrackingbranch) false
568 set default_config(gui.pruneduringfetch) false
569 set default_config(gui.trustmtime) false
570 set default_config(gui.diffcontext) 5
571 set default_config(gui.newbranchtemplate) {}
572 set default_config(gui.fontui) [font configure font_ui]
573 set default_config(gui.fontdiff) [font configure font_diff]
575 {fontui font_ui {mc "Main Font"}}
576 {fontdiff font_diff {mc "Diff/Console Font"}}
579 ######################################################################
583 set _git [_which git]
585 catch {wm withdraw .}
589 -title [mc "git-gui: fatal error"] \
590 -message [mc "Cannot find git in PATH."]
594 ######################################################################
598 if {[catch {set _git_version [git --version]} err]} {
599 catch {wm withdraw .}
603 -title [mc "git-gui: fatal error"] \
604 -message "Cannot determine Git version:
608 [appname] requires Git 1.5.0 or later."
611 if {![regsub {^git version } $_git_version {} _git_version]} {
612 catch {wm withdraw .}
616 -title [mc "git-gui: fatal error"] \
617 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
621 set _real_git_version $_git_version
622 regsub -- {-dirty$} $_git_version {} _git_version
623 regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version
624 regsub {\.rc[0-9]+$} $_git_version {} _git_version
625 regsub {\.GIT$} $_git_version {} _git_version
626 regsub {\.[a-zA-Z]+\.[0-9]+$} $_git_version {} _git_version
628 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
629 catch {wm withdraw .}
634 -title "[appname]: warning" \
635 -message [mc "Git version cannot be determined.
637 %s claims it is version '%s'.
639 %s requires at least Git 1.5.0 or later.
641 Assume '%s' is version 1.5.0?
642 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
643 set _git_version 1.5.0
648 unset _real_git_version
650 proc git-version {args} {
653 switch [llength $args] {
659 set op [lindex $args 0]
660 set vr [lindex $args 1]
661 set cm [package vcompare $_git_version $vr]
662 return [expr $cm $op 0]
666 set type [lindex $args 0]
667 set name [lindex $args 1]
668 set parm [lindex $args 2]
669 set body [lindex $args 3]
671 if {($type ne {proc} && $type ne {method})} {
672 error "Invalid arguments to git-version"
674 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
675 error "Last arm of $type $name must be default"
678 foreach {op vr cb} [lrange $body 0 end-2] {
679 if {[git-version $op $vr]} {
680 return [uplevel [list $type $name $parm $cb]]
684 return [uplevel [list $type $name $parm [lindex $body end]]]
688 error "git-version >= x"
694 if {[git-version < 1.5]} {
695 catch {wm withdraw .}
699 -title [mc "git-gui: fatal error"] \
700 -message "[appname] requires Git 1.5.0 or later.
702 You are using [git-version]:
708 ######################################################################
710 ## configure our library
712 set idx [file join $oguilib tclIndex]
713 if {[catch {set fd [open $idx r]} err]} {
714 catch {wm withdraw .}
718 -title [mc "git-gui: fatal error"] \
722 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
724 while {[gets $fd n] >= 0} {
725 if {$n ne {} && ![string match #* $n]} {
737 if {[lsearch -exact $loaded $p] >= 0} continue
738 source [file join $oguilib $p]
743 set auto_path [concat [list $oguilib] $auto_path]
745 unset -nocomplain idx fd
747 ######################################################################
749 ## config file parsing
751 git-version proc _parse_config {arr_name args} {
757 set fd_rc [eval [list git_read config --null --list] $args]
758 fconfigure $fd_rc -translation binary
759 set buf [read $fd_rc]
762 foreach line [split $buf "\0"] {
763 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
764 if {[is_many_config $name]} {
765 lappend arr($name) $value
767 set arr($name) $value
776 set fd_rc [eval [list git_read config --list] $args]
777 while {[gets $fd_rc line] >= 0} {
778 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
779 if {[is_many_config $name]} {
780 lappend arr($name) $value
782 set arr($name) $value
791 proc load_config {include_global} {
792 global repo_config global_config default_config
794 if {$include_global} {
795 _parse_config global_config --global
797 _parse_config repo_config
799 foreach name [array names default_config] {
800 if {[catch {set v $global_config($name)}]} {
801 set global_config($name) $default_config($name)
803 if {[catch {set v $repo_config($name)}]} {
804 set repo_config($name) $default_config($name)
809 ######################################################################
811 ## feature option selection
813 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
818 if {$subcommand eq {gui.sh}} {
821 if {$subcommand eq {gui} && [llength $argv] > 0} {
822 set subcommand [lindex $argv 0]
823 set argv [lrange $argv 1 end]
826 enable_option multicommit
828 enable_option transport
831 switch -- $subcommand {
836 disable_option multicommit
837 disable_option branch
838 disable_option transport
841 enable_option singlecommit
843 disable_option multicommit
844 disable_option branch
845 disable_option transport
849 ######################################################################
854 set _gitdir $env(GIT_DIR)
858 set _gitdir [git rev-parse --git-dir]
859 set _prefix [git rev-parse --show-prefix]
863 choose_repository::pick
865 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
866 catch {set _gitdir [exec cygpath --windows $_gitdir]}
868 if {![file isdirectory $_gitdir]} {
869 catch {wm withdraw .}
870 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
873 if {$_prefix ne {}} {
874 regsub -all {[^/]+/} $_prefix ../ cdup
875 if {[catch {cd $cdup} err]} {
876 catch {wm withdraw .}
877 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
881 } elseif {![is_enabled bare]} {
882 if {[lindex [file split $_gitdir] end] ne {.git}} {
883 catch {wm withdraw .}
884 error_popup [strcat [mc "Cannot use funny .git directory:"] "\n\n$_gitdir"]
887 if {[catch {cd [file dirname $_gitdir]} err]} {
888 catch {wm withdraw .}
889 error_popup [strcat [mc "No working directory"] " [file dirname $_gitdir]:\n\n$err"]
893 set _reponame [file split [file normalize $_gitdir]]
894 if {[lindex $_reponame end] eq {.git}} {
895 set _reponame [lindex $_reponame end-1]
897 set _reponame [lindex $_reponame end]
900 ######################################################################
904 set current_diff_path {}
905 set current_diff_side {}
906 set diff_actions [list]
910 set MERGE_HEAD [list]
913 set current_branch {}
915 set current_diff_path {}
917 set selected_commit_type new
919 ######################################################################
927 set disable_on_lock [list]
928 set index_lock_type none
930 proc lock_index {type} {
931 global index_lock_type disable_on_lock
933 if {$index_lock_type eq {none}} {
934 set index_lock_type $type
935 foreach w $disable_on_lock {
936 uplevel #0 $w disabled
939 } elseif {$index_lock_type eq "begin-$type"} {
940 set index_lock_type $type
946 proc unlock_index {} {
947 global index_lock_type disable_on_lock
949 set index_lock_type none
950 foreach w $disable_on_lock {
955 ######################################################################
959 proc repository_state {ctvar hdvar mhvar} {
960 global current_branch
961 upvar $ctvar ct $hdvar hd $mhvar mh
966 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
972 set merge_head [gitdir MERGE_HEAD]
973 if {[file exists $merge_head]} {
975 set fd_mh [open $merge_head r]
976 while {[gets $fd_mh line] >= 0} {
987 global PARENT empty_tree
989 set p [lindex $PARENT 0]
993 if {$empty_tree eq {}} {
994 set empty_tree [git mktree << {}]
999 proc rescan {after {honor_trustmtime 1}} {
1000 global HEAD PARENT MERGE_HEAD commit_type
1001 global ui_index ui_workdir ui_comm
1002 global rescan_active file_states
1005 if {$rescan_active > 0 || ![lock_index read]} return
1007 repository_state newType newHEAD newMERGE_HEAD
1008 if {[string match amend* $commit_type]
1009 && $newType eq {normal}
1010 && $newHEAD eq $HEAD} {
1014 set MERGE_HEAD $newMERGE_HEAD
1015 set commit_type $newType
1018 array unset file_states
1020 if {!$::GITGUI_BCK_exists &&
1021 (![$ui_comm edit modified]
1022 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1023 if {[string match amend* $commit_type]} {
1024 } elseif {[load_message GITGUI_MSG]} {
1025 } elseif {[load_message MERGE_MSG]} {
1026 } elseif {[load_message SQUASH_MSG]} {
1029 $ui_comm edit modified false
1032 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1033 rescan_stage2 {} $after
1036 ui_status [mc "Refreshing file status..."]
1037 set fd_rf [git_read update-index \
1043 fconfigure $fd_rf -blocking 0 -translation binary
1044 fileevent $fd_rf readable \
1045 [list rescan_stage2 $fd_rf $after]
1050 set is_git_info_link {}
1051 set is_git_info_exclude {}
1052 proc have_info_exclude {} {
1053 global is_git_info_link is_git_info_exclude
1055 if {$is_git_info_link eq {}} {
1056 set is_git_info_link [file isfile [gitdir info.lnk]]
1059 if {$is_git_info_link} {
1060 if {$is_git_info_exclude eq {}} {
1061 if {[catch {exec test -f [gitdir info exclude]}]} {
1062 set is_git_info_exclude 0
1064 set is_git_info_exclude 1
1067 return $is_git_info_exclude
1069 return [file readable [gitdir info exclude]]
1073 proc have_info_exclude {} {
1074 return [file readable [gitdir info exclude]]
1078 proc rescan_stage2 {fd after} {
1079 global rescan_active buf_rdi buf_rdf buf_rlo
1083 if {![eof $fd]} return
1087 set ls_others [list --exclude-per-directory=.gitignore]
1088 if {[have_info_exclude]} {
1089 lappend ls_others "--exclude-from=[gitdir info exclude]"
1091 set user_exclude [get_config core.excludesfile]
1092 if {$user_exclude ne {} && [file readable $user_exclude]} {
1093 lappend ls_others "--exclude-from=$user_exclude"
1101 ui_status [mc "Scanning for modified files ..."]
1102 set fd_di [git_read diff-index --cached -z [PARENT]]
1103 set fd_df [git_read diff-files -z]
1104 set fd_lo [eval git_read ls-files --others -z $ls_others]
1106 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1107 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1108 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1109 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1110 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1111 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1114 proc load_message {file} {
1117 set f [gitdir $file]
1118 if {[file isfile $f]} {
1119 if {[catch {set fd [open $f r]}]} {
1122 fconfigure $fd -eofchar {}
1123 set content [string trim [read $fd]]
1125 regsub -all -line {[ \r\t]+$} $content {} content
1126 $ui_comm delete 0.0 end
1127 $ui_comm insert end $content
1133 proc read_diff_index {fd after} {
1136 append buf_rdi [read $fd]
1138 set n [string length $buf_rdi]
1140 set z1 [string first "\0" $buf_rdi $c]
1141 if {$z1 == -1} break
1143 set z2 [string first "\0" $buf_rdi $z1]
1144 if {$z2 == -1} break
1147 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1148 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1150 [encoding convertfrom $p] \
1152 [list [lindex $i 0] [lindex $i 2]] \
1158 set buf_rdi [string range $buf_rdi $c end]
1163 rescan_done $fd buf_rdi $after
1166 proc read_diff_files {fd after} {
1169 append buf_rdf [read $fd]
1171 set n [string length $buf_rdf]
1173 set z1 [string first "\0" $buf_rdf $c]
1174 if {$z1 == -1} break
1176 set z2 [string first "\0" $buf_rdf $z1]
1177 if {$z2 == -1} break
1180 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1181 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1183 [encoding convertfrom $p] \
1186 [list [lindex $i 0] [lindex $i 2]]
1191 set buf_rdf [string range $buf_rdf $c end]
1196 rescan_done $fd buf_rdf $after
1199 proc read_ls_others {fd after} {
1202 append buf_rlo [read $fd]
1203 set pck [split $buf_rlo "\0"]
1204 set buf_rlo [lindex $pck end]
1205 foreach p [lrange $pck 0 end-1] {
1206 set p [encoding convertfrom $p]
1207 if {[string index $p end] eq {/}} {
1208 set p [string range $p 0 end-1]
1212 rescan_done $fd buf_rlo $after
1215 proc rescan_done {fd buf after} {
1216 global rescan_active current_diff_path
1217 global file_states repo_config
1220 if {![eof $fd]} return
1223 if {[incr rescan_active -1] > 0} return
1228 if {$current_diff_path ne {}} reshow_diff
1232 proc prune_selection {} {
1233 global file_states selected_paths
1235 foreach path [array names selected_paths] {
1236 if {[catch {set still_here $file_states($path)}]} {
1237 unset selected_paths($path)
1242 ######################################################################
1246 proc mapicon {w state path} {
1249 if {[catch {set r $all_icons($state$w)}]} {
1250 puts "error: no icon for $w state={$state} $path"
1256 proc mapdesc {state path} {
1259 if {[catch {set r $all_descs($state)}]} {
1260 puts "error: no desc for state={$state} $path"
1266 proc ui_status {msg} {
1268 if {[info exists main_status]} {
1269 $main_status show $msg
1273 proc ui_ready {{test {}}} {
1275 if {[info exists main_status]} {
1276 $main_status show [mc "Ready."] $test
1280 proc escape_path {path} {
1281 regsub -all {\\} $path "\\\\" path
1282 regsub -all "\n" $path "\\n" path
1286 proc short_path {path} {
1287 return [escape_path [lindex [file split $path] end]]
1291 set null_sha1 [string repeat 0 40]
1293 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1294 global file_states next_icon_id null_sha1
1296 set s0 [string index $new_state 0]
1297 set s1 [string index $new_state 1]
1299 if {[catch {set info $file_states($path)}]} {
1301 set icon n[incr next_icon_id]
1303 set state [lindex $info 0]
1304 set icon [lindex $info 1]
1305 if {$head_info eq {}} {set head_info [lindex $info 2]}
1306 if {$index_info eq {}} {set index_info [lindex $info 3]}
1309 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1310 elseif {$s0 eq {_}} {set s0 _}
1312 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1313 elseif {$s1 eq {_}} {set s1 _}
1315 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1316 set head_info [list 0 $null_sha1]
1317 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1318 && $head_info eq {}} {
1319 set head_info $index_info
1322 set file_states($path) [list $s0$s1 $icon \
1323 $head_info $index_info \
1328 proc display_file_helper {w path icon_name old_m new_m} {
1331 if {$new_m eq {_}} {
1332 set lno [lsearch -sorted -exact $file_lists($w) $path]
1334 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1336 $w conf -state normal
1337 $w delete $lno.0 [expr {$lno + 1}].0
1338 $w conf -state disabled
1340 } elseif {$old_m eq {_} && $new_m ne {_}} {
1341 lappend file_lists($w) $path
1342 set file_lists($w) [lsort -unique $file_lists($w)]
1343 set lno [lsearch -sorted -exact $file_lists($w) $path]
1345 $w conf -state normal
1346 $w image create $lno.0 \
1347 -align center -padx 5 -pady 1 \
1349 -image [mapicon $w $new_m $path]
1350 $w insert $lno.1 "[escape_path $path]\n"
1351 $w conf -state disabled
1352 } elseif {$old_m ne $new_m} {
1353 $w conf -state normal
1354 $w image conf $icon_name -image [mapicon $w $new_m $path]
1355 $w conf -state disabled
1359 proc display_file {path state} {
1360 global file_states selected_paths
1361 global ui_index ui_workdir
1363 set old_m [merge_state $path $state]
1364 set s $file_states($path)
1365 set new_m [lindex $s 0]
1366 set icon_name [lindex $s 1]
1368 set o [string index $old_m 0]
1369 set n [string index $new_m 0]
1376 display_file_helper $ui_index $path $icon_name $o $n
1378 if {[string index $old_m 0] eq {U}} {
1381 set o [string index $old_m 1]
1383 if {[string index $new_m 0] eq {U}} {
1386 set n [string index $new_m 1]
1388 display_file_helper $ui_workdir $path $icon_name $o $n
1390 if {$new_m eq {__}} {
1391 unset file_states($path)
1392 catch {unset selected_paths($path)}
1396 proc display_all_files_helper {w path icon_name m} {
1399 lappend file_lists($w) $path
1400 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1401 $w image create end \
1402 -align center -padx 5 -pady 1 \
1404 -image [mapicon $w $m $path]
1405 $w insert end "[escape_path $path]\n"
1408 proc display_all_files {} {
1409 global ui_index ui_workdir
1410 global file_states file_lists
1413 $ui_index conf -state normal
1414 $ui_workdir conf -state normal
1416 $ui_index delete 0.0 end
1417 $ui_workdir delete 0.0 end
1420 set file_lists($ui_index) [list]
1421 set file_lists($ui_workdir) [list]
1423 foreach path [lsort [array names file_states]] {
1424 set s $file_states($path)
1426 set icon_name [lindex $s 1]
1428 set s [string index $m 0]
1429 if {$s ne {U} && $s ne {_}} {
1430 display_all_files_helper $ui_index $path \
1434 if {[string index $m 0] eq {U}} {
1437 set s [string index $m 1]
1440 display_all_files_helper $ui_workdir $path \
1445 $ui_index conf -state disabled
1446 $ui_workdir conf -state disabled
1449 ######################################################################
1454 #define mask_width 14
1455 #define mask_height 15
1456 static unsigned char mask_bits[] = {
1457 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1458 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1459 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1462 image create bitmap file_plain -background white -foreground black -data {
1463 #define plain_width 14
1464 #define plain_height 15
1465 static unsigned char plain_bits[] = {
1466 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1467 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1468 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1469 } -maskdata $filemask
1471 image create bitmap file_mod -background white -foreground blue -data {
1472 #define mod_width 14
1473 #define mod_height 15
1474 static unsigned char mod_bits[] = {
1475 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1476 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1477 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1478 } -maskdata $filemask
1480 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1481 #define file_fulltick_width 14
1482 #define file_fulltick_height 15
1483 static unsigned char file_fulltick_bits[] = {
1484 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1485 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1486 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1487 } -maskdata $filemask
1489 image create bitmap file_parttick -background white -foreground "#005050" -data {
1490 #define parttick_width 14
1491 #define parttick_height 15
1492 static unsigned char parttick_bits[] = {
1493 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1494 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
1495 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1496 } -maskdata $filemask
1498 image create bitmap file_question -background white -foreground black -data {
1499 #define file_question_width 14
1500 #define file_question_height 15
1501 static unsigned char file_question_bits[] = {
1502 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1503 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1504 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1505 } -maskdata $filemask
1507 image create bitmap file_removed -background white -foreground red -data {
1508 #define file_removed_width 14
1509 #define file_removed_height 15
1510 static unsigned char file_removed_bits[] = {
1511 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1512 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1513 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1514 } -maskdata $filemask
1516 image create bitmap file_merge -background white -foreground blue -data {
1517 #define file_merge_width 14
1518 #define file_merge_height 15
1519 static unsigned char file_merge_bits[] = {
1520 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1521 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1522 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1523 } -maskdata $filemask
1525 set ui_index .vpane.files.index.list
1526 set ui_workdir .vpane.files.workdir.list
1528 set all_icons(_$ui_index) file_plain
1529 set all_icons(A$ui_index) file_fulltick
1530 set all_icons(M$ui_index) file_fulltick
1531 set all_icons(D$ui_index) file_removed
1532 set all_icons(U$ui_index) file_merge
1534 set all_icons(_$ui_workdir) file_plain
1535 set all_icons(M$ui_workdir) file_mod
1536 set all_icons(D$ui_workdir) file_question
1537 set all_icons(U$ui_workdir) file_merge
1538 set all_icons(O$ui_workdir) file_plain
1540 set max_status_desc 0
1542 {__ {mc "Unmodified"}}
1544 {_M {mc "Modified, not staged"}}
1545 {M_ {mc "Staged for commit"}}
1546 {MM {mc "Portions staged for commit"}}
1547 {MD {mc "Staged for commit, missing"}}
1549 {_O {mc "Untracked, not staged"}}
1550 {A_ {mc "Staged for commit"}}
1551 {AM {mc "Portions staged for commit"}}
1552 {AD {mc "Staged for commit, missing"}}
1555 {D_ {mc "Staged for removal"}}
1556 {DO {mc "Staged for removal, still present"}}
1558 {U_ {mc "Requires merge resolution"}}
1559 {UU {mc "Requires merge resolution"}}
1560 {UM {mc "Requires merge resolution"}}
1561 {UD {mc "Requires merge resolution"}}
1563 set text [eval [lindex $i 1]]
1564 if {$max_status_desc < [string length $text]} {
1565 set max_status_desc [string length $text]
1567 set all_descs([lindex $i 0]) $text
1571 ######################################################################
1575 proc scrollbar2many {list mode args} {
1576 foreach w $list {eval $w $mode $args}
1579 proc many2scrollbar {list mode sb top bottom} {
1580 $sb set $top $bottom
1581 foreach w $list {$w $mode moveto $top}
1584 proc incr_font_size {font {amt 1}} {
1585 set sz [font configure $font -size]
1587 font configure $font -size $sz
1588 font configure ${font}bold -size $sz
1589 font configure ${font}italic -size $sz
1592 ######################################################################
1596 set starting_gitk_msg [mc "Starting gitk... please wait..."]
1598 proc do_gitk {revs} {
1599 # -- Always start gitk through whatever we were loaded with. This
1600 # lets us bypass using shell process on Windows systems.
1602 set exe [file join [file dirname $::_git] gitk]
1603 set cmd [list [info nameofexecutable] $exe]
1604 if {! [file exists $exe]} {
1605 error_popup [mc "Unable to start gitk:\n\n%s does not exist" $exe]
1609 if {[info exists env(GIT_DIR)]} {
1610 set old_GIT_DIR $env(GIT_DIR)
1616 cd [file dirname [gitdir]]
1617 set env(GIT_DIR) [file tail [gitdir]]
1619 eval exec $cmd $revs &
1621 if {$old_GIT_DIR eq {}} {
1624 set env(GIT_DIR) $old_GIT_DIR
1628 ui_status $::starting_gitk_msg
1630 ui_ready $starting_gitk_msg
1638 global ui_comm is_quitting repo_config commit_type
1639 global GITGUI_BCK_exists GITGUI_BCK_i
1641 if {$is_quitting} return
1644 if {[winfo exists $ui_comm]} {
1645 # -- Stash our current commit buffer.
1647 set save [gitdir GITGUI_MSG]
1648 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
1649 file rename -force [gitdir GITGUI_BCK] $save
1650 set GITGUI_BCK_exists 0
1652 set msg [string trim [$ui_comm get 0.0 end]]
1653 regsub -all -line {[ \r\t]+$} $msg {} msg
1654 if {(![string match amend* $commit_type]
1655 || [$ui_comm edit modified])
1658 set fd [open $save w]
1659 puts -nonewline $fd $msg
1663 catch {file delete $save}
1667 # -- Remove our editor backup, its not needed.
1669 after cancel $GITGUI_BCK_i
1670 if {$GITGUI_BCK_exists} {
1671 catch {file delete [gitdir GITGUI_BCK]}
1674 # -- Stash our current window geometry into this repository.
1676 set cfg_geometry [list]
1677 lappend cfg_geometry [wm geometry .]
1678 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
1679 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
1680 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
1683 if {$cfg_geometry ne $rc_geometry} {
1684 catch {git config gui.geometry $cfg_geometry}
1699 proc toggle_or_diff {w x y} {
1700 global file_states file_lists current_diff_path ui_index ui_workdir
1701 global last_clicked selected_paths
1703 set pos [split [$w index @$x,$y] .]
1704 set lno [lindex $pos 0]
1705 set col [lindex $pos 1]
1706 set path [lindex $file_lists($w) [expr {$lno - 1}]]
1712 set last_clicked [list $w $lno]
1713 array unset selected_paths
1714 $ui_index tag remove in_sel 0.0 end
1715 $ui_workdir tag remove in_sel 0.0 end
1718 if {$current_diff_path eq $path} {
1719 set after {reshow_diff;}
1723 if {$w eq $ui_index} {
1725 "Unstaging [short_path $path] from commit" \
1727 [concat $after [list ui_ready]]
1728 } elseif {$w eq $ui_workdir} {
1730 "Adding [short_path $path]" \
1732 [concat $after [list ui_ready]]
1735 show_diff $path $w $lno
1739 proc add_one_to_selection {w x y} {
1740 global file_lists last_clicked selected_paths
1742 set lno [lindex [split [$w index @$x,$y] .] 0]
1743 set path [lindex $file_lists($w) [expr {$lno - 1}]]
1749 if {$last_clicked ne {}
1750 && [lindex $last_clicked 0] ne $w} {
1751 array unset selected_paths
1752 [lindex $last_clicked 0] tag remove in_sel 0.0 end
1755 set last_clicked [list $w $lno]
1756 if {[catch {set in_sel $selected_paths($path)}]} {
1760 unset selected_paths($path)
1761 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
1763 set selected_paths($path) 1
1764 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
1768 proc add_range_to_selection {w x y} {
1769 global file_lists last_clicked selected_paths
1771 if {[lindex $last_clicked 0] ne $w} {
1772 toggle_or_diff $w $x $y
1776 set lno [lindex [split [$w index @$x,$y] .] 0]
1777 set lc [lindex $last_clicked 1]
1786 foreach path [lrange $file_lists($w) \
1787 [expr {$begin - 1}] \
1788 [expr {$end - 1}]] {
1789 set selected_paths($path) 1
1791 $w tag add in_sel $begin.0 [expr {$end + 1}].0
1794 ######################################################################
1804 menu .mbar -tearoff 0
1805 .mbar add cascade -label [mc Repository] -menu .mbar.repository
1806 .mbar add cascade -label [mc Edit] -menu .mbar.edit
1807 if {[is_enabled branch]} {
1808 .mbar add cascade -label [mc Branch] -menu .mbar.branch
1810 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
1811 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
1813 if {[is_enabled transport]} {
1814 .mbar add cascade -label [mc Merge] -menu .mbar.merge
1815 .mbar add cascade -label [mc Remote] -menu .mbar.remote
1817 . configure -menu .mbar
1819 # -- Repository Menu
1821 menu .mbar.repository
1823 .mbar.repository add command \
1824 -label [mc "Browse Current Branch's Files"] \
1825 -command {browser::new $current_branch}
1826 set ui_browse_current [.mbar.repository index last]
1827 .mbar.repository add command \
1828 -label [mc "Browse Branch Files..."] \
1829 -command browser_open::dialog
1830 .mbar.repository add separator
1832 .mbar.repository add command \
1833 -label [mc "Visualize Current Branch's History"] \
1834 -command {do_gitk $current_branch}
1835 set ui_visualize_current [.mbar.repository index last]
1836 .mbar.repository add command \
1837 -label [mc "Visualize All Branch History"] \
1838 -command {do_gitk --all}
1839 .mbar.repository add separator
1841 proc current_branch_write {args} {
1842 global current_branch
1843 .mbar.repository entryconf $::ui_browse_current \
1844 -label [mc "Browse %s's Files" $current_branch]
1845 .mbar.repository entryconf $::ui_visualize_current \
1846 -label [mc "Visualize %s's History" $current_branch]
1848 trace add variable current_branch write current_branch_write
1850 if {[is_enabled multicommit]} {
1851 .mbar.repository add command -label [mc "Database Statistics"] \
1854 .mbar.repository add command -label [mc "Compress Database"] \
1857 .mbar.repository add command -label [mc "Verify Database"] \
1858 -command do_fsck_objects
1860 .mbar.repository add separator
1863 .mbar.repository add command \
1864 -label [mc "Create Desktop Icon"] \
1865 -command do_cygwin_shortcut
1866 } elseif {[is_Windows]} {
1867 .mbar.repository add command \
1868 -label [mc "Create Desktop Icon"] \
1869 -command do_windows_shortcut
1870 } elseif {[is_MacOSX]} {
1871 .mbar.repository add command \
1872 -label [mc "Create Desktop Icon"] \
1873 -command do_macosx_app
1877 .mbar.repository add command -label [mc Quit] \
1884 .mbar.edit add command -label [mc Undo] \
1885 -command {catch {[focus] edit undo}} \
1887 .mbar.edit add command -label [mc Redo] \
1888 -command {catch {[focus] edit redo}} \
1890 .mbar.edit add separator
1891 .mbar.edit add command -label [mc Cut] \
1892 -command {catch {tk_textCut [focus]}} \
1894 .mbar.edit add command -label [mc Copy] \
1895 -command {catch {tk_textCopy [focus]}} \
1897 .mbar.edit add command -label [mc Paste] \
1898 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
1900 .mbar.edit add command -label [mc Delete] \
1901 -command {catch {[focus] delete sel.first sel.last}} \
1903 .mbar.edit add separator
1904 .mbar.edit add command -label [mc "Select All"] \
1905 -command {catch {[focus] tag add sel 0.0 end}} \
1910 if {[is_enabled branch]} {
1913 .mbar.branch add command -label [mc "Create..."] \
1914 -command branch_create::dialog \
1916 lappend disable_on_lock [list .mbar.branch entryconf \
1917 [.mbar.branch index last] -state]
1919 .mbar.branch add command -label [mc "Checkout..."] \
1920 -command branch_checkout::dialog \
1922 lappend disable_on_lock [list .mbar.branch entryconf \
1923 [.mbar.branch index last] -state]
1925 .mbar.branch add command -label [mc "Rename..."] \
1926 -command branch_rename::dialog
1927 lappend disable_on_lock [list .mbar.branch entryconf \
1928 [.mbar.branch index last] -state]
1930 .mbar.branch add command -label [mc "Delete..."] \
1931 -command branch_delete::dialog
1932 lappend disable_on_lock [list .mbar.branch entryconf \
1933 [.mbar.branch index last] -state]
1935 .mbar.branch add command -label [mc "Reset..."] \
1936 -command merge::reset_hard
1937 lappend disable_on_lock [list .mbar.branch entryconf \
1938 [.mbar.branch index last] -state]
1943 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
1946 .mbar.commit add radiobutton \
1947 -label [mc "New Commit"] \
1948 -command do_select_commit_type \
1949 -variable selected_commit_type \
1951 lappend disable_on_lock \
1952 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1954 .mbar.commit add radiobutton \
1955 -label [mc "Amend Last Commit"] \
1956 -command do_select_commit_type \
1957 -variable selected_commit_type \
1959 lappend disable_on_lock \
1960 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1962 .mbar.commit add separator
1964 .mbar.commit add command -label [mc Rescan] \
1965 -command do_rescan \
1967 lappend disable_on_lock \
1968 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1970 .mbar.commit add command -label [mc "Stage To Commit"] \
1971 -command do_add_selection
1972 lappend disable_on_lock \
1973 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1975 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
1976 -command do_add_all \
1978 lappend disable_on_lock \
1979 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1981 .mbar.commit add command -label [mc "Unstage From Commit"] \
1982 -command do_unstage_selection
1983 lappend disable_on_lock \
1984 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1986 .mbar.commit add command -label [mc "Revert Changes"] \
1987 -command do_revert_selection
1988 lappend disable_on_lock \
1989 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1991 .mbar.commit add separator
1993 .mbar.commit add command -label [mc "Sign Off"] \
1994 -command do_signoff \
1997 .mbar.commit add command -label [mc Commit@@verb] \
1998 -command do_commit \
1999 -accelerator $M1T-Return
2000 lappend disable_on_lock \
2001 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2006 if {[is_enabled branch]} {
2008 .mbar.merge add command -label [mc "Local Merge..."] \
2009 -command merge::dialog \
2011 lappend disable_on_lock \
2012 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2013 .mbar.merge add command -label [mc "Abort Merge..."] \
2014 -command merge::reset_hard
2015 lappend disable_on_lock \
2016 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2021 if {[is_enabled transport]} {
2024 .mbar.remote add command \
2025 -label [mc "Push..."] \
2026 -command do_push_anywhere \
2028 .mbar.remote add command \
2029 -label [mc "Delete..."] \
2030 -command remote_branch_delete::dialog
2034 # -- Apple Menu (Mac OS X only)
2036 .mbar add cascade -label [mc Apple] -menu .mbar.apple
2039 .mbar.apple add command -label [mc "About %s" [appname]] \
2041 .mbar.apple add separator
2042 .mbar.apple add command \
2043 -label [mc "Preferences..."] \
2044 -command do_options \
2046 bind . <$M1B-,> do_options
2050 .mbar.edit add separator
2051 .mbar.edit add command -label [mc "Options..."] \
2057 .mbar add cascade -label [mc Help] -menu .mbar.help
2061 .mbar.help add command -label [mc "About %s" [appname]] \
2066 catch {set browser $repo_config(instaweb.browser)}
2067 set doc_path [file dirname [gitexec]]
2068 set doc_path [file join $doc_path Documentation index.html]
2071 set doc_path [exec cygpath --mixed $doc_path]
2074 if {$browser eq {}} {
2077 } elseif {[is_Cygwin]} {
2078 set program_files [file dirname [exec cygpath --windir]]
2079 set program_files [file join $program_files {Program Files}]
2080 set firefox [file join $program_files {Mozilla Firefox} firefox.exe]
2081 set ie [file join $program_files {Internet Explorer} IEXPLORE.EXE]
2082 if {[file exists $firefox]} {
2083 set browser $firefox
2084 } elseif {[file exists $ie]} {
2087 unset program_files firefox ie
2091 if {[file isfile $doc_path]} {
2092 set doc_url "file:$doc_path"
2094 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2097 if {$browser ne {}} {
2098 .mbar.help add command -label [mc "Online Documentation"] \
2099 -command [list exec $browser $doc_url &]
2101 unset browser doc_path doc_url
2103 # -- Standard bindings
2105 wm protocol . WM_DELETE_WINDOW do_quit
2106 bind all <$M1B-Key-q> do_quit
2107 bind all <$M1B-Key-Q> do_quit
2108 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2109 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2111 set subcommand_args {}
2113 puts stderr "usage: $::argv0 $::subcommand $::subcommand_args"
2117 # -- Not a normal commit type invocation? Do that instead!
2119 switch -- $subcommand {
2122 set subcommand_args {rev? path}
2123 if {$argv eq {}} usage
2128 if {$is_path || [file exists $_prefix$a]} {
2129 if {$path ne {}} usage
2132 } elseif {$a eq {--}} {
2134 if {$head ne {}} usage
2139 } elseif {$head eq {}} {
2140 if {$head ne {}} usage
2149 if {$head ne {} && $path eq {}} {
2150 set path $_prefix$head
2157 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
2159 set head [git rev-parse --verify $head]
2165 set current_branch $head
2168 switch -- $subcommand {
2171 if {$path ne {} && [file isdirectory $path]} {
2172 set head $current_branch
2178 browser::new $head $path
2181 if {$head eq {} && ![file exists $path]} {
2182 puts stderr [mc "fatal: cannot stat path %s: No such file or directory" $path]
2185 blame::new $head $path
2192 if {[llength $argv] != 0} {
2193 puts -nonewline stderr "usage: $argv0"
2194 if {$subcommand ne {gui}
2195 && [file tail $argv0] ne "git-$subcommand"} {
2196 puts -nonewline stderr " $subcommand"
2201 # fall through to setup UI for commits
2204 puts stderr "usage: $argv0 \[{blame|browser|citool}\]"
2215 -text [mc "Current Branch:"] \
2219 -textvariable current_branch \
2222 pack .branch.l1 -side left
2223 pack .branch.cb -side left -fill x
2224 pack .branch -side top -fill x
2226 # -- Main Window Layout
2228 panedwindow .vpane -orient horizontal
2229 panedwindow .vpane.files -orient vertical
2230 .vpane add .vpane.files -sticky nsew -height 100 -width 200
2231 pack .vpane -anchor n -side top -fill both -expand 1
2233 # -- Index File List
2235 frame .vpane.files.index -height 100 -width 200
2236 label .vpane.files.index.title -text [mc "Staged Changes (Will Commit)"] \
2237 -background lightgreen
2238 text $ui_index -background white -borderwidth 0 \
2239 -width 20 -height 10 \
2241 -cursor $cursor_ptr \
2242 -xscrollcommand {.vpane.files.index.sx set} \
2243 -yscrollcommand {.vpane.files.index.sy set} \
2245 scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
2246 scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
2247 pack .vpane.files.index.title -side top -fill x
2248 pack .vpane.files.index.sx -side bottom -fill x
2249 pack .vpane.files.index.sy -side right -fill y
2250 pack $ui_index -side left -fill both -expand 1
2252 # -- Working Directory File List
2254 frame .vpane.files.workdir -height 100 -width 200
2255 label .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
2256 -background lightsalmon
2257 text $ui_workdir -background white -borderwidth 0 \
2258 -width 20 -height 10 \
2260 -cursor $cursor_ptr \
2261 -xscrollcommand {.vpane.files.workdir.sx set} \
2262 -yscrollcommand {.vpane.files.workdir.sy set} \
2264 scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
2265 scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
2266 pack .vpane.files.workdir.title -side top -fill x
2267 pack .vpane.files.workdir.sx -side bottom -fill x
2268 pack .vpane.files.workdir.sy -side right -fill y
2269 pack $ui_workdir -side left -fill both -expand 1
2271 .vpane.files add .vpane.files.workdir -sticky nsew
2272 .vpane.files add .vpane.files.index -sticky nsew
2274 foreach i [list $ui_index $ui_workdir] {
2276 $i tag conf in_diff -background [$i tag cget in_sel -background]
2280 # -- Diff and Commit Area
2282 frame .vpane.lower -height 300 -width 400
2283 frame .vpane.lower.commarea
2284 frame .vpane.lower.diff -relief sunken -borderwidth 1
2285 pack .vpane.lower.diff -fill both -expand 1
2286 pack .vpane.lower.commarea -side bottom -fill x
2287 .vpane add .vpane.lower -sticky nsew
2289 # -- Commit Area Buttons
2291 frame .vpane.lower.commarea.buttons
2292 label .vpane.lower.commarea.buttons.l -text {} \
2295 pack .vpane.lower.commarea.buttons.l -side top -fill x
2296 pack .vpane.lower.commarea.buttons -side left -fill y
2298 button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
2300 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
2301 lappend disable_on_lock \
2302 {.vpane.lower.commarea.buttons.rescan conf -state}
2304 button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
2306 pack .vpane.lower.commarea.buttons.incall -side top -fill x
2307 lappend disable_on_lock \
2308 {.vpane.lower.commarea.buttons.incall conf -state}
2310 button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
2312 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
2314 button .vpane.lower.commarea.buttons.commit -text [mc Commit@@verb] \
2316 pack .vpane.lower.commarea.buttons.commit -side top -fill x
2317 lappend disable_on_lock \
2318 {.vpane.lower.commarea.buttons.commit conf -state}
2320 button .vpane.lower.commarea.buttons.push -text [mc Push] \
2321 -command do_push_anywhere
2322 pack .vpane.lower.commarea.buttons.push -side top -fill x
2324 # -- Commit Message Buffer
2326 frame .vpane.lower.commarea.buffer
2327 frame .vpane.lower.commarea.buffer.header
2328 set ui_comm .vpane.lower.commarea.buffer.t
2329 set ui_coml .vpane.lower.commarea.buffer.header.l
2330 radiobutton .vpane.lower.commarea.buffer.header.new \
2331 -text [mc "New Commit"] \
2332 -command do_select_commit_type \
2333 -variable selected_commit_type \
2335 lappend disable_on_lock \
2336 [list .vpane.lower.commarea.buffer.header.new conf -state]
2337 radiobutton .vpane.lower.commarea.buffer.header.amend \
2338 -text [mc "Amend Last Commit"] \
2339 -command do_select_commit_type \
2340 -variable selected_commit_type \
2342 lappend disable_on_lock \
2343 [list .vpane.lower.commarea.buffer.header.amend conf -state]
2347 proc trace_commit_type {varname args} {
2348 global ui_coml commit_type
2349 switch -glob -- $commit_type {
2350 initial {set txt [mc "Initial Commit Message:"]}
2351 amend {set txt [mc "Amended Commit Message:"]}
2352 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
2353 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
2354 merge {set txt [mc "Merge Commit Message:"]}
2355 * {set txt [mc "Commit Message:"]}
2357 $ui_coml conf -text $txt
2359 trace add variable commit_type write trace_commit_type
2360 pack $ui_coml -side left -fill x
2361 pack .vpane.lower.commarea.buffer.header.amend -side right
2362 pack .vpane.lower.commarea.buffer.header.new -side right
2364 text $ui_comm -background white -borderwidth 1 \
2367 -autoseparators true \
2369 -width 75 -height 9 -wrap none \
2371 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
2372 scrollbar .vpane.lower.commarea.buffer.sby \
2373 -command [list $ui_comm yview]
2374 pack .vpane.lower.commarea.buffer.header -side top -fill x
2375 pack .vpane.lower.commarea.buffer.sby -side right -fill y
2376 pack $ui_comm -side left -fill y
2377 pack .vpane.lower.commarea.buffer -side left -fill y
2379 # -- Commit Message Buffer Context Menu
2381 set ctxm .vpane.lower.commarea.buffer.ctxm
2382 menu $ctxm -tearoff 0
2385 -command {tk_textCut $ui_comm}
2388 -command {tk_textCopy $ui_comm}
2391 -command {tk_textPaste $ui_comm}
2393 -label [mc Delete] \
2394 -command {$ui_comm delete sel.first sel.last}
2397 -label [mc "Select All"] \
2398 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
2400 -label [mc "Copy All"] \
2402 $ui_comm tag add sel 0.0 end
2403 tk_textCopy $ui_comm
2404 $ui_comm tag remove sel 0.0 end
2408 -label [mc "Sign Off"] \
2410 bind_button3 $ui_comm "tk_popup $ctxm %X %Y"
2414 proc trace_current_diff_path {varname args} {
2415 global current_diff_path diff_actions file_states
2416 if {$current_diff_path eq {}} {
2422 set p $current_diff_path
2423 set s [mapdesc [lindex $file_states($p) 0] $p]
2425 set p [escape_path $p]
2429 .vpane.lower.diff.header.status configure -text $s
2430 .vpane.lower.diff.header.file configure -text $f
2431 .vpane.lower.diff.header.path configure -text $p
2432 foreach w $diff_actions {
2436 trace add variable current_diff_path write trace_current_diff_path
2438 frame .vpane.lower.diff.header -background gold
2439 label .vpane.lower.diff.header.status \
2441 -width $max_status_desc \
2444 label .vpane.lower.diff.header.file \
2448 label .vpane.lower.diff.header.path \
2452 pack .vpane.lower.diff.header.status -side left
2453 pack .vpane.lower.diff.header.file -side left
2454 pack .vpane.lower.diff.header.path -fill x
2455 set ctxm .vpane.lower.diff.header.ctxm
2456 menu $ctxm -tearoff 0
2464 -- $current_diff_path
2466 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2467 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
2471 frame .vpane.lower.diff.body
2472 set ui_diff .vpane.lower.diff.body.t
2473 text $ui_diff -background white -borderwidth 0 \
2474 -width 80 -height 15 -wrap none \
2476 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
2477 -yscrollcommand {.vpane.lower.diff.body.sby set} \
2479 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
2480 -command [list $ui_diff xview]
2481 scrollbar .vpane.lower.diff.body.sby -orient vertical \
2482 -command [list $ui_diff yview]
2483 pack .vpane.lower.diff.body.sbx -side bottom -fill x
2484 pack .vpane.lower.diff.body.sby -side right -fill y
2485 pack $ui_diff -side left -fill both -expand 1
2486 pack .vpane.lower.diff.header -side top -fill x
2487 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
2489 $ui_diff tag conf d_cr -elide true
2490 $ui_diff tag conf d_@ -foreground blue -font font_diffbold
2491 $ui_diff tag conf d_+ -foreground {#00a000}
2492 $ui_diff tag conf d_- -foreground red
2494 $ui_diff tag conf d_++ -foreground {#00a000}
2495 $ui_diff tag conf d_-- -foreground red
2496 $ui_diff tag conf d_+s \
2497 -foreground {#00a000} \
2498 -background {#e2effa}
2499 $ui_diff tag conf d_-s \
2501 -background {#e2effa}
2502 $ui_diff tag conf d_s+ \
2503 -foreground {#00a000} \
2505 $ui_diff tag conf d_s- \
2509 $ui_diff tag conf d<<<<<<< \
2510 -foreground orange \
2512 $ui_diff tag conf d======= \
2513 -foreground orange \
2515 $ui_diff tag conf d>>>>>>> \
2516 -foreground orange \
2519 $ui_diff tag raise sel
2521 # -- Diff Body Context Menu
2523 set ctxm .vpane.lower.diff.body.ctxm
2524 menu $ctxm -tearoff 0
2526 -label [mc Refresh] \
2527 -command reshow_diff
2528 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2531 -command {tk_textCopy $ui_diff}
2532 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2534 -label [mc "Select All"] \
2535 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
2536 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2538 -label [mc "Copy All"] \
2540 $ui_diff tag add sel 0.0 end
2541 tk_textCopy $ui_diff
2542 $ui_diff tag remove sel 0.0 end
2544 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2547 -label [mc "Apply/Reverse Hunk"] \
2548 -command {apply_hunk $cursorX $cursorY}
2549 set ui_diff_applyhunk [$ctxm index last]
2550 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
2553 -label [mc "Decrease Font Size"] \
2554 -command {incr_font_size font_diff -1}
2555 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2557 -label [mc "Increase Font Size"] \
2558 -command {incr_font_size font_diff 1}
2559 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2562 -label [mc "Show Less Context"] \
2563 -command {if {$repo_config(gui.diffcontext) >= 1} {
2564 incr repo_config(gui.diffcontext) -1
2567 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2569 -label [mc "Show More Context"] \
2570 -command {if {$repo_config(gui.diffcontext) < 99} {
2571 incr repo_config(gui.diffcontext)
2574 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2576 $ctxm add command -label [mc "Options..."] \
2578 proc popup_diff_menu {ctxm x y X Y} {
2579 global current_diff_path file_states
2582 if {$::ui_index eq $::current_diff_side} {
2583 set l [mc "Unstage Hunk From Commit"]
2585 set l [mc "Stage Hunk For Commit"]
2588 || $current_diff_path eq {}
2589 || ![info exists file_states($current_diff_path)]
2590 || {_O} eq [lindex $file_states($current_diff_path) 0]} {
2595 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
2596 tk_popup $ctxm $X $Y
2598 bind_button3 $ui_diff [list popup_diff_menu $ctxm %x %y %X %Y]
2602 set main_status [::status_bar::new .status]
2603 pack .status -anchor w -side bottom -fill x
2604 $main_status show [mc "Initializing..."]
2609 set gm $repo_config(gui.geometry)
2610 wm geometry . [lindex $gm 0]
2611 .vpane sash place 0 \
2613 [lindex [.vpane sash coord 0] 1]
2614 .vpane.files sash place 0 \
2615 [lindex [.vpane.files sash coord 0] 0] \
2622 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
2623 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
2624 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
2625 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
2626 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
2627 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
2628 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
2629 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
2630 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
2631 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
2632 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
2634 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
2635 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
2636 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
2637 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
2638 bind $ui_diff <$M1B-Key-v> {break}
2639 bind $ui_diff <$M1B-Key-V> {break}
2640 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
2641 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
2642 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
2643 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
2644 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
2645 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
2646 bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
2647 bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
2648 bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
2649 bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
2650 bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
2651 bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
2652 bind $ui_diff <Button-1> {focus %W}
2654 if {[is_enabled branch]} {
2655 bind . <$M1B-Key-n> branch_create::dialog
2656 bind . <$M1B-Key-N> branch_create::dialog
2657 bind . <$M1B-Key-o> branch_checkout::dialog
2658 bind . <$M1B-Key-O> branch_checkout::dialog
2659 bind . <$M1B-Key-m> merge::dialog
2660 bind . <$M1B-Key-M> merge::dialog
2662 if {[is_enabled transport]} {
2663 bind . <$M1B-Key-p> do_push_anywhere
2664 bind . <$M1B-Key-P> do_push_anywhere
2667 bind . <Key-F5> do_rescan
2668 bind . <$M1B-Key-r> do_rescan
2669 bind . <$M1B-Key-R> do_rescan
2670 bind . <$M1B-Key-s> do_signoff
2671 bind . <$M1B-Key-S> do_signoff
2672 bind . <$M1B-Key-i> do_add_all
2673 bind . <$M1B-Key-I> do_add_all
2674 bind . <$M1B-Key-Return> do_commit
2675 foreach i [list $ui_index $ui_workdir] {
2676 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
2677 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
2678 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
2682 set file_lists($ui_index) [list]
2683 set file_lists($ui_workdir) [list]
2685 wm title . "[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"
2686 focus -force $ui_comm
2688 # -- Warn the user about environmental problems. Cygwin's Tcl
2689 # does *not* pass its env array onto any processes it spawns.
2690 # This means that git processes get none of our environment.
2695 set msg [mc "Possible environment issues exist.
2697 The following environment variables are probably
2698 going to be ignored by any Git subprocess run
2702 foreach name [array names env] {
2703 switch -regexp -- $name {
2704 {^GIT_INDEX_FILE$} -
2705 {^GIT_OBJECT_DIRECTORY$} -
2706 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
2708 {^GIT_EXTERNAL_DIFF$} -
2712 {^GIT_CONFIG_LOCAL$} -
2713 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
2714 append msg " - $name\n"
2717 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
2718 append msg " - $name\n"
2720 set suggest_user $name
2724 if {$ignored_env > 0} {
2726 This is due to a known issue with the
2727 Tcl binary distributed by Cygwin."]
2729 if {$suggest_user ne {}} {
2732 A good replacement for %s
2733 is placing values for the user.name and
2734 user.email settings into your personal
2740 unset ignored_env msg suggest_user name
2743 # -- Only initialize complex UI if we are going to stay running.
2745 if {[is_enabled transport]} {
2748 set n [.mbar.remote index end]
2751 set n [expr {[.mbar.remote index end] - $n}]
2753 .mbar.remote insert $n separator
2758 if {[winfo exists $ui_comm]} {
2759 set GITGUI_BCK_exists [load_message GITGUI_BCK]
2761 # -- If both our backup and message files exist use the
2762 # newer of the two files to initialize the buffer.
2764 if {$GITGUI_BCK_exists} {
2765 set m [gitdir GITGUI_MSG]
2766 if {[file isfile $m]} {
2767 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
2768 catch {file delete [gitdir GITGUI_MSG]}
2770 $ui_comm delete 0.0 end
2772 $ui_comm edit modified false
2773 catch {file delete [gitdir GITGUI_BCK]}
2774 set GITGUI_BCK_exists 0
2780 proc backup_commit_buffer {} {
2781 global ui_comm GITGUI_BCK_exists
2783 set m [$ui_comm edit modified]
2784 if {$m || $GITGUI_BCK_exists} {
2785 set msg [string trim [$ui_comm get 0.0 end]]
2786 regsub -all -line {[ \r\t]+$} $msg {} msg
2789 if {$GITGUI_BCK_exists} {
2790 catch {file delete [gitdir GITGUI_BCK]}
2791 set GITGUI_BCK_exists 0
2795 set fd [open [gitdir GITGUI_BCK] w]
2796 puts -nonewline $fd $msg
2798 set GITGUI_BCK_exists 1
2802 $ui_comm edit modified false
2805 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
2808 backup_commit_buffer
2811 lock_index begin-read
2812 if {![winfo ismapped .]} {
2816 if {[is_enabled multicommit]} {