2 # Tcl ignores the next line -*- tcl -*- \
3 if test "z$*" = zversion \
4 ||
test "z$*" = z--version
; \
6 echo 'git-gui version @@GITGUI_VERSION@@'; \
11 set appvers
{@@GITGUI_VERSION@@
}
13 Copyright ©
2006, 2007 Shawn Pearce
, et. al.
15 This program is free software
; you can redistribute it and
/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation
; either version
2 of the License
, or
18 (at your option
) any later version.
20 This program is distributed
in the hope that it will be useful
,
21 but WITHOUT ANY WARRANTY
; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License
for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program
; if not
, write to the Free Software
27 Foundation
, Inc.
, 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
}
29 ######################################################################
31 ## Tcl/Tk sanity check
33 if {[catch
{package require Tcl
8.4} err
]
34 ||
[catch
{package require Tk
8.4} err
]
40 -title "git-gui: fatal error" \
45 ######################################################################
49 set oguilib
{@@GITGUI_LIBDIR@@
}
50 set oguirel
{@@GITGUI_RELATIVE@@
}
51 if {$oguirel eq
{1}} {
52 set oguilib
[file dirname [file dirname [file normalize
$argv0]]]
53 set oguilib
[file join $oguilib share git-gui lib
]
54 set oguimsg
[file join $oguilib msgs
]
55 } elseif
{[string match @@
* $oguirel]} {
56 set oguilib
[file join [file dirname [file normalize
$argv0]] lib
]
57 set oguimsg
[file join [file dirname [file normalize
$argv0]] po
]
59 set oguimsg
[file join $oguilib msgs
]
63 ######################################################################
65 ## enable verbose loading?
67 if {![catch
{set _verbose
$env(GITGUI_VERBOSE
)}]} {
69 rename auto_load real__auto_load
70 proc auto_load
{name args
} {
71 puts stderr
"auto_load $name"
72 return [uplevel
1 real__auto_load
$name $args]
74 rename
source real__source
76 puts stderr
"source $name"
77 uplevel
1 real__source
$name
81 ######################################################################
83 ## Internationalization (i18n) through msgcat and gettext. See
84 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
86 package require msgcat
87 namespace import
::msgcat
::mc
88 ::msgcat
::mcload
$oguimsg
91 ######################################################################
95 set _appname
[lindex
[file split $argv0] end
]
112 return [eval [list
file join $_gitdir] $args]
115 proc gitexec
{args
} {
117 if {$_gitexec eq
{}} {
118 if {[catch
{set _gitexec
[git
--exec-path]} err
]} {
119 error
"Git not installed?\n\n$err"
122 set _gitexec
[exec cygpath \
127 set _gitexec
[file normalize
$_gitexec]
133 return [eval [list
file join $_gitexec] $args]
141 if {[tk windowingsystem
] eq
{aqua
}} {
148 if {$
::tcl_platform
(platform
) eq
{windows
}} {
156 if {$_iscygwin eq
{}} {
157 if {$
::tcl_platform
(platform
) eq
{windows
}} {
158 if {[catch
{set p
[exec cygpath
--windir]} err
]} {
170 proc is_enabled
{option
} {
171 global enabled_options
172 if {[catch
{set on
$enabled_options($option)}]} {return 0}
176 proc enable_option
{option
} {
177 global enabled_options
178 set enabled_options
($option) 1
181 proc disable_option
{option
} {
182 global enabled_options
183 set enabled_options
($option) 0
186 ######################################################################
190 proc is_many_config
{name
} {
191 switch
-glob -- $name {
200 proc is_config_true
{name
} {
202 if {[catch
{set v
$repo_config($name)}]} {
204 } elseif
{$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes}} {
211 proc get_config
{name
} {
213 if {[catch
{set v
$repo_config($name)}]} {
220 proc load_config
{include_global
} {
221 global repo_config global_config default_config
223 array
unset global_config
224 if {$include_global} {
226 set fd_rc
[git_read config
--global --list]
227 while {[gets
$fd_rc line
] >= 0} {
228 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
229 if {[is_many_config
$name]} {
230 lappend global_config
($name) $value
232 set global_config
($name) $value
240 array
unset repo_config
242 set fd_rc
[git_read config
--list]
243 while {[gets
$fd_rc line
] >= 0} {
244 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
245 if {[is_many_config
$name]} {
246 lappend repo_config
($name) $value
248 set repo_config
($name) $value
255 foreach name
[array names default_config
] {
256 if {[catch
{set v
$global_config($name)}]} {
257 set global_config
($name) $default_config($name)
259 if {[catch
{set v
$repo_config($name)}]} {
260 set repo_config
($name) $default_config($name)
265 ######################################################################
269 proc _git_cmd
{name
} {
272 if {[catch
{set v
$_git_cmd_path($name)}]} {
276 --exec-path { return [list $
::_git
$name] }
279 set p
[gitexec git-
$name$
::_search_exe
]
280 if {[file exists
$p]} {
282 } elseif
{[is_Windows
] && [file exists
[gitexec git-
$name]]} {
283 # Try to determine what sort of magic will make
284 # git-$name go and do its thing, because native
285 # Tcl on Windows doesn't know it.
287 set p
[gitexec git-
$name]
294 #!*perl { set i perl }
295 #!*python { set i python }
296 default
{ error
"git-$name is not supported: $s" }
300 if {![info exists interp
]} {
301 set interp
[_which
$i]
304 error
"git-$name requires $i (not in PATH)"
306 set v
[list
$interp $p]
308 # Assume it is builtin to git somehow and we
309 # aren't actually able to see a file for it.
311 set v
[list $
::_git
$name]
313 set _git_cmd_path
($name) $v
319 global env _search_exe _search_path
321 if {$_search_path eq
{}} {
323 set _search_path
[split [exec cygpath \
329 } elseif
{[is_Windows
]} {
330 set _search_path
[split $env(PATH
) {;}]
333 set _search_path
[split $env(PATH
) :]
338 foreach p
$_search_path {
339 set p
[file join $p $what$_search_exe]
340 if {[file exists
$p]} {
341 return [file normalize
$p]
347 proc _lappend_nice
{cmd_var
} {
351 if {![info exists _nice
]} {
352 set _nice
[_which nice
]
363 switch
-- [lindex
$args 0] {
374 set args
[lrange
$args 1 end
]
377 set cmdp
[_git_cmd
[lindex
$args 0]]
378 set args
[lrange
$args 1 end
]
380 return [eval $opt $cmdp $args]
383 proc _open_stdout_stderr
{cmd
} {
387 if { [lindex
$cmd end
] eq
{2>@
1}
388 && $err eq
{can not
find channel named
"1"}
390 # Older versions of Tcl 8.4 don't have this 2>@1 IO
391 # redirect operator. Fallback to |& cat for those.
392 # The command was not actually started, so its safe
393 # to try to start it a second time.
395 set fd
[open
[concat \
396 [lrange
$cmd 0 end-1
] \
403 fconfigure
$fd -eofchar {}
407 proc git_read
{args
} {
411 switch
-- [lindex
$args 0] {
426 set args
[lrange
$args 1 end
]
429 set cmdp
[_git_cmd
[lindex
$args 0]]
430 set args
[lrange
$args 1 end
]
432 return [_open_stdout_stderr
[concat
$opt $cmdp $args]]
435 proc git_write
{args
} {
439 switch
-- [lindex
$args 0] {
450 set args
[lrange
$args 1 end
]
453 set cmdp
[_git_cmd
[lindex
$args 0]]
454 set args
[lrange
$args 1 end
]
456 return [open
[concat
$opt $cmdp $args] w
]
460 regsub
-all ' $value "'\\''" value
464 proc load_current_branch {} {
465 global current_branch is_detached
467 set fd [open [gitdir HEAD] r]
468 if {[gets $fd ref] < 1} {
473 set pfx {ref: refs/heads/}
474 set len [string length $pfx]
475 if {[string equal -length $len $pfx $ref]} {
476 # We're on a branch. It might not exist. But
477 # HEAD looks good enough to be a branch.
479 set current_branch [string range $ref $len end]
482 # Assume this is a detached head.
484 set current_branch HEAD
489 auto_load tk_optionMenu
490 rename tk_optionMenu real__tkOptionMenu
491 proc tk_optionMenu {w varName args} {
492 set m [eval real__tkOptionMenu $w $varName $args]
493 $m configure -font font_ui
494 $w configure -font font_ui
498 ######################################################################
502 set _git [_which git]
504 catch {wm withdraw .}
505 error_popup "Cannot
find git
in PATH.
"
509 ######################################################################
513 if {[catch {set _git_version [git --version]} err]} {
514 catch {wm withdraw .}
518 -title "git-gui
: fatal error
" \
519 -message "Cannot determine Git version
:
523 [appname
] requires Git
1.5.0 or later.
"
526 if {![regsub {^git version } $_git_version {} _git_version]} {
527 catch {wm withdraw .}
531 -title "git-gui
: fatal error
" \
532 -message "Cannot parse Git version string
:\n\n$_git_version"
536 set _real_git_version $_git_version
537 regsub -- {-dirty$} $_git_version {} _git_version
538 regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version
539 regsub {\.rc[0-9]+$} $_git_version {} _git_version
540 regsub {\.GIT$} $_git_version {} _git_version
542 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
543 catch {wm withdraw .}
548 -title "[appname
]: warning
" \
549 -message "Git version cannot be determined.
551 $_git claims it is version
'$_real_git_version'.
553 [appname
] requires
at least Git
1.5.0 or later.
555 Assume
'$_real_git_version' is version
1.5.0?
557 set _git_version 1.5.0
562 unset _real_git_version
564 proc git-version {args} {
567 switch [llength $args] {
573 set op [lindex $args 0]
574 set vr [lindex $args 1]
575 set cm [package vcompare $_git_version $vr]
576 return [expr $cm $op 0]
580 set type [lindex $args 0]
581 set name [lindex $args 1]
582 set parm [lindex $args 2]
583 set body [lindex $args 3]
585 if {($type ne {proc} && $type ne {method})} {
586 error "Invalid arguments to git-version
"
588 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
589 error "Last arm of
$type $name must be default
"
592 foreach {op vr cb} [lrange $body 0 end-2] {
593 if {[git-version $op $vr]} {
594 return [uplevel [list $type $name $parm $cb]]
598 return [uplevel [list $type $name $parm [lindex $body end]]]
602 error "git-version
>= x
"
608 if {[git-version < 1.5]} {
609 catch {wm withdraw .}
613 -title "git-gui
: fatal error
" \
614 -message "[appname
] requires Git
1.5.0 or later.
616 You are using
[git-version
]:
622 ######################################################################
624 ## configure our library
626 set idx [file join $oguilib tclIndex]
627 if {[catch {set fd [open $idx r]} err]} {
628 catch {wm withdraw .}
632 -title "git-gui
: fatal error
" \
636 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
638 while {[gets $fd n] >= 0} {
639 if {$n ne {} && ![string match #* $n]} {
651 if {[lsearch -exact $loaded $p] >= 0} continue
652 source [file join $oguilib $p]
657 set auto_path [concat [list $oguilib] $auto_path]
659 unset -nocomplain idx fd
661 ######################################################################
663 ## feature option selection
665 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
670 if {$subcommand eq {gui.sh}} {
673 if {$subcommand eq {gui} && [llength $argv] > 0} {
674 set subcommand [lindex $argv 0]
675 set argv [lrange $argv 1 end]
678 enable_option multicommit
680 enable_option transport
683 switch -- $subcommand {
688 disable_option multicommit
689 disable_option branch
690 disable_option transport
693 enable_option singlecommit
695 disable_option multicommit
696 disable_option branch
697 disable_option transport
701 ######################################################################
706 set _gitdir $env(GIT_DIR)
710 set _gitdir [git rev-parse --git-dir]
711 set _prefix [git rev-parse --show-prefix]
713 catch {wm withdraw .}
714 error_popup "Cannot
find the git directory
:\n\n$err"
717 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
718 catch {set _gitdir [exec cygpath --unix $_gitdir]}
720 if {![file isdirectory $_gitdir]} {
721 catch {wm withdraw .}
722 error_popup "Git directory not found
:\n\n$_gitdir"
725 if {$_prefix ne {}} {
726 regsub -all {[^/]+/} $_prefix ../ cdup
727 if {[catch {cd $cdup} err]} {
728 catch {wm withdraw .}
729 error_popup "Cannot move to top of working directory
:\n\n$err"
733 } elseif {![is_enabled bare]} {
734 if {[lindex [file split $_gitdir] end] ne {.git}} {
735 catch {wm withdraw .}
736 error_popup "Cannot use funny .git directory
:\n\n$_gitdir"
739 if {[catch {cd [file dirname $_gitdir]} err]} {
740 catch {wm withdraw .}
741 error_popup "No working directory
[file dirname $_gitdir]:\n\n$err"
745 set _reponame [file split [file normalize $_gitdir]]
746 if {[lindex $_reponame end] eq {.git}} {
747 set _reponame [lindex $_reponame end-1]
749 set _reponame [lindex $_reponame end]
752 ######################################################################
756 set current_diff_path {}
757 set current_diff_side {}
758 set diff_actions [list]
762 set MERGE_HEAD [list]
765 set current_branch {}
767 set current_diff_path {}
769 set selected_commit_type new
771 ######################################################################
779 set disable_on_lock [list]
780 set index_lock_type none
782 proc lock_index {type} {
783 global index_lock_type disable_on_lock
785 if {$index_lock_type eq {none}} {
786 set index_lock_type $type
787 foreach w $disable_on_lock {
788 uplevel #0 $w disabled
791 } elseif {$index_lock_type eq "begin-
$type"} {
792 set index_lock_type $type
798 proc unlock_index {} {
799 global index_lock_type disable_on_lock
801 set index_lock_type none
802 foreach w $disable_on_lock {
807 ######################################################################
811 proc repository_state {ctvar hdvar mhvar} {
812 global current_branch
813 upvar $ctvar ct $hdvar hd $mhvar mh
818 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
824 set merge_head [gitdir MERGE_HEAD]
825 if {[file exists $merge_head]} {
827 set fd_mh [open $merge_head r]
828 while {[gets $fd_mh line] >= 0} {
839 global PARENT empty_tree
841 set p [lindex $PARENT 0]
845 if {$empty_tree eq {}} {
846 set empty_tree [git mktree << {}]
851 proc rescan {after {honor_trustmtime 1}} {
852 global HEAD PARENT MERGE_HEAD commit_type
853 global ui_index ui_workdir ui_comm
854 global rescan_active file_states
857 if {$rescan_active > 0 || ![lock_index read]} return
859 repository_state newType newHEAD newMERGE_HEAD
860 if {[string match amend* $commit_type]
861 && $newType eq {normal}
862 && $newHEAD eq $HEAD} {
866 set MERGE_HEAD $newMERGE_HEAD
867 set commit_type $newType
870 array unset file_states
872 if {!$::GITGUI_BCK_exists &&
873 (![$ui_comm edit modified]
874 || [string trim [$ui_comm get 0.0 end]] eq {})} {
875 if {[string match amend* $commit_type]} {
876 } elseif {[load_message GITGUI_MSG]} {
877 } elseif {[load_message MERGE_MSG]} {
878 } elseif {[load_message SQUASH_MSG]} {
881 $ui_comm edit modified false
884 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
885 rescan_stage2 {} $after
888 ui_status {Refreshing file status...}
889 set fd_rf [git_read update-index \
895 fconfigure $fd_rf -blocking 0 -translation binary
896 fileevent $fd_rf readable \
897 [list rescan_stage2 $fd_rf $after]
901 proc rescan_stage2 {fd after} {
902 global rescan_active buf_rdi buf_rdf buf_rlo
906 if {![eof $fd]} return
910 set ls_others [list --exclude-per-directory=.gitignore]
911 set info_exclude [gitdir info exclude]
912 if {[file readable $info_exclude]} {
913 lappend ls_others "--exclude-from=$info_exclude"
915 set user_exclude [get_config core.excludesfile]
916 if {$user_exclude ne {} && [file readable $user_exclude]} {
917 lappend ls_others "--exclude-from=$user_exclude"
925 ui_status {Scanning for modified files ...}
926 set fd_di [git_read diff-index --cached -z [PARENT]]
927 set fd_df [git_read diff-files -z]
928 set fd_lo [eval git_read ls-files --others -z $ls_others]
930 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
931 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
932 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
933 fileevent $fd_di readable [list read_diff_index $fd_di $after]
934 fileevent $fd_df readable [list read_diff_files $fd_df $after]
935 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
938 proc load_message {file} {
942 if {[file isfile $f]} {
943 if {[catch {set fd [open $f r]}]} {
946 fconfigure $fd -eofchar {}
947 set content [string trim [read $fd]]
949 regsub -all -line {[ \r\t]+$} $content {} content
950 $ui_comm delete 0.0 end
951 $ui_comm insert end $content
957 proc read_diff_index {fd after} {
960 append buf_rdi [read $fd]
962 set n [string length $buf_rdi]
964 set z1 [string first "\
0" $buf_rdi $c]
967 set z2 [string first "\
0" $buf_rdi $z1]
971 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
972 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
974 [encoding convertfrom $p] \
976 [list [lindex $i 0] [lindex $i 2]] \
982 set buf_rdi [string range $buf_rdi $c end]
987 rescan_done $fd buf_rdi $after
990 proc read_diff_files {fd after} {
993 append buf_rdf [read $fd]
995 set n [string length $buf_rdf]
997 set z1 [string first "\
0" $buf_rdf $c]
1000 set z2 [string first "\
0" $buf_rdf $z1]
1001 if {$z2 == -1} break
1004 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1005 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1007 [encoding convertfrom $p] \
1010 [list [lindex $i 0] [lindex $i 2]]
1015 set buf_rdf [string range $buf_rdf $c end]
1020 rescan_done $fd buf_rdf $after
1023 proc read_ls_others {fd after} {
1026 append buf_rlo [read $fd]
1027 set pck [split $buf_rlo "\
0"]
1028 set buf_rlo [lindex $pck end]
1029 foreach p [lrange $pck 0 end-1] {
1030 merge_state [encoding convertfrom $p] ?O
1032 rescan_done $fd buf_rlo $after
1035 proc rescan_done {fd buf after} {
1036 global rescan_active current_diff_path
1037 global file_states repo_config
1040 if {![eof $fd]} return
1043 if {[incr rescan_active -1] > 0} return
1048 if {$current_diff_path ne {}} reshow_diff
1052 proc prune_selection {} {
1053 global file_states selected_paths
1055 foreach path [array names selected_paths] {
1056 if {[catch {set still_here $file_states($path)}]} {
1057 unset selected_paths($path)
1062 ######################################################################
1066 proc mapicon {w state path} {
1069 if {[catch {set r $all_icons($state$w)}]} {
1070 puts "error
: no icon
for $w state
={$state} $path"
1076 proc mapdesc {state path} {
1079 if {[catch {set r $all_descs($state)}]} {
1080 puts "error
: no desc
for state
={$state} $path"
1086 proc ui_status {msg} {
1087 $::main_status show $msg
1090 proc ui_ready {{test {}}} {
1091 $::main_status show {Ready.} $test
1094 proc escape_path {path} {
1095 regsub -all {\\} $path "\\\\" path
1096 regsub -all "\n" $path "\\n
" path
1100 proc short_path {path} {
1101 return [escape_path [lindex [file split $path] end]]
1105 set null_sha1 [string repeat 0 40]
1107 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1108 global file_states next_icon_id null_sha1
1110 set s0 [string index $new_state 0]
1111 set s1 [string index $new_state 1]
1113 if {[catch {set info $file_states($path)}]} {
1115 set icon n[incr next_icon_id]
1117 set state [lindex $info 0]
1118 set icon [lindex $info 1]
1119 if {$head_info eq {}} {set head_info [lindex $info 2]}
1120 if {$index_info eq {}} {set index_info [lindex $info 3]}
1123 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1124 elseif {$s0 eq {_}} {set s0 _}
1126 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1127 elseif {$s1 eq {_}} {set s1 _}
1129 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1130 set head_info [list 0 $null_sha1]
1131 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1132 && $head_info eq {}} {
1133 set head_info $index_info
1136 set file_states($path) [list $s0$s1 $icon \
1137 $head_info $index_info \
1142 proc display_file_helper {w path icon_name old_m new_m} {
1145 if {$new_m eq {_}} {
1146 set lno [lsearch -sorted -exact $file_lists($w) $path]
1148 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1150 $w conf -state normal
1151 $w delete $lno.0 [expr {$lno + 1}].0
1152 $w conf -state disabled
1154 } elseif {$old_m eq {_} && $new_m ne {_}} {
1155 lappend file_lists($w) $path
1156 set file_lists($w) [lsort -unique $file_lists($w)]
1157 set lno [lsearch -sorted -exact $file_lists($w) $path]
1159 $w conf -state normal
1160 $w image create $lno.0 \
1161 -align center -padx 5 -pady 1 \
1163 -image [mapicon $w $new_m $path]
1164 $w insert $lno.1 "[escape_path
$path]\n"
1165 $w conf -state disabled
1166 } elseif {$old_m ne $new_m} {
1167 $w conf -state normal
1168 $w image conf $icon_name -image [mapicon $w $new_m $path]
1169 $w conf -state disabled
1173 proc display_file {path state} {
1174 global file_states selected_paths
1175 global ui_index ui_workdir
1177 set old_m [merge_state $path $state]
1178 set s $file_states($path)
1179 set new_m [lindex $s 0]
1180 set icon_name [lindex $s 1]
1182 set o [string index $old_m 0]
1183 set n [string index $new_m 0]
1190 display_file_helper $ui_index $path $icon_name $o $n
1192 if {[string index $old_m 0] eq {U}} {
1195 set o [string index $old_m 1]
1197 if {[string index $new_m 0] eq {U}} {
1200 set n [string index $new_m 1]
1202 display_file_helper $ui_workdir $path $icon_name $o $n
1204 if {$new_m eq {__}} {
1205 unset file_states($path)
1206 catch {unset selected_paths($path)}
1210 proc display_all_files_helper {w path icon_name m} {
1213 lappend file_lists($w) $path
1214 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1215 $w image create end \
1216 -align center -padx 5 -pady 1 \
1218 -image [mapicon $w $m $path]
1219 $w insert end "[escape_path
$path]\n"
1222 proc display_all_files {} {
1223 global ui_index ui_workdir
1224 global file_states file_lists
1227 $ui_index conf -state normal
1228 $ui_workdir conf -state normal
1230 $ui_index delete 0.0 end
1231 $ui_workdir delete 0.0 end
1234 set file_lists($ui_index) [list]
1235 set file_lists($ui_workdir) [list]
1237 foreach path [lsort [array names file_states]] {
1238 set s $file_states($path)
1240 set icon_name [lindex $s 1]
1242 set s [string index $m 0]
1243 if {$s ne {U} && $s ne {_}} {
1244 display_all_files_helper $ui_index $path \
1248 if {[string index $m 0] eq {U}} {
1251 set s [string index $m 1]
1254 display_all_files_helper $ui_workdir $path \
1259 $ui_index conf -state disabled
1260 $ui_workdir conf -state disabled
1263 ######################################################################
1268 #define mask_width 14
1269 #define mask_height 15
1270 static unsigned char mask_bits[] = {
1271 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1272 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1273 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1276 image create bitmap file_plain -background white -foreground black -data {
1277 #define plain_width 14
1278 #define plain_height 15
1279 static unsigned char plain_bits[] = {
1280 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1281 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1282 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1283 } -maskdata $filemask
1285 image create bitmap file_mod -background white -foreground blue -data {
1286 #define mod_width 14
1287 #define mod_height 15
1288 static unsigned char mod_bits[] = {
1289 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1290 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1291 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1292 } -maskdata $filemask
1294 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1295 #define file_fulltick_width 14
1296 #define file_fulltick_height 15
1297 static unsigned char file_fulltick_bits
[] = {
1298 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1299 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1300 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1301 } -maskdata $filemask
1303 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
1304 #define parttick_width 14
1305 #define parttick_height 15
1306 static unsigned char parttick_bits
[] = {
1307 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1308 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
1309 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1310 } -maskdata $filemask
1312 image create bitmap file_question
-background white
-foreground black
-data {
1313 #define file_question_width 14
1314 #define file_question_height 15
1315 static unsigned char file_question_bits
[] = {
1316 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1317 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1318 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1319 } -maskdata $filemask
1321 image create bitmap file_removed
-background white
-foreground red
-data {
1322 #define file_removed_width 14
1323 #define file_removed_height 15
1324 static unsigned char file_removed_bits
[] = {
1325 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1326 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1327 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1328 } -maskdata $filemask
1330 image create bitmap file_merge
-background white
-foreground blue
-data {
1331 #define file_merge_width 14
1332 #define file_merge_height 15
1333 static unsigned char file_merge_bits
[] = {
1334 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1335 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1336 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1337 } -maskdata $filemask
1339 set ui_index .vpane.files.index.list
1340 set ui_workdir .vpane.files.workdir.list
1342 set all_icons
(_
$ui_index) file_plain
1343 set all_icons
(A
$ui_index) file_fulltick
1344 set all_icons
(M
$ui_index) file_fulltick
1345 set all_icons
(D
$ui_index) file_removed
1346 set all_icons
(U
$ui_index) file_merge
1348 set all_icons
(_
$ui_workdir) file_plain
1349 set all_icons
(M
$ui_workdir) file_mod
1350 set all_icons
(D
$ui_workdir) file_question
1351 set all_icons
(U
$ui_workdir) file_merge
1352 set all_icons
(O
$ui_workdir) file_plain
1354 set max_status_desc
0
1358 {_M
"Modified, not staged"}
1359 {M_
"Staged for commit"}
1360 {MM
"Portions staged for commit"}
1361 {MD
"Staged for commit, missing"}
1363 {_O
"Untracked, not staged"}
1364 {A_
"Staged for commit"}
1365 {AM
"Portions staged for commit"}
1366 {AD
"Staged for commit, missing"}
1369 {D_
"Staged for removal"}
1370 {DO
"Staged for removal, still present"}
1372 {U_
"Requires merge resolution"}
1373 {UU
"Requires merge resolution"}
1374 {UM
"Requires merge resolution"}
1375 {UD
"Requires merge resolution"}
1377 if {$max_status_desc < [string length
[lindex
$i 1]]} {
1378 set max_status_desc
[string length
[lindex
$i 1]]
1380 set all_descs
([lindex
$i 0]) [lindex
$i 1]
1384 ######################################################################
1388 proc bind_button3
{w cmd
} {
1389 bind $w <Any-Button-3
> $cmd
1391 # Mac OS X sends Button-2 on right click through three-button mouse,
1392 # or through trackpad right-clicking (two-finger touch + click).
1393 bind $w <Any-Button-2
> $cmd
1394 bind $w <Control-Button-1
> $cmd
1398 proc scrollbar2many
{list mode args
} {
1399 foreach w
$list {eval $w $mode $args}
1402 proc many2scrollbar
{list mode sb top bottom
} {
1403 $sb set $top $bottom
1404 foreach w
$list {$w $mode moveto
$top}
1407 proc incr_font_size
{font
{amt
1}} {
1408 set sz
[font configure
$font -size]
1410 font configure
$font -size $sz
1411 font configure
${font}bold
-size $sz
1412 font configure
${font}italic
-size $sz
1415 ######################################################################
1419 set starting_gitk_msg
{Starting gitk... please
wait...
}
1421 proc do_gitk
{revs
} {
1422 # -- Always start gitk through whatever we were loaded with. This
1423 # lets us bypass using shell process on Windows systems.
1425 set exe
[file join [file dirname $
::_git
] gitk
]
1426 set cmd
[list
[info nameofexecutable
] $exe]
1427 if {! [file exists
$exe]} {
1428 error_popup
"Unable to start gitk:\n\n$exe does not exist"
1430 eval exec $cmd $revs &
1431 ui_status $
::starting_gitk_msg
1433 ui_ready
$starting_gitk_msg
1441 global ui_comm is_quitting repo_config commit_type
1442 global GITGUI_BCK_exists GITGUI_BCK_i
1444 if {$is_quitting} return
1447 if {[winfo exists
$ui_comm]} {
1448 # -- Stash our current commit buffer.
1450 set save
[gitdir GITGUI_MSG
]
1451 if {$GITGUI_BCK_exists && ![$ui_comm edit modified
]} {
1452 file rename
-force [gitdir GITGUI_BCK
] $save
1453 set GITGUI_BCK_exists
0
1455 set msg
[string trim
[$ui_comm get
0.0 end
]]
1456 regsub
-all -line {[ \r\t]+$
} $msg {} msg
1457 if {(![string match amend
* $commit_type]
1458 ||
[$ui_comm edit modified
])
1461 set fd
[open
$save w
]
1462 puts
-nonewline $fd $msg
1466 catch
{file delete
$save}
1470 # -- Remove our editor backup, its not needed.
1472 after cancel
$GITGUI_BCK_i
1473 if {$GITGUI_BCK_exists} {
1474 catch
{file delete
[gitdir GITGUI_BCK
]}
1477 # -- Stash our current window geometry into this repository.
1479 set cfg_geometry
[list
]
1480 lappend cfg_geometry
[wm geometry .
]
1481 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
1482 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
1483 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
1486 if {$cfg_geometry ne
$rc_geometry} {
1487 catch
{git config gui.geometry
$cfg_geometry}
1502 proc toggle_or_diff
{w x y
} {
1503 global file_states file_lists current_diff_path ui_index ui_workdir
1504 global last_clicked selected_paths
1506 set pos
[split [$w index @
$x,$y] .
]
1507 set lno
[lindex
$pos 0]
1508 set col [lindex
$pos 1]
1509 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
1515 set last_clicked
[list
$w $lno]
1516 array
unset selected_paths
1517 $ui_index tag remove in_sel
0.0 end
1518 $ui_workdir tag remove in_sel
0.0 end
1521 if {$current_diff_path eq
$path} {
1522 set after
{reshow_diff
;}
1526 if {$w eq
$ui_index} {
1528 "Unstaging [short_path $path] from commit" \
1530 [concat
$after [list ui_ready
]]
1531 } elseif
{$w eq
$ui_workdir} {
1533 "Adding [short_path $path]" \
1535 [concat
$after [list ui_ready
]]
1538 show_diff
$path $w $lno
1542 proc add_one_to_selection
{w x y
} {
1543 global file_lists last_clicked selected_paths
1545 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
1546 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
1552 if {$last_clicked ne
{}
1553 && [lindex
$last_clicked 0] ne
$w} {
1554 array
unset selected_paths
1555 [lindex
$last_clicked 0] tag remove in_sel
0.0 end
1558 set last_clicked
[list
$w $lno]
1559 if {[catch
{set in_sel
$selected_paths($path)}]} {
1563 unset selected_paths
($path)
1564 $w tag remove in_sel
$lno.0 [expr {$lno + 1}].0
1566 set selected_paths
($path) 1
1567 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
1571 proc add_range_to_selection
{w x y
} {
1572 global file_lists last_clicked selected_paths
1574 if {[lindex
$last_clicked 0] ne
$w} {
1575 toggle_or_diff
$w $x $y
1579 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
1580 set lc
[lindex
$last_clicked 1]
1589 foreach path
[lrange
$file_lists($w) \
1590 [expr {$begin - 1}] \
1591 [expr {$end - 1}]] {
1592 set selected_paths
($path) 1
1594 $w tag add in_sel
$begin.0 [expr {$end + 1}].0
1597 ######################################################################
1601 set cursor_ptr arrow
1602 font create font_diff
-family Courier
-size 10
1606 eval font configure font_ui
[font actual
[.dummy cget
-font]]
1610 font create font_uiitalic
1611 font create font_uibold
1612 font create font_diffbold
1613 font create font_diffitalic
1615 foreach class
{Button Checkbutton Entry Label
1616 Labelframe Listbox Menu Message
1617 Radiobutton Spinbox Text
} {
1618 option add
*$class.font font_ui
1622 if {[is_Windows
] ||
[is_MacOSX
]} {
1623 option add
*Menu.tearOff
0
1634 proc apply_config
{} {
1635 global repo_config font_descs
1637 foreach option
$font_descs {
1638 set name
[lindex
$option 0]
1639 set font
[lindex
$option 1]
1641 foreach
{cn cv
} $repo_config(gui.
$name) {
1642 font configure
$font $cn $cv
1645 error_popup
"Invalid font specified in gui.$name:\n\n$err"
1647 foreach
{cn cv
} [font configure
$font] {
1648 font configure
${font}bold
$cn $cv
1649 font configure
${font}italic
$cn $cv
1651 font configure
${font}bold
-weight bold
1652 font configure
${font}italic
-slant italic
1656 set default_config
(merge.diffstat
) true
1657 set default_config
(merge.summary
) false
1658 set default_config
(merge.verbosity
) 2
1659 set default_config
(user.name
) {}
1660 set default_config
(user.email
) {}
1662 set default_config
(gui.matchtrackingbranch
) false
1663 set default_config
(gui.pruneduringfetch
) false
1664 set default_config
(gui.trustmtime
) false
1665 set default_config
(gui.diffcontext
) 5
1666 set default_config
(gui.newbranchtemplate
) {}
1667 set default_config
(gui.fontui
) [font configure font_ui
]
1668 set default_config
(gui.fontdiff
) [font configure font_diff
]
1670 {fontui font_ui
{Main Font
}}
1671 {fontdiff font_diff
{Diff
/Console Font
}}
1676 ######################################################################
1684 menu .mbar
-tearoff 0
1685 .mbar add cascade
-label Repository
-menu .mbar.repository
1686 .mbar add cascade
-label Edit
-menu .mbar.edit
1687 if {[is_enabled branch
]} {
1688 .mbar add cascade
-label Branch
-menu .mbar.branch
1690 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
1691 .mbar add cascade
-label Commit
-menu .mbar.commit
1693 if {[is_enabled transport
]} {
1694 .mbar add cascade
-label Merge
-menu .mbar.merge
1695 .mbar add cascade
-label Fetch
-menu .mbar.fetch
1696 .mbar add cascade
-label Push
-menu .mbar.push
1698 . configure
-menu .mbar
1700 # -- Repository Menu
1702 menu .mbar.repository
1704 .mbar.repository add
command \
1705 -label {Browse Current Branch
's Files} \
1706 -command {browser::new $current_branch}
1707 set ui_browse_current [.mbar.repository index last]
1708 .mbar.repository add command \
1709 -label {Browse Branch Files...} \
1710 -command browser_open::dialog
1711 .mbar.repository add separator
1713 .mbar.repository add command \
1714 -label {Visualize Current Branch's History
} \
1715 -command {do_gitk
$current_branch}
1716 set ui_visualize_current
[.mbar.repository index last
]
1717 .mbar.repository add
command \
1718 -label {Visualize All Branch History
} \
1719 -command {do_gitk
--all}
1720 .mbar.repository add separator
1722 proc current_branch_write
{args
} {
1723 global current_branch
1724 .mbar.repository entryconf $
::ui_browse_current \
1725 -label "Browse $current_branch's Files"
1726 .mbar.repository entryconf $
::ui_visualize_current \
1727 -label "Visualize $current_branch's History"
1729 trace add variable current_branch
write current_branch_write
1731 if {[is_enabled multicommit
]} {
1732 .mbar.repository add
command -label {Database Statistics
} \
1735 .mbar.repository add
command -label {Compress Database
} \
1738 .mbar.repository add
command -label {Verify Database
} \
1739 -command do_fsck_objects
1741 .mbar.repository add separator
1744 .mbar.repository add
command \
1745 -label {Create Desktop Icon
} \
1746 -command do_cygwin_shortcut
1747 } elseif
{[is_Windows
]} {
1748 .mbar.repository add
command \
1749 -label {Create Desktop Icon
} \
1750 -command do_windows_shortcut
1751 } elseif
{[is_MacOSX
]} {
1752 .mbar.repository add
command \
1753 -label {Create Desktop Icon
} \
1754 -command do_macosx_app
1758 .mbar.repository add
command -label Quit \
1765 .mbar.edit add
command -label Undo \
1766 -command {catch
{[focus
] edit undo
}} \
1768 .mbar.edit add
command -label Redo \
1769 -command {catch
{[focus
] edit redo
}} \
1771 .mbar.edit add separator
1772 .mbar.edit add
command -label Cut \
1773 -command {catch
{tk_textCut
[focus
]}} \
1775 .mbar.edit add
command -label Copy \
1776 -command {catch
{tk_textCopy
[focus
]}} \
1778 .mbar.edit add
command -label Paste \
1779 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
1781 .mbar.edit add
command -label Delete \
1782 -command {catch
{[focus
] delete sel.first sel.last
}} \
1784 .mbar.edit add separator
1785 .mbar.edit add
command -label {Select All
} \
1786 -command {catch
{[focus
] tag add sel
0.0 end
}} \
1791 if {[is_enabled branch
]} {
1794 .mbar.branch add
command -label {Create...
} \
1795 -command branch_create
::dialog \
1797 lappend disable_on_lock
[list .mbar.branch entryconf \
1798 [.mbar.branch index last
] -state]
1800 .mbar.branch add
command -label {Checkout...
} \
1801 -command branch_checkout
::dialog \
1803 lappend disable_on_lock
[list .mbar.branch entryconf \
1804 [.mbar.branch index last
] -state]
1806 .mbar.branch add
command -label {Rename...
} \
1807 -command branch_rename
::dialog
1808 lappend disable_on_lock
[list .mbar.branch entryconf \
1809 [.mbar.branch index last
] -state]
1811 .mbar.branch add
command -label {Delete...
} \
1812 -command branch_delete
::dialog
1813 lappend disable_on_lock
[list .mbar.branch entryconf \
1814 [.mbar.branch index last
] -state]
1816 .mbar.branch add
command -label {Reset...
} \
1817 -command merge
::reset_hard
1818 lappend disable_on_lock
[list .mbar.branch entryconf \
1819 [.mbar.branch index last
] -state]
1824 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
1827 .mbar.commit add radiobutton \
1828 -label {New Commit
} \
1829 -command do_select_commit_type \
1830 -variable selected_commit_type \
1832 lappend disable_on_lock \
1833 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1835 .mbar.commit add radiobutton \
1836 -label {Amend Last Commit
} \
1837 -command do_select_commit_type \
1838 -variable selected_commit_type \
1840 lappend disable_on_lock \
1841 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1843 .mbar.commit add separator
1845 .mbar.commit add
command -label Rescan \
1846 -command do_rescan \
1848 lappend disable_on_lock \
1849 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1851 .mbar.commit add
command -label {Stage To Commit
} \
1852 -command do_add_selection
1853 lappend disable_on_lock \
1854 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1856 .mbar.commit add
command -label {Stage Changed Files To Commit
} \
1857 -command do_add_all \
1859 lappend disable_on_lock \
1860 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1862 .mbar.commit add
command -label {Unstage From Commit
} \
1863 -command do_unstage_selection
1864 lappend disable_on_lock \
1865 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1867 .mbar.commit add
command -label {Revert Changes
} \
1868 -command do_revert_selection
1869 lappend disable_on_lock \
1870 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1872 .mbar.commit add separator
1874 .mbar.commit add
command -label {Sign Off
} \
1875 -command do_signoff \
1878 .mbar.commit add
command -label Commit \
1879 -command do_commit \
1880 -accelerator $M1T-Return
1881 lappend disable_on_lock \
1882 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1887 if {[is_enabled branch
]} {
1889 .mbar.merge add
command -label {Local Merge...
} \
1890 -command merge
::dialog \
1892 lappend disable_on_lock \
1893 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
1894 .mbar.merge add
command -label {Abort Merge...
} \
1895 -command merge
::reset_hard
1896 lappend disable_on_lock \
1897 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
1902 if {[is_enabled transport
]} {
1906 .mbar.push add
command -label {Push...
} \
1907 -command do_push_anywhere \
1909 .mbar.push add
command -label {Delete...
} \
1910 -command remote_branch_delete
::dialog
1914 # -- Apple Menu (Mac OS X only)
1916 .mbar add cascade
-label Apple
-menu .mbar.apple
1919 .mbar.apple add
command -label "About [appname]" \
1921 .mbar.apple add
command -label "Options..." \
1926 .mbar.edit add separator
1927 .mbar.edit add
command -label {Options...
} \
1933 .mbar add cascade
-label Help
-menu .mbar.
help
1937 .mbar.
help add
command -label "About [appname]" \
1942 catch
{set browser
$repo_config(instaweb.browser
)}
1943 set doc_path
[file dirname [gitexec
]]
1944 set doc_path
[file join $doc_path Documentation index.html
]
1947 set doc_path
[exec cygpath
--mixed $doc_path]
1950 if {$browser eq
{}} {
1953 } elseif
{[is_Cygwin
]} {
1954 set program_files
[file dirname [exec cygpath
--windir]]
1955 set program_files
[file join $program_files {Program Files
}]
1956 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
1957 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
1958 if {[file exists
$firefox]} {
1959 set browser
$firefox
1960 } elseif
{[file exists
$ie]} {
1963 unset program_files firefox ie
1967 if {[file isfile
$doc_path]} {
1968 set doc_url
"file:$doc_path"
1970 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
1973 if {$browser ne
{}} {
1974 .mbar.
help add
command -label {Online Documentation
} \
1975 -command [list
exec $browser $doc_url &]
1977 unset browser doc_path doc_url
1980 bind .
<Visibility
> {
1981 bind .
<Visibility
> {}
1985 # -- Standard bindings
1987 wm protocol . WM_DELETE_WINDOW do_quit
1988 bind all
<$M1B-Key-q> do_quit
1989 bind all
<$M1B-Key-Q> do_quit
1990 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
1991 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
1993 set subcommand_args
{}
1995 puts stderr
"usage: $::argv0 $::subcommand $::subcommand_args"
1999 # -- Not a normal commit type invocation? Do that instead!
2001 switch
-- $subcommand {
2004 set subcommand_args
{rev? path
}
2005 if {$argv eq
{}} usage
2010 if {$is_path ||
[file exists
$_prefix$a]} {
2011 if {$path ne
{}} usage
2014 } elseif
{$a eq
{--}} {
2016 if {$head ne
{}} usage
2021 } elseif
{$head eq
{}} {
2022 if {$head ne
{}} usage
2031 if {$head ne
{} && $path eq
{}} {
2032 set path
$_prefix$head
2039 if {[regexp
{^
[0-9a-f]{1,39}$
} $head]} {
2041 set head [git rev-parse
--verify $head]
2047 set current_branch
$head
2050 switch
-- $subcommand {
2053 if {$path ne
{} && [file isdirectory
$path]} {
2054 set head $current_branch
2060 browser
::new
$head $path
2063 if {$head eq
{} && ![file exists
$path]} {
2064 puts stderr
"fatal: cannot stat path $path: No such file or directory"
2067 blame
::new
$head $path
2074 if {[llength
$argv] != 0} {
2075 puts
-nonewline stderr
"usage: $argv0"
2076 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
2077 puts
-nonewline stderr
" $subcommand"
2082 # fall through to setup UI for commits
2085 puts stderr
"usage: $argv0 \[{blame|browser|citool}\]"
2096 -text {Current Branch
:} \
2100 -textvariable current_branch \
2103 pack .branch.l1
-side left
2104 pack .branch.cb
-side left
-fill x
2105 pack .branch
-side top
-fill x
2107 # -- Main Window Layout
2109 panedwindow .vpane
-orient vertical
2110 panedwindow .vpane.files
-orient horizontal
2111 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
2112 pack .vpane
-anchor n
-side top
-fill both
-expand 1
2114 # -- Index File List
2116 frame .vpane.files.index
-height 100 -width 200
2117 label .vpane.files.index.title
-text {Staged Changes
(Will Be Committed
)} \
2118 -background lightgreen
2119 text
$ui_index -background white
-borderwidth 0 \
2120 -width 20 -height 10 \
2122 -cursor $cursor_ptr \
2123 -xscrollcommand {.vpane.files.index.sx
set} \
2124 -yscrollcommand {.vpane.files.index.sy
set} \
2126 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
2127 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
2128 pack .vpane.files.index.title
-side top
-fill x
2129 pack .vpane.files.index.sx
-side bottom
-fill x
2130 pack .vpane.files.index.sy
-side right
-fill y
2131 pack
$ui_index -side left
-fill both
-expand 1
2132 .vpane.files add .vpane.files.index
-sticky nsew
2134 # -- Working Directory File List
2136 frame .vpane.files.workdir
-height 100 -width 200
2137 label .vpane.files.workdir.title
-text {Unstaged Changes
(Will Not Be Committed
)} \
2138 -background lightsalmon
2139 text
$ui_workdir -background white
-borderwidth 0 \
2140 -width 20 -height 10 \
2142 -cursor $cursor_ptr \
2143 -xscrollcommand {.vpane.files.workdir.sx
set} \
2144 -yscrollcommand {.vpane.files.workdir.sy
set} \
2146 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
2147 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
2148 pack .vpane.files.workdir.title
-side top
-fill x
2149 pack .vpane.files.workdir.sx
-side bottom
-fill x
2150 pack .vpane.files.workdir.sy
-side right
-fill y
2151 pack
$ui_workdir -side left
-fill both
-expand 1
2152 .vpane.files add .vpane.files.workdir
-sticky nsew
2154 foreach i
[list
$ui_index $ui_workdir] {
2155 $i tag conf in_diff
-background lightgray
2156 $i tag conf in_sel
-background lightgray
2160 # -- Diff and Commit Area
2162 frame .vpane.lower
-height 300 -width 400
2163 frame .vpane.lower.commarea
2164 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
2165 pack .vpane.lower.commarea
-side top
-fill x
2166 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
2167 .vpane add .vpane.lower
-sticky nsew
2169 # -- Commit Area Buttons
2171 frame .vpane.lower.commarea.buttons
2172 label .vpane.lower.commarea.buttons.l
-text {} \
2175 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
2176 pack .vpane.lower.commarea.buttons
-side left
-fill y
2178 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
2180 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
2181 lappend disable_on_lock \
2182 {.vpane.lower.commarea.buttons.rescan conf
-state}
2184 button .vpane.lower.commarea.buttons.incall
-text {Stage Changed
} \
2186 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
2187 lappend disable_on_lock \
2188 {.vpane.lower.commarea.buttons.incall conf
-state}
2190 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
2192 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
2194 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
2196 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
2197 lappend disable_on_lock \
2198 {.vpane.lower.commarea.buttons.commit conf
-state}
2200 button .vpane.lower.commarea.buttons.push
-text {Push
} \
2201 -command do_push_anywhere
2202 pack .vpane.lower.commarea.buttons.push
-side top
-fill x
2204 # -- Commit Message Buffer
2206 frame .vpane.lower.commarea.buffer
2207 frame .vpane.lower.commarea.buffer.header
2208 set ui_comm .vpane.lower.commarea.buffer.t
2209 set ui_coml .vpane.lower.commarea.buffer.header.l
2210 radiobutton .vpane.lower.commarea.buffer.header.new \
2211 -text {New Commit
} \
2212 -command do_select_commit_type \
2213 -variable selected_commit_type \
2215 lappend disable_on_lock \
2216 [list .vpane.lower.commarea.buffer.header.new conf
-state]
2217 radiobutton .vpane.lower.commarea.buffer.header.amend \
2218 -text {Amend Last Commit
} \
2219 -command do_select_commit_type \
2220 -variable selected_commit_type \
2222 lappend disable_on_lock \
2223 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
2227 proc trace_commit_type
{varname args
} {
2228 global ui_coml commit_type
2229 switch
-glob -- $commit_type {
2230 initial
{set txt
{Initial Commit Message
:}}
2231 amend
{set txt
{Amended Commit Message
:}}
2232 amend-initial
{set txt
{Amended Initial Commit Message
:}}
2233 amend-merge
{set txt
{Amended Merge Commit Message
:}}
2234 merge
{set txt
{Merge Commit Message
:}}
2235 * {set txt
{Commit Message
:}}
2237 $ui_coml conf
-text $txt
2239 trace add variable commit_type
write trace_commit_type
2240 pack
$ui_coml -side left
-fill x
2241 pack .vpane.lower.commarea.buffer.header.amend
-side right
2242 pack .vpane.lower.commarea.buffer.header.new
-side right
2244 text
$ui_comm -background white
-borderwidth 1 \
2247 -autoseparators true \
2249 -width 75 -height 9 -wrap none \
2251 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
2252 scrollbar .vpane.lower.commarea.buffer.sby \
2253 -command [list
$ui_comm yview
]
2254 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
2255 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
2256 pack
$ui_comm -side left
-fill y
2257 pack .vpane.lower.commarea.buffer
-side left
-fill y
2259 # -- Commit Message Buffer Context Menu
2261 set ctxm .vpane.lower.commarea.buffer.ctxm
2262 menu
$ctxm -tearoff 0
2265 -command {tk_textCut
$ui_comm}
2268 -command {tk_textCopy
$ui_comm}
2271 -command {tk_textPaste
$ui_comm}
2274 -command {$ui_comm delete sel.first sel.last
}
2277 -label {Select All
} \
2278 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
2282 $ui_comm tag add sel
0.0 end
2283 tk_textCopy
$ui_comm
2284 $ui_comm tag remove sel
0.0 end
2290 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
2294 proc trace_current_diff_path
{varname args
} {
2295 global current_diff_path diff_actions file_states
2296 if {$current_diff_path eq
{}} {
2302 set p
$current_diff_path
2303 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
2305 set p
[escape_path
$p]
2309 .vpane.lower.
diff.header.status configure
-text $s
2310 .vpane.lower.
diff.header.
file configure
-text $f
2311 .vpane.lower.
diff.header.path configure
-text $p
2312 foreach w
$diff_actions {
2316 trace add variable current_diff_path
write trace_current_diff_path
2318 frame .vpane.lower.
diff.header
-background gold
2319 label .vpane.lower.
diff.header.status \
2321 -width $max_status_desc \
2324 label .vpane.lower.
diff.header.
file \
2328 label .vpane.lower.
diff.header.path \
2332 pack .vpane.lower.
diff.header.status
-side left
2333 pack .vpane.lower.
diff.header.
file -side left
2334 pack .vpane.lower.
diff.header.path
-fill x
2335 set ctxm .vpane.lower.
diff.header.ctxm
2336 menu
$ctxm -tearoff 0
2344 -- $current_diff_path
2346 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2347 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
2351 frame .vpane.lower.
diff.body
2352 set ui_diff .vpane.lower.
diff.body.t
2353 text
$ui_diff -background white
-borderwidth 0 \
2354 -width 80 -height 15 -wrap none \
2356 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
2357 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
2359 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
2360 -command [list
$ui_diff xview
]
2361 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
2362 -command [list
$ui_diff yview
]
2363 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
2364 pack .vpane.lower.
diff.body.sby
-side right
-fill y
2365 pack
$ui_diff -side left
-fill both
-expand 1
2366 pack .vpane.lower.
diff.header
-side top
-fill x
2367 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
2369 $ui_diff tag conf d_cr
-elide true
2370 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
2371 $ui_diff tag conf d_
+ -foreground {#00a000}
2372 $ui_diff tag conf d_-
-foreground red
2374 $ui_diff tag conf d_
++ -foreground {#00a000}
2375 $ui_diff tag conf d_--
-foreground red
2376 $ui_diff tag conf d_
+s \
2377 -foreground {#00a000} \
2378 -background {#e2effa}
2379 $ui_diff tag conf d_-s \
2381 -background {#e2effa}
2382 $ui_diff tag conf d_s
+ \
2383 -foreground {#00a000} \
2385 $ui_diff tag conf d_s- \
2389 $ui_diff tag conf d
<<<<<<< \
2390 -foreground orange \
2392 $ui_diff tag conf d
======= \
2393 -foreground orange \
2395 $ui_diff tag conf d
>>>>>>> \
2396 -foreground orange \
2399 $ui_diff tag raise sel
2401 # -- Diff Body Context Menu
2403 set ctxm .vpane.lower.
diff.body.ctxm
2404 menu
$ctxm -tearoff 0
2407 -command reshow_diff
2408 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2411 -command {tk_textCopy
$ui_diff}
2412 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2414 -label {Select All
} \
2415 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
2416 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2420 $ui_diff tag add sel
0.0 end
2421 tk_textCopy
$ui_diff
2422 $ui_diff tag remove sel
0.0 end
2424 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2427 -label {Apply
/Reverse Hunk
} \
2428 -command {apply_hunk
$cursorX $cursorY}
2429 set ui_diff_applyhunk
[$ctxm index last
]
2430 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
2433 -label {Decrease Font Size
} \
2434 -command {incr_font_size font_diff
-1}
2435 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2437 -label {Increase Font Size
} \
2438 -command {incr_font_size font_diff
1}
2439 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2442 -label {Show Less Context
} \
2443 -command {if {$repo_config(gui.diffcontext
) >= 1} {
2444 incr repo_config
(gui.diffcontext
) -1
2447 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2449 -label {Show More Context
} \
2450 -command {if {$repo_config(gui.diffcontext
) < 99} {
2451 incr repo_config
(gui.diffcontext
)
2454 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2456 $ctxm add
command -label {Options...
} \
2458 proc popup_diff_menu
{ctxm x y X Y
} {
2459 global current_diff_path file_states
2462 if {$
::ui_index eq $
::current_diff_side
} {
2464 set l
"Unstage Hunk From Commit"
2466 if {$current_diff_path eq
{}
2467 ||
![info exists file_states
($current_diff_path)]
2468 ||
{_O
} eq
[lindex
$file_states($current_diff_path) 0]} {
2473 set l
"Stage Hunk For Commit"
2475 if {$
::is_3way_diff
} {
2478 $ctxm entryconf $
::ui_diff_applyhunk
-state $s -label $l
2479 tk_popup
$ctxm $X $Y
2481 bind_button3
$ui_diff [list popup_diff_menu
$ctxm %x
%y
%X
%Y
]
2485 set main_status
[::status_bar
::new .status
]
2486 pack .status
-anchor w
-side bottom
-fill x
2487 $main_status show
{Initializing...
}
2492 set gm
$repo_config(gui.geometry
)
2493 wm geometry .
[lindex
$gm 0]
2494 .vpane sash place
0 \
2495 [lindex
[.vpane sash coord
0] 0] \
2497 .vpane.files sash place
0 \
2499 [lindex
[.vpane.files sash coord
0] 1]
2505 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
2506 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
2507 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
2508 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
2509 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
2510 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
2511 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
2512 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
2513 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
2514 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2515 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2517 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
2518 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
2519 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
2520 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
2521 bind $ui_diff <$M1B-Key-v> {break}
2522 bind $ui_diff <$M1B-Key-V> {break}
2523 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2524 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2525 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
2526 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
2527 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
2528 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
2529 bind $ui_diff <Key-k
> {catch
{%W yview scroll
-1 units
};break}
2530 bind $ui_diff <Key-j
> {catch
{%W yview scroll
1 units
};break}
2531 bind $ui_diff <Key-h
> {catch
{%W xview scroll
-1 units
};break}
2532 bind $ui_diff <Key-l
> {catch
{%W xview scroll
1 units
};break}
2533 bind $ui_diff <Control-Key-b
> {catch
{%W yview scroll
-1 pages
};break}
2534 bind $ui_diff <Control-Key-f
> {catch
{%W yview scroll
1 pages
};break}
2535 bind $ui_diff <Button-1
> {focus
%W
}
2537 if {[is_enabled branch
]} {
2538 bind .
<$M1B-Key-n> branch_create
::dialog
2539 bind .
<$M1B-Key-N> branch_create
::dialog
2540 bind .
<$M1B-Key-o> branch_checkout
::dialog
2541 bind .
<$M1B-Key-O> branch_checkout
::dialog
2542 bind .
<$M1B-Key-m> merge
::dialog
2543 bind .
<$M1B-Key-M> merge
::dialog
2545 if {[is_enabled transport
]} {
2546 bind .
<$M1B-Key-p> do_push_anywhere
2547 bind .
<$M1B-Key-P> do_push_anywhere
2550 bind .
<Key-F5
> do_rescan
2551 bind .
<$M1B-Key-r> do_rescan
2552 bind .
<$M1B-Key-R> do_rescan
2553 bind .
<$M1B-Key-s> do_signoff
2554 bind .
<$M1B-Key-S> do_signoff
2555 bind .
<$M1B-Key-i> do_add_all
2556 bind .
<$M1B-Key-I> do_add_all
2557 bind .
<$M1B-Key-Return> do_commit
2558 foreach i
[list
$ui_index $ui_workdir] {
2559 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
2560 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
2561 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
2565 set file_lists
($ui_index) [list
]
2566 set file_lists
($ui_workdir) [list
]
2568 wm title .
"[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"
2569 focus
-force $ui_comm
2571 # -- Warn the user about environmental problems. Cygwin's Tcl
2572 # does *not* pass its env array onto any processes it spawns.
2573 # This means that git processes get none of our environment.
2578 set msg
"Possible environment issues exist.
2580 The following environment variables are probably
2581 going to be ignored by any Git subprocess run
2585 foreach name
[array names env
] {
2586 switch
-regexp -- $name {
2587 {^GIT_INDEX_FILE$
} -
2588 {^GIT_OBJECT_DIRECTORY$
} -
2589 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
2591 {^GIT_EXTERNAL_DIFF$
} -
2595 {^GIT_CONFIG_LOCAL$
} -
2596 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
2597 append msg
" - $name\n"
2600 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
2601 append msg
" - $name\n"
2603 set suggest_user
$name
2607 if {$ignored_env > 0} {
2609 This is due to a known issue with the
2610 Tcl binary distributed by Cygwin."
2612 if {$suggest_user ne
{}} {
2615 A good replacement for $suggest_user
2616 is placing values for the user.name and
2617 user.email settings into your personal
2623 unset ignored_env msg suggest_user name
2626 # -- Only initialize complex UI if we are going to stay running.
2628 if {[is_enabled transport
]} {
2635 if {[winfo exists
$ui_comm]} {
2636 set GITGUI_BCK_exists
[load_message GITGUI_BCK
]
2638 # -- If both our backup and message files exist use the
2639 # newer of the two files to initialize the buffer.
2641 if {$GITGUI_BCK_exists} {
2642 set m
[gitdir GITGUI_MSG
]
2643 if {[file isfile
$m]} {
2644 if {[file mtime
[gitdir GITGUI_BCK
]] > [file mtime
$m]} {
2645 catch
{file delete
[gitdir GITGUI_MSG
]}
2647 $ui_comm delete
0.0 end
2649 $ui_comm edit modified false
2650 catch
{file delete
[gitdir GITGUI_BCK
]}
2651 set GITGUI_BCK_exists
0
2657 proc backup_commit_buffer
{} {
2658 global ui_comm GITGUI_BCK_exists
2660 set m
[$ui_comm edit modified
]
2661 if {$m ||
$GITGUI_BCK_exists} {
2662 set msg
[string trim
[$ui_comm get
0.0 end
]]
2663 regsub
-all -line {[ \r\t]+$
} $msg {} msg
2666 if {$GITGUI_BCK_exists} {
2667 catch
{file delete
[gitdir GITGUI_BCK
]}
2668 set GITGUI_BCK_exists
0
2672 set fd
[open
[gitdir GITGUI_BCK
] w
]
2673 puts
-nonewline $fd $msg
2675 set GITGUI_BCK_exists
1
2679 $ui_comm edit modified false
2682 set ::GITGUI_BCK_i
[after
2000 backup_commit_buffer
]
2685 backup_commit_buffer
2688 lock_index begin-read
2689 if {![winfo ismapped .
]} {
2693 if {[is_enabled multicommit
]} {