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 catch
{rename send
{}} ; # What an evil concept...
47 ######################################################################
49 ## enable verbose loading?
51 if {![catch
{set _verbose
$env(GITGUI_VERBOSE
)}]} {
53 rename auto_load real__auto_load
54 proc auto_load
{name args
} {
55 puts stderr
"auto_load $name"
56 return [uplevel
1 real__auto_load
$name $args]
58 rename
source real__source
60 puts stderr
"source $name"
61 uplevel
1 real__source
$name
65 ######################################################################
67 ## Fake internationalization to ease backporting of changes.
70 set cmk
[string first @@
$fmt]
72 set fmt [string range
$fmt 0 [expr {$cmk - 1}]]
74 return [eval [list format
$fmt] $args]
77 ######################################################################
81 set _appname
[lindex
[file split $argv0] end
]
98 return [eval [list
file join $_gitdir] $args]
101 proc gitexec
{args
} {
103 if {$_gitexec eq
{}} {
104 if {[catch
{set _gitexec
[git
--exec-path]} err
]} {
105 error
"Git not installed?\n\n$err"
108 set _gitexec
[exec cygpath \
113 set _gitexec
[file normalize
$_gitexec]
119 return [eval [list
file join $_gitexec] $args]
127 if {[tk windowingsystem
] eq
{aqua
}} {
134 if {$
::tcl_platform
(platform
) eq
{windows
}} {
142 if {$_iscygwin eq
{}} {
143 if {$
::tcl_platform
(platform
) eq
{windows
}} {
144 if {[catch
{set p
[exec cygpath
--windir]} err
]} {
156 proc is_enabled
{option
} {
157 global enabled_options
158 if {[catch
{set on
$enabled_options($option)}]} {return 0}
162 proc enable_option
{option
} {
163 global enabled_options
164 set enabled_options
($option) 1
167 proc disable_option
{option
} {
168 global enabled_options
169 set enabled_options
($option) 0
172 ######################################################################
176 proc is_many_config
{name
} {
177 switch
-glob -- $name {
186 proc is_config_true
{name
} {
188 if {[catch
{set v
$repo_config($name)}]} {
190 } elseif
{$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes}} {
197 proc get_config
{name
} {
199 if {[catch
{set v
$repo_config($name)}]} {
206 proc load_config
{include_global
} {
207 global repo_config global_config default_config
209 array
unset global_config
210 if {$include_global} {
212 set fd_rc
[git_read config
--global --list]
213 while {[gets
$fd_rc line
] >= 0} {
214 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
215 if {[is_many_config
$name]} {
216 lappend global_config
($name) $value
218 set global_config
($name) $value
226 array
unset repo_config
228 set fd_rc
[git_read config
--list]
229 while {[gets
$fd_rc line
] >= 0} {
230 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
231 if {[is_many_config
$name]} {
232 lappend repo_config
($name) $value
234 set repo_config
($name) $value
241 foreach name
[array names default_config
] {
242 if {[catch
{set v
$global_config($name)}]} {
243 set global_config
($name) $default_config($name)
245 if {[catch
{set v
$repo_config($name)}]} {
246 set repo_config
($name) $default_config($name)
251 ######################################################################
255 proc _git_cmd
{name
} {
258 if {[catch
{set v
$_git_cmd_path($name)}]} {
262 --exec-path { return [list $
::_git
$name] }
265 set p
[gitexec git-
$name$
::_search_exe
]
266 if {[file exists
$p]} {
268 } elseif
{[is_Windows
] && [file exists
[gitexec git-
$name]]} {
269 # Try to determine what sort of magic will make
270 # git-$name go and do its thing, because native
271 # Tcl on Windows doesn't know it.
273 set p
[gitexec git-
$name]
278 switch
-glob -- [lindex
$s 0] {
280 #!*perl { set i perl }
281 #!*python { set i python }
282 default
{ error
"git-$name is not supported: $s" }
286 if {![info exists interp
]} {
287 set interp
[_which
$i]
290 error
"git-$name requires $i (not in PATH)"
292 set v
[concat
[list
$interp] [lrange
$s 1 end
] [list
$p]]
294 # Assume it is builtin to git somehow and we
295 # aren't actually able to see a file for it.
297 set v
[list $
::_git
$name]
299 set _git_cmd_path
($name) $v
305 global env _search_exe _search_path
307 if {$_search_path eq
{}} {
309 set _search_path
[split [exec cygpath \
315 } elseif
{[is_Windows
]} {
316 set _search_path
[split $env(PATH
) {;}]
319 set _search_path
[split $env(PATH
) :]
324 foreach p
$_search_path {
325 set p
[file join $p $what$_search_exe]
326 if {[file exists
$p]} {
327 return [file normalize
$p]
333 proc _lappend_nice
{cmd_var
} {
337 if {![info exists _nice
]} {
338 set _nice
[_which nice
]
349 switch
-- [lindex
$args 0] {
360 set args
[lrange
$args 1 end
]
363 set cmdp
[_git_cmd
[lindex
$args 0]]
364 set args
[lrange
$args 1 end
]
366 return [eval $opt $cmdp $args]
369 proc _open_stdout_stderr
{cmd
} {
373 if { [lindex
$cmd end
] eq
{2>@
1}
374 && $err eq
{can not
find channel named
"1"}
376 # Older versions of Tcl 8.4 don't have this 2>@1 IO
377 # redirect operator. Fallback to |& cat for those.
378 # The command was not actually started, so its safe
379 # to try to start it a second time.
381 set fd
[open
[concat \
382 [lrange
$cmd 0 end-1
] \
389 fconfigure
$fd -eofchar {}
393 proc git_read
{args
} {
397 switch
-- [lindex
$args 0] {
412 set args
[lrange
$args 1 end
]
415 set cmdp
[_git_cmd
[lindex
$args 0]]
416 set args
[lrange
$args 1 end
]
418 return [_open_stdout_stderr
[concat
$opt $cmdp $args]]
421 proc git_write
{args
} {
425 switch
-- [lindex
$args 0] {
436 set args
[lrange
$args 1 end
]
439 set cmdp
[_git_cmd
[lindex
$args 0]]
440 set args
[lrange
$args 1 end
]
442 return [open
[concat
$opt $cmdp $args] w
]
446 regsub
-all ' $value "'\\''" value
450 proc load_current_branch {} {
451 global current_branch is_detached
453 set fd [open [gitdir HEAD] r]
454 if {[gets $fd ref] < 1} {
459 set pfx {ref: refs/heads/}
460 set len [string length $pfx]
461 if {[string equal -length $len $pfx $ref]} {
462 # We're on a branch. It might not exist. But
463 # HEAD looks good enough to be a branch.
465 set current_branch [string range $ref $len end]
468 # Assume this is a detached head.
470 set current_branch HEAD
475 auto_load tk_optionMenu
476 rename tk_optionMenu real__tkOptionMenu
477 proc tk_optionMenu {w varName args} {
478 set m [eval real__tkOptionMenu $w $varName $args]
479 $m configure -font font_ui
480 $w configure -font font_ui
484 proc rmsel_tag {text} {
486 -background [$text cget -background] \
487 -foreground [$text cget -foreground] \
489 $text tag conf in_sel -background lightgray
490 bind $text <Motion> break
494 ######################################################################
498 set _git [_which git]
500 catch {wm withdraw .}
501 error_popup "Cannot
find git
in PATH.
"
505 ######################################################################
509 if {[catch {set _git_version [git --version]} err]} {
510 catch {wm withdraw .}
514 -title "git-gui
: fatal error
" \
515 -message "Cannot determine Git version
:
519 [appname
] requires Git
1.5.0 or later.
"
522 if {![regsub {^git version } $_git_version {} _git_version]} {
523 catch {wm withdraw .}
527 -title "git-gui
: fatal error
" \
528 -message "Cannot parse Git version string
:\n\n$_git_version"
532 set _real_git_version $_git_version
533 regsub -- {-dirty$} $_git_version {} _git_version
534 regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version
535 regsub {\.rc[0-9]+$} $_git_version {} _git_version
536 regsub {\.GIT$} $_git_version {} _git_version
538 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
539 catch {wm withdraw .}
544 -title "[appname
]: warning
" \
545 -message "Git version cannot be determined.
547 $_git claims it is version
'$_real_git_version'.
549 [appname
] requires
at least Git
1.5.0 or later.
551 Assume
'$_real_git_version' is version
1.5.0?
553 set _git_version 1.5.0
558 unset _real_git_version
560 proc git-version {args} {
563 switch [llength $args] {
569 set op [lindex $args 0]
570 set vr [lindex $args 1]
571 set cm [package vcompare $_git_version $vr]
572 return [expr $cm $op 0]
576 set type [lindex $args 0]
577 set name [lindex $args 1]
578 set parm [lindex $args 2]
579 set body [lindex $args 3]
581 if {($type ne {proc} && $type ne {method})} {
582 error "Invalid arguments to git-version
"
584 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
585 error "Last arm of
$type $name must be default
"
588 foreach {op vr cb} [lrange $body 0 end-2] {
589 if {[git-version $op $vr]} {
590 return [uplevel [list $type $name $parm $cb]]
594 return [uplevel [list $type $name $parm [lindex $body end]]]
598 error "git-version
>= x
"
604 if {[git-version < 1.5]} {
605 catch {wm withdraw .}
609 -title "git-gui
: fatal error
" \
610 -message "[appname
] requires Git
1.5.0 or later.
612 You are using
[git-version
]:
618 ######################################################################
620 ## configure our library
622 set oguilib {@@GITGUI_LIBDIR@@}
623 set oguirel {@@GITGUI_RELATIVE@@}
624 if {$oguirel eq {1}} {
625 set oguilib [file dirname [file dirname [file normalize $argv0]]]
626 set oguilib [file join $oguilib share git-gui lib]
627 } elseif {[string match @@* $oguirel]} {
628 set oguilib [file join [file dirname [file normalize $argv0]] lib]
631 set idx [file join $oguilib tclIndex]
632 if {[catch {set fd [open $idx r]} err]} {
633 catch {wm withdraw .}
637 -title "git-gui
: fatal error
" \
641 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
643 while {[gets $fd n] >= 0} {
644 if {$n ne {} && ![string match #* $n]} {
656 if {[lsearch -exact $loaded $p] >= 0} continue
657 source [file join $oguilib $p]
662 set auto_path [concat [list $oguilib] $auto_path]
664 unset -nocomplain oguirel idx fd
666 ######################################################################
668 ## feature option selection
670 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
675 if {$subcommand eq {gui.sh}} {
678 if {$subcommand eq {gui} && [llength $argv] > 0} {
679 set subcommand [lindex $argv 0]
680 set argv [lrange $argv 1 end]
683 enable_option multicommit
685 enable_option transport
688 switch -- $subcommand {
693 disable_option multicommit
694 disable_option branch
695 disable_option transport
698 enable_option singlecommit
700 disable_option multicommit
701 disable_option branch
702 disable_option transport
706 ######################################################################
711 set _gitdir $env(GIT_DIR)
715 set _gitdir [git rev-parse --git-dir]
716 set _prefix [git rev-parse --show-prefix]
718 catch {wm withdraw .}
719 error_popup "Cannot
find the git directory
:\n\n$err"
722 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
723 catch {set _gitdir [exec cygpath --unix $_gitdir]}
725 if {![file isdirectory $_gitdir]} {
726 catch {wm withdraw .}
727 error_popup "Git directory not found
:\n\n$_gitdir"
730 if {$_prefix ne {}} {
731 regsub -all {[^/]+/} $_prefix ../ cdup
732 if {[catch {cd $cdup} err]} {
733 catch {wm withdraw .}
734 error_popup "Cannot move to top of working directory
:\n\n$err"
738 } elseif {![is_enabled bare]} {
739 if {[lindex [file split $_gitdir] end] ne {.git}} {
740 catch {wm withdraw .}
741 error_popup "Cannot use funny .git directory
:\n\n$_gitdir"
744 if {[catch {cd [file dirname $_gitdir]} err]} {
745 catch {wm withdraw .}
746 error_popup "No working directory
[file dirname $_gitdir]:\n\n$err"
750 set _reponame [file split [file normalize $_gitdir]]
751 if {[lindex $_reponame end] eq {.git}} {
752 set _reponame [lindex $_reponame end-1]
754 set _reponame [lindex $_reponame end]
757 ######################################################################
761 set current_diff_path {}
762 set current_diff_side {}
763 set diff_actions [list]
767 set MERGE_HEAD [list]
770 set current_branch {}
772 set current_diff_path {}
774 set selected_commit_type new
776 ######################################################################
784 set disable_on_lock [list]
785 set index_lock_type none
787 proc lock_index {type} {
788 global index_lock_type disable_on_lock
790 if {$index_lock_type eq {none}} {
791 set index_lock_type $type
792 foreach w $disable_on_lock {
793 uplevel #0 $w disabled
796 } elseif {$index_lock_type eq "begin-
$type"} {
797 set index_lock_type $type
803 proc unlock_index {} {
804 global index_lock_type disable_on_lock
806 set index_lock_type none
807 foreach w $disable_on_lock {
812 ######################################################################
816 proc repository_state {ctvar hdvar mhvar} {
817 global current_branch
818 upvar $ctvar ct $hdvar hd $mhvar mh
823 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
829 set merge_head [gitdir MERGE_HEAD]
830 if {[file exists $merge_head]} {
832 set fd_mh [open $merge_head r]
833 while {[gets $fd_mh line] >= 0} {
844 global PARENT empty_tree
846 set p [lindex $PARENT 0]
850 if {$empty_tree eq {}} {
851 set empty_tree [git mktree << {}]
856 proc rescan {after {honor_trustmtime 1}} {
857 global HEAD PARENT MERGE_HEAD commit_type
858 global ui_index ui_workdir ui_comm
859 global rescan_active file_states
862 if {$rescan_active > 0 || ![lock_index read]} return
864 repository_state newType newHEAD newMERGE_HEAD
865 if {[string match amend* $commit_type]
866 && $newType eq {normal}
867 && $newHEAD eq $HEAD} {
871 set MERGE_HEAD $newMERGE_HEAD
872 set commit_type $newType
875 array unset file_states
877 if {!$::GITGUI_BCK_exists &&
878 (![$ui_comm edit modified]
879 || [string trim [$ui_comm get 0.0 end]] eq {})} {
880 if {[string match amend* $commit_type]} {
881 } elseif {[load_message GITGUI_MSG]} {
882 } elseif {[load_message MERGE_MSG]} {
883 } elseif {[load_message SQUASH_MSG]} {
886 $ui_comm edit modified false
889 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
890 rescan_stage2 {} $after
893 ui_status {Refreshing file status...}
894 set fd_rf [git_read update-index \
900 fconfigure $fd_rf -blocking 0 -translation binary
901 fileevent $fd_rf readable \
902 [list rescan_stage2 $fd_rf $after]
906 proc rescan_stage2 {fd after} {
907 global rescan_active buf_rdi buf_rdf buf_rlo
911 if {![eof $fd]} return
915 set ls_others [list --exclude-per-directory=.gitignore]
916 set info_exclude [gitdir info exclude]
917 if {[file readable $info_exclude]} {
918 lappend ls_others "--exclude-from=$info_exclude"
920 set user_exclude [get_config core.excludesfile]
921 if {$user_exclude ne {} && [file readable $user_exclude]} {
922 lappend ls_others "--exclude-from=$user_exclude"
930 ui_status {Scanning for modified files ...}
931 set fd_di [git_read diff-index --cached -z [PARENT]]
932 set fd_df [git_read diff-files -z]
933 set fd_lo [eval git_read ls-files --others -z $ls_others]
935 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
936 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
937 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
938 fileevent $fd_di readable [list read_diff_index $fd_di $after]
939 fileevent $fd_df readable [list read_diff_files $fd_df $after]
940 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
943 proc load_message {file} {
947 if {[file isfile $f]} {
948 if {[catch {set fd [open $f r]}]} {
951 fconfigure $fd -eofchar {}
952 set content [string trim [read $fd]]
954 regsub -all -line {[ \r\t]+$} $content {} content
955 $ui_comm delete 0.0 end
956 $ui_comm insert end $content
962 proc read_diff_index {fd after} {
965 append buf_rdi [read $fd]
967 set n [string length $buf_rdi]
969 set z1 [string first "\
0" $buf_rdi $c]
972 set z2 [string first "\
0" $buf_rdi $z1]
976 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
977 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
979 [encoding convertfrom $p] \
981 [list [lindex $i 0] [lindex $i 2]] \
987 set buf_rdi [string range $buf_rdi $c end]
992 rescan_done $fd buf_rdi $after
995 proc read_diff_files {fd after} {
998 append buf_rdf [read $fd]
1000 set n [string length $buf_rdf]
1002 set z1 [string first "\
0" $buf_rdf $c]
1003 if {$z1 == -1} break
1005 set z2 [string first "\
0" $buf_rdf $z1]
1006 if {$z2 == -1} break
1009 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1010 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1012 [encoding convertfrom $p] \
1015 [list [lindex $i 0] [lindex $i 2]]
1020 set buf_rdf [string range $buf_rdf $c end]
1025 rescan_done $fd buf_rdf $after
1028 proc read_ls_others {fd after} {
1031 append buf_rlo [read $fd]
1032 set pck [split $buf_rlo "\
0"]
1033 set buf_rlo [lindex $pck end]
1034 foreach p [lrange $pck 0 end-1] {
1035 set p [encoding convertfrom $p]
1036 if {[string index $p end] eq {/}} {
1037 set p [string range $p 0 end-1]
1041 rescan_done $fd buf_rlo $after
1044 proc rescan_done {fd buf after} {
1045 global rescan_active current_diff_path
1046 global file_states repo_config
1049 if {![eof $fd]} return
1052 if {[incr rescan_active -1] > 0} return
1057 if {$current_diff_path ne {}} reshow_diff
1061 proc prune_selection {} {
1062 global file_states selected_paths
1064 foreach path [array names selected_paths] {
1065 if {[catch {set still_here $file_states($path)}]} {
1066 unset selected_paths($path)
1071 ######################################################################
1075 proc mapicon {w state path} {
1078 if {[catch {set r $all_icons($state$w)}]} {
1079 puts "error
: no icon
for $w state
={$state} $path"
1085 proc mapdesc {state path} {
1088 if {[catch {set r $all_descs($state)}]} {
1089 puts "error
: no desc
for state
={$state} $path"
1095 proc ui_status {msg} {
1096 $::main_status show $msg
1099 proc ui_ready {{test {}}} {
1100 $::main_status show {Ready.} $test
1103 proc escape_path {path} {
1104 regsub -all {\\} $path "\\\\" path
1105 regsub -all "\n" $path "\\n
" path
1109 proc short_path {path} {
1110 return [escape_path [lindex [file split $path] end]]
1114 set null_sha1 [string repeat 0 40]
1116 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1117 global file_states next_icon_id null_sha1
1119 set s0 [string index $new_state 0]
1120 set s1 [string index $new_state 1]
1122 if {[catch {set info $file_states($path)}]} {
1124 set icon n[incr next_icon_id]
1126 set state [lindex $info 0]
1127 set icon [lindex $info 1]
1128 if {$head_info eq {}} {set head_info [lindex $info 2]}
1129 if {$index_info eq {}} {set index_info [lindex $info 3]}
1132 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1133 elseif {$s0 eq {_}} {set s0 _}
1135 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1136 elseif {$s1 eq {_}} {set s1 _}
1138 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1139 set head_info [list 0 $null_sha1]
1140 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1141 && $head_info eq {}} {
1142 set head_info $index_info
1145 set file_states($path) [list $s0$s1 $icon \
1146 $head_info $index_info \
1151 proc display_file_helper {w path icon_name old_m new_m} {
1154 if {$new_m eq {_}} {
1155 set lno [lsearch -sorted -exact $file_lists($w) $path]
1157 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1159 $w conf -state normal
1160 $w delete $lno.0 [expr {$lno + 1}].0
1161 $w conf -state disabled
1163 } elseif {$old_m eq {_} && $new_m ne {_}} {
1164 lappend file_lists($w) $path
1165 set file_lists($w) [lsort -unique $file_lists($w)]
1166 set lno [lsearch -sorted -exact $file_lists($w) $path]
1168 $w conf -state normal
1169 $w image create $lno.0 \
1170 -align center -padx 5 -pady 1 \
1172 -image [mapicon $w $new_m $path]
1173 $w insert $lno.1 "[escape_path
$path]\n"
1174 $w conf -state disabled
1175 } elseif {$old_m ne $new_m} {
1176 $w conf -state normal
1177 $w image conf $icon_name -image [mapicon $w $new_m $path]
1178 $w conf -state disabled
1182 proc display_file {path state} {
1183 global file_states selected_paths
1184 global ui_index ui_workdir
1186 set old_m [merge_state $path $state]
1187 set s $file_states($path)
1188 set new_m [lindex $s 0]
1189 set icon_name [lindex $s 1]
1191 set o [string index $old_m 0]
1192 set n [string index $new_m 0]
1199 display_file_helper $ui_index $path $icon_name $o $n
1201 if {[string index $old_m 0] eq {U}} {
1204 set o [string index $old_m 1]
1206 if {[string index $new_m 0] eq {U}} {
1209 set n [string index $new_m 1]
1211 display_file_helper $ui_workdir $path $icon_name $o $n
1213 if {$new_m eq {__}} {
1214 unset file_states($path)
1215 catch {unset selected_paths($path)}
1219 proc display_all_files_helper {w path icon_name m} {
1222 lappend file_lists($w) $path
1223 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1224 $w image create end \
1225 -align center -padx 5 -pady 1 \
1227 -image [mapicon $w $m $path]
1228 $w insert end "[escape_path
$path]\n"
1231 proc display_all_files {} {
1232 global ui_index ui_workdir
1233 global file_states file_lists
1236 $ui_index conf -state normal
1237 $ui_workdir conf -state normal
1239 $ui_index delete 0.0 end
1240 $ui_workdir delete 0.0 end
1243 set file_lists($ui_index) [list]
1244 set file_lists($ui_workdir) [list]
1246 foreach path [lsort [array names file_states]] {
1247 set s $file_states($path)
1249 set icon_name [lindex $s 1]
1251 set s [string index $m 0]
1252 if {$s ne {U} && $s ne {_}} {
1253 display_all_files_helper $ui_index $path \
1257 if {[string index $m 0] eq {U}} {
1260 set s [string index $m 1]
1263 display_all_files_helper $ui_workdir $path \
1268 $ui_index conf -state disabled
1269 $ui_workdir conf -state disabled
1272 ######################################################################
1277 #define mask_width 14
1278 #define mask_height 15
1279 static unsigned char mask_bits[] = {
1280 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1281 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1282 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1285 image create bitmap file_plain -background white -foreground black -data {
1286 #define plain_width 14
1287 #define plain_height 15
1288 static unsigned char plain_bits[] = {
1289 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1290 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1291 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1292 } -maskdata $filemask
1294 image create bitmap file_mod -background white -foreground blue -data {
1295 #define mod_width 14
1296 #define mod_height 15
1297 static unsigned char mod_bits[] = {
1298 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1299 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1300 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1301 } -maskdata $filemask
1303 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1304 #define file_fulltick_width 14
1305 #define file_fulltick_height 15
1306 static unsigned char file_fulltick_bits
[] = {
1307 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1308 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1309 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1310 } -maskdata $filemask
1312 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
1313 #define parttick_width 14
1314 #define parttick_height 15
1315 static unsigned char parttick_bits
[] = {
1316 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1317 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
1318 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1319 } -maskdata $filemask
1321 image create bitmap file_question
-background white
-foreground black
-data {
1322 #define file_question_width 14
1323 #define file_question_height 15
1324 static unsigned char file_question_bits
[] = {
1325 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1326 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1327 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1328 } -maskdata $filemask
1330 image create bitmap file_removed
-background white
-foreground red
-data {
1331 #define file_removed_width 14
1332 #define file_removed_height 15
1333 static unsigned char file_removed_bits
[] = {
1334 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1335 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1336 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1337 } -maskdata $filemask
1339 image create bitmap file_merge
-background white
-foreground blue
-data {
1340 #define file_merge_width 14
1341 #define file_merge_height 15
1342 static unsigned char file_merge_bits
[] = {
1343 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1344 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1345 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1346 } -maskdata $filemask
1348 set ui_index .vpane.files.index.list
1349 set ui_workdir .vpane.files.workdir.list
1351 set all_icons
(_
$ui_index) file_plain
1352 set all_icons
(A
$ui_index) file_fulltick
1353 set all_icons
(M
$ui_index) file_fulltick
1354 set all_icons
(D
$ui_index) file_removed
1355 set all_icons
(U
$ui_index) file_merge
1357 set all_icons
(_
$ui_workdir) file_plain
1358 set all_icons
(M
$ui_workdir) file_mod
1359 set all_icons
(D
$ui_workdir) file_question
1360 set all_icons
(U
$ui_workdir) file_merge
1361 set all_icons
(O
$ui_workdir) file_plain
1363 set max_status_desc
0
1367 {_M
"Modified, not staged"}
1368 {M_
"Staged for commit"}
1369 {MM
"Portions staged for commit"}
1370 {MD
"Staged for commit, missing"}
1372 {_O
"Untracked, not staged"}
1373 {A_
"Staged for commit"}
1374 {AM
"Portions staged for commit"}
1375 {AD
"Staged for commit, missing"}
1378 {D_
"Staged for removal"}
1379 {DO
"Staged for removal, still present"}
1381 {U_
"Requires merge resolution"}
1382 {UU
"Requires merge resolution"}
1383 {UM
"Requires merge resolution"}
1384 {UD
"Requires merge resolution"}
1386 if {$max_status_desc < [string length
[lindex
$i 1]]} {
1387 set max_status_desc
[string length
[lindex
$i 1]]
1389 set all_descs
([lindex
$i 0]) [lindex
$i 1]
1393 ######################################################################
1397 proc bind_button3
{w cmd
} {
1398 bind $w <Any-Button-3
> $cmd
1400 # Mac OS X sends Button-2 on right click through three-button mouse,
1401 # or through trackpad right-clicking (two-finger touch + click).
1402 bind $w <Any-Button-2
> $cmd
1403 bind $w <Control-Button-1
> $cmd
1407 proc scrollbar2many
{list mode args
} {
1408 foreach w
$list {eval $w $mode $args}
1411 proc many2scrollbar
{list mode sb top bottom
} {
1412 $sb set $top $bottom
1413 foreach w
$list {$w $mode moveto
$top}
1416 proc incr_font_size
{font
{amt
1}} {
1417 set sz
[font configure
$font -size]
1419 font configure
$font -size $sz
1420 font configure
${font}bold
-size $sz
1421 font configure
${font}italic
-size $sz
1424 ######################################################################
1428 set starting_gitk_msg
{Starting gitk... please
wait...
}
1430 proc do_gitk
{revs
} {
1431 # -- Always start gitk through whatever we were loaded with. This
1432 # lets us bypass using shell process on Windows systems.
1434 set exe
[file join [file dirname $
::_git
] gitk
]
1435 set cmd
[list
[info nameofexecutable
] $exe]
1436 if {! [file exists
$exe]} {
1437 error_popup
"Unable to start gitk:\n\n$exe does not exist"
1439 eval exec $cmd $revs &
1440 ui_status $
::starting_gitk_msg
1442 ui_ready
$starting_gitk_msg
1450 global ui_comm is_quitting repo_config commit_type
1451 global GITGUI_BCK_exists GITGUI_BCK_i
1453 if {$is_quitting} return
1456 if {[winfo exists
$ui_comm]} {
1457 # -- Stash our current commit buffer.
1459 set save
[gitdir GITGUI_MSG
]
1460 if {$GITGUI_BCK_exists && ![$ui_comm edit modified
]} {
1461 file rename
-force [gitdir GITGUI_BCK
] $save
1462 set GITGUI_BCK_exists
0
1464 set msg
[string trim
[$ui_comm get
0.0 end
]]
1465 regsub
-all -line {[ \r\t]+$
} $msg {} msg
1466 if {(![string match amend
* $commit_type]
1467 ||
[$ui_comm edit modified
])
1470 set fd
[open
$save w
]
1471 puts
-nonewline $fd $msg
1475 catch
{file delete
$save}
1479 # -- Remove our editor backup, its not needed.
1481 after cancel
$GITGUI_BCK_i
1482 if {$GITGUI_BCK_exists} {
1483 catch
{file delete
[gitdir GITGUI_BCK
]}
1486 # -- Stash our current window geometry into this repository.
1488 set cfg_geometry
[list
]
1489 lappend cfg_geometry
[wm geometry .
]
1490 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
1491 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
1492 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
1495 if {$cfg_geometry ne
$rc_geometry} {
1496 catch
{git config gui.geometry
$cfg_geometry}
1511 proc toggle_or_diff
{w x y
} {
1512 global file_states file_lists current_diff_path ui_index ui_workdir
1513 global last_clicked selected_paths
1515 set pos
[split [$w index @
$x,$y] .
]
1516 set lno
[lindex
$pos 0]
1517 set col [lindex
$pos 1]
1518 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
1524 set last_clicked
[list
$w $lno]
1525 array
unset selected_paths
1526 $ui_index tag remove in_sel
0.0 end
1527 $ui_workdir tag remove in_sel
0.0 end
1530 if {$current_diff_path eq
$path} {
1531 set after
{reshow_diff
;}
1535 if {$w eq
$ui_index} {
1537 "Unstaging [short_path $path] from commit" \
1539 [concat
$after [list ui_ready
]]
1540 } elseif
{$w eq
$ui_workdir} {
1542 "Adding [short_path $path]" \
1544 [concat
$after [list ui_ready
]]
1547 show_diff
$path $w $lno
1551 proc add_one_to_selection
{w x y
} {
1552 global file_lists last_clicked selected_paths
1554 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
1555 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
1561 if {$last_clicked ne
{}
1562 && [lindex
$last_clicked 0] ne
$w} {
1563 array
unset selected_paths
1564 [lindex
$last_clicked 0] tag remove in_sel
0.0 end
1567 set last_clicked
[list
$w $lno]
1568 if {[catch
{set in_sel
$selected_paths($path)}]} {
1572 unset selected_paths
($path)
1573 $w tag remove in_sel
$lno.0 [expr {$lno + 1}].0
1575 set selected_paths
($path) 1
1576 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
1580 proc add_range_to_selection
{w x y
} {
1581 global file_lists last_clicked selected_paths
1583 if {[lindex
$last_clicked 0] ne
$w} {
1584 toggle_or_diff
$w $x $y
1588 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
1589 set lc
[lindex
$last_clicked 1]
1598 foreach path
[lrange
$file_lists($w) \
1599 [expr {$begin - 1}] \
1600 [expr {$end - 1}]] {
1601 set selected_paths
($path) 1
1603 $w tag add in_sel
$begin.0 [expr {$end + 1}].0
1606 ######################################################################
1610 set cursor_ptr arrow
1611 font create font_diff
-family Courier
-size 10
1615 eval font configure font_ui
[font actual
[.dummy cget
-font]]
1619 font create font_uiitalic
1620 font create font_uibold
1621 font create font_diffbold
1622 font create font_diffitalic
1624 foreach class
{Button Checkbutton Entry Label
1625 Labelframe Listbox Menu Message
1626 Radiobutton Spinbox Text
} {
1627 option add
*$class.font font_ui
1631 if {[is_Windows
] ||
[is_MacOSX
]} {
1632 option add
*Menu.tearOff
0
1643 proc apply_config
{} {
1644 global repo_config font_descs
1646 foreach option
$font_descs {
1647 set name
[lindex
$option 0]
1648 set font
[lindex
$option 1]
1650 foreach
{cn cv
} $repo_config(gui.
$name) {
1651 font configure
$font $cn $cv
1654 error_popup
"Invalid font specified in gui.$name:\n\n$err"
1656 foreach
{cn cv
} [font configure
$font] {
1657 font configure
${font}bold
$cn $cv
1658 font configure
${font}italic
$cn $cv
1660 font configure
${font}bold
-weight bold
1661 font configure
${font}italic
-slant italic
1665 set default_config
(merge.diffstat
) true
1666 set default_config
(merge.summary
) false
1667 set default_config
(merge.verbosity
) 2
1668 set default_config
(user.name
) {}
1669 set default_config
(user.email
) {}
1671 set default_config
(gui.matchtrackingbranch
) false
1672 set default_config
(gui.pruneduringfetch
) false
1673 set default_config
(gui.trustmtime
) false
1674 set default_config
(gui.diffcontext
) 5
1675 set default_config
(gui.newbranchtemplate
) {}
1676 set default_config
(gui.fontui
) [font configure font_ui
]
1677 set default_config
(gui.fontdiff
) [font configure font_diff
]
1679 {fontui font_ui
{Main Font
}}
1680 {fontdiff font_diff
{Diff
/Console Font
}}
1685 ######################################################################
1693 menu .mbar
-tearoff 0
1694 .mbar add cascade
-label Repository
-menu .mbar.repository
1695 .mbar add cascade
-label Edit
-menu .mbar.edit
1696 if {[is_enabled branch
]} {
1697 .mbar add cascade
-label Branch
-menu .mbar.branch
1699 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
1700 .mbar add cascade
-label Commit
-menu .mbar.commit
1702 if {[is_enabled transport
]} {
1703 .mbar add cascade
-label Merge
-menu .mbar.merge
1704 .mbar add cascade
-label Fetch
-menu .mbar.fetch
1705 .mbar add cascade
-label Push
-menu .mbar.push
1707 . configure
-menu .mbar
1709 # -- Repository Menu
1711 menu .mbar.repository
1713 .mbar.repository add
command \
1714 -label {Browse Current Branch
's Files} \
1715 -command {browser::new $current_branch}
1716 set ui_browse_current [.mbar.repository index last]
1717 .mbar.repository add command \
1718 -label {Browse Branch Files...} \
1719 -command browser_open::dialog
1720 .mbar.repository add separator
1722 .mbar.repository add command \
1723 -label {Visualize Current Branch's History
} \
1724 -command {do_gitk
$current_branch}
1725 set ui_visualize_current
[.mbar.repository index last
]
1726 .mbar.repository add
command \
1727 -label {Visualize All Branch History
} \
1728 -command {do_gitk
--all}
1729 .mbar.repository add separator
1731 proc current_branch_write
{args
} {
1732 global current_branch
1733 .mbar.repository entryconf $
::ui_browse_current \
1734 -label "Browse $current_branch's Files"
1735 .mbar.repository entryconf $
::ui_visualize_current \
1736 -label "Visualize $current_branch's History"
1738 trace add variable current_branch
write current_branch_write
1740 if {[is_enabled multicommit
]} {
1741 .mbar.repository add
command -label {Database Statistics
} \
1744 .mbar.repository add
command -label {Compress Database
} \
1747 .mbar.repository add
command -label {Verify Database
} \
1748 -command do_fsck_objects
1750 .mbar.repository add separator
1753 .mbar.repository add
command \
1754 -label {Create Desktop Icon
} \
1755 -command do_cygwin_shortcut
1756 } elseif
{[is_Windows
]} {
1757 .mbar.repository add
command \
1758 -label {Create Desktop Icon
} \
1759 -command do_windows_shortcut
1760 } elseif
{[is_MacOSX
]} {
1761 .mbar.repository add
command \
1762 -label {Create Desktop Icon
} \
1763 -command do_macosx_app
1767 .mbar.repository add
command -label Quit \
1774 .mbar.edit add
command -label Undo \
1775 -command {catch
{[focus
] edit undo
}} \
1777 .mbar.edit add
command -label Redo \
1778 -command {catch
{[focus
] edit redo
}} \
1780 .mbar.edit add separator
1781 .mbar.edit add
command -label Cut \
1782 -command {catch
{tk_textCut
[focus
]}} \
1784 .mbar.edit add
command -label Copy \
1785 -command {catch
{tk_textCopy
[focus
]}} \
1787 .mbar.edit add
command -label Paste \
1788 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
1790 .mbar.edit add
command -label Delete \
1791 -command {catch
{[focus
] delete sel.first sel.last
}} \
1793 .mbar.edit add separator
1794 .mbar.edit add
command -label {Select All
} \
1795 -command {catch
{[focus
] tag add sel
0.0 end
}} \
1800 if {[is_enabled branch
]} {
1803 .mbar.branch add
command -label {Create...
} \
1804 -command branch_create
::dialog \
1806 lappend disable_on_lock
[list .mbar.branch entryconf \
1807 [.mbar.branch index last
] -state]
1809 .mbar.branch add
command -label {Checkout...
} \
1810 -command branch_checkout
::dialog \
1812 lappend disable_on_lock
[list .mbar.branch entryconf \
1813 [.mbar.branch index last
] -state]
1815 .mbar.branch add
command -label {Rename...
} \
1816 -command branch_rename
::dialog
1817 lappend disable_on_lock
[list .mbar.branch entryconf \
1818 [.mbar.branch index last
] -state]
1820 .mbar.branch add
command -label {Delete...
} \
1821 -command branch_delete
::dialog
1822 lappend disable_on_lock
[list .mbar.branch entryconf \
1823 [.mbar.branch index last
] -state]
1825 .mbar.branch add
command -label {Reset...
} \
1826 -command merge
::reset_hard
1827 lappend disable_on_lock
[list .mbar.branch entryconf \
1828 [.mbar.branch index last
] -state]
1833 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
1836 .mbar.commit add radiobutton \
1837 -label {New Commit
} \
1838 -command do_select_commit_type \
1839 -variable selected_commit_type \
1841 lappend disable_on_lock \
1842 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1844 .mbar.commit add radiobutton \
1845 -label {Amend Last Commit
} \
1846 -command do_select_commit_type \
1847 -variable selected_commit_type \
1849 lappend disable_on_lock \
1850 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1852 .mbar.commit add separator
1854 .mbar.commit add
command -label Rescan \
1855 -command do_rescan \
1857 lappend disable_on_lock \
1858 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1860 .mbar.commit add
command -label {Stage To Commit
} \
1861 -command do_add_selection
1862 lappend disable_on_lock \
1863 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1865 .mbar.commit add
command -label {Stage Changed Files To Commit
} \
1866 -command do_add_all \
1868 lappend disable_on_lock \
1869 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1871 .mbar.commit add
command -label {Unstage From Commit
} \
1872 -command do_unstage_selection
1873 lappend disable_on_lock \
1874 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1876 .mbar.commit add
command -label {Revert Changes
} \
1877 -command do_revert_selection
1878 lappend disable_on_lock \
1879 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1881 .mbar.commit add separator
1883 .mbar.commit add
command -label {Sign Off
} \
1884 -command do_signoff \
1887 .mbar.commit add
command -label Commit \
1888 -command do_commit \
1889 -accelerator $M1T-Return
1890 lappend disable_on_lock \
1891 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1896 if {[is_enabled branch
]} {
1898 .mbar.merge add
command -label {Local Merge...
} \
1899 -command merge
::dialog \
1901 lappend disable_on_lock \
1902 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
1903 .mbar.merge add
command -label {Abort Merge...
} \
1904 -command merge
::reset_hard
1905 lappend disable_on_lock \
1906 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
1911 if {[is_enabled transport
]} {
1915 .mbar.push add
command -label {Push...
} \
1916 -command do_push_anywhere \
1918 .mbar.push add
command -label {Delete...
} \
1919 -command remote_branch_delete
::dialog
1923 # -- Apple Menu (Mac OS X only)
1925 .mbar add cascade
-label Apple
-menu .mbar.apple
1928 .mbar.apple add
command -label "About [appname]" \
1930 .mbar.apple add
command -label "Options..." \
1935 .mbar.edit add separator
1936 .mbar.edit add
command -label {Options...
} \
1942 .mbar add cascade
-label Help
-menu .mbar.
help
1946 .mbar.
help add
command -label "About [appname]" \
1951 catch
{set browser
$repo_config(instaweb.browser
)}
1952 set doc_path
[file dirname [gitexec
]]
1953 set doc_path
[file join $doc_path Documentation index.html
]
1956 set doc_path
[exec cygpath
--mixed $doc_path]
1959 if {$browser eq
{}} {
1962 } elseif
{[is_Cygwin
]} {
1963 set program_files
[file dirname [exec cygpath
--windir]]
1964 set program_files
[file join $program_files {Program Files
}]
1965 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
1966 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
1967 if {[file exists
$firefox]} {
1968 set browser
$firefox
1969 } elseif
{[file exists
$ie]} {
1972 unset program_files firefox ie
1976 if {[file isfile
$doc_path]} {
1977 set doc_url
"file:$doc_path"
1979 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
1982 if {$browser ne
{}} {
1983 .mbar.
help add
command -label {Online Documentation
} \
1984 -command [list
exec $browser $doc_url &]
1986 unset browser doc_path doc_url
1989 bind .
<Visibility
> {
1990 bind .
<Visibility
> {}
1994 # -- Standard bindings
1996 wm protocol . WM_DELETE_WINDOW do_quit
1997 bind all
<$M1B-Key-q> do_quit
1998 bind all
<$M1B-Key-Q> do_quit
1999 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
2000 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
2002 set subcommand_args
{}
2004 puts stderr
"usage: $::argv0 $::subcommand $::subcommand_args"
2008 # -- Not a normal commit type invocation? Do that instead!
2010 switch
-- $subcommand {
2013 set subcommand_args
{rev? path
}
2014 if {$argv eq
{}} usage
2019 if {$is_path ||
[file exists
$_prefix$a]} {
2020 if {$path ne
{}} usage
2023 } elseif
{$a eq
{--}} {
2025 if {$head ne
{}} usage
2030 } elseif
{$head eq
{}} {
2031 if {$head ne
{}} usage
2040 if {$head ne
{} && $path eq
{}} {
2041 set path
$_prefix$head
2048 if {[regexp
{^
[0-9a-f]{1,39}$
} $head]} {
2050 set head [git rev-parse
--verify $head]
2056 set current_branch
$head
2059 switch
-- $subcommand {
2062 if {$path ne
{} && [file isdirectory
$path]} {
2063 set head $current_branch
2069 browser
::new
$head $path
2072 if {$head eq
{} && ![file exists
$path]} {
2073 puts stderr
"fatal: cannot stat path $path: No such file or directory"
2076 blame
::new
$head $path
2083 if {[llength
$argv] != 0} {
2084 puts
-nonewline stderr
"usage: $argv0"
2085 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
2086 puts
-nonewline stderr
" $subcommand"
2091 # fall through to setup UI for commits
2094 puts stderr
"usage: $argv0 \[{blame|browser|citool}\]"
2105 -text {Current Branch
:} \
2109 -textvariable current_branch \
2112 pack .branch.l1
-side left
2113 pack .branch.cb
-side left
-fill x
2114 pack .branch
-side top
-fill x
2116 # -- Main Window Layout
2118 panedwindow .vpane
-orient vertical
2119 panedwindow .vpane.files
-orient horizontal
2120 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
2121 pack .vpane
-anchor n
-side top
-fill both
-expand 1
2123 # -- Index File List
2125 frame .vpane.files.index
-height 100 -width 200
2126 label .vpane.files.index.title
-text {Staged Changes
(Will Be Committed
)} \
2127 -background lightgreen
2128 text
$ui_index -background white
-borderwidth 0 \
2129 -width 20 -height 10 \
2131 -cursor $cursor_ptr \
2132 -xscrollcommand {.vpane.files.index.sx
set} \
2133 -yscrollcommand {.vpane.files.index.sy
set} \
2135 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
2136 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
2137 pack .vpane.files.index.title
-side top
-fill x
2138 pack .vpane.files.index.sx
-side bottom
-fill x
2139 pack .vpane.files.index.sy
-side right
-fill y
2140 pack
$ui_index -side left
-fill both
-expand 1
2141 .vpane.files add .vpane.files.index
-sticky nsew
2143 # -- Working Directory File List
2145 frame .vpane.files.workdir
-height 100 -width 200
2146 label .vpane.files.workdir.title
-text {Unstaged Changes
(Will Not Be Committed
)} \
2147 -background lightsalmon
2148 text
$ui_workdir -background white
-borderwidth 0 \
2149 -width 20 -height 10 \
2151 -cursor $cursor_ptr \
2152 -xscrollcommand {.vpane.files.workdir.sx
set} \
2153 -yscrollcommand {.vpane.files.workdir.sy
set} \
2155 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
2156 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
2157 pack .vpane.files.workdir.title
-side top
-fill x
2158 pack .vpane.files.workdir.sx
-side bottom
-fill x
2159 pack .vpane.files.workdir.sy
-side right
-fill y
2160 pack
$ui_workdir -side left
-fill both
-expand 1
2161 .vpane.files add .vpane.files.workdir
-sticky nsew
2163 foreach i
[list
$ui_index $ui_workdir] {
2165 $i tag conf in_diff
-background [$i tag cget in_sel
-background]
2169 # -- Diff and Commit Area
2171 frame .vpane.lower
-height 300 -width 400
2172 frame .vpane.lower.commarea
2173 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
2174 pack .vpane.lower.commarea
-side top
-fill x
2175 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
2176 .vpane add .vpane.lower
-sticky nsew
2178 # -- Commit Area Buttons
2180 frame .vpane.lower.commarea.buttons
2181 label .vpane.lower.commarea.buttons.l
-text {} \
2184 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
2185 pack .vpane.lower.commarea.buttons
-side left
-fill y
2187 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
2189 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
2190 lappend disable_on_lock \
2191 {.vpane.lower.commarea.buttons.rescan conf
-state}
2193 button .vpane.lower.commarea.buttons.incall
-text {Stage Changed
} \
2195 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
2196 lappend disable_on_lock \
2197 {.vpane.lower.commarea.buttons.incall conf
-state}
2199 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
2201 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
2203 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
2205 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
2206 lappend disable_on_lock \
2207 {.vpane.lower.commarea.buttons.commit conf
-state}
2209 button .vpane.lower.commarea.buttons.push
-text {Push
} \
2210 -command do_push_anywhere
2211 pack .vpane.lower.commarea.buttons.push
-side top
-fill x
2213 # -- Commit Message Buffer
2215 frame .vpane.lower.commarea.buffer
2216 frame .vpane.lower.commarea.buffer.header
2217 set ui_comm .vpane.lower.commarea.buffer.t
2218 set ui_coml .vpane.lower.commarea.buffer.header.l
2219 radiobutton .vpane.lower.commarea.buffer.header.new \
2220 -text {New Commit
} \
2221 -command do_select_commit_type \
2222 -variable selected_commit_type \
2224 lappend disable_on_lock \
2225 [list .vpane.lower.commarea.buffer.header.new conf
-state]
2226 radiobutton .vpane.lower.commarea.buffer.header.amend \
2227 -text {Amend Last Commit
} \
2228 -command do_select_commit_type \
2229 -variable selected_commit_type \
2231 lappend disable_on_lock \
2232 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
2236 proc trace_commit_type
{varname args
} {
2237 global ui_coml commit_type
2238 switch
-glob -- $commit_type {
2239 initial
{set txt
{Initial Commit Message
:}}
2240 amend
{set txt
{Amended Commit Message
:}}
2241 amend-initial
{set txt
{Amended Initial Commit Message
:}}
2242 amend-merge
{set txt
{Amended Merge Commit Message
:}}
2243 merge
{set txt
{Merge Commit Message
:}}
2244 * {set txt
{Commit Message
:}}
2246 $ui_coml conf
-text $txt
2248 trace add variable commit_type
write trace_commit_type
2249 pack
$ui_coml -side left
-fill x
2250 pack .vpane.lower.commarea.buffer.header.amend
-side right
2251 pack .vpane.lower.commarea.buffer.header.new
-side right
2253 text
$ui_comm -background white
-borderwidth 1 \
2256 -autoseparators true \
2258 -width 75 -height 9 -wrap none \
2260 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
2261 scrollbar .vpane.lower.commarea.buffer.sby \
2262 -command [list
$ui_comm yview
]
2263 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
2264 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
2265 pack
$ui_comm -side left
-fill y
2266 pack .vpane.lower.commarea.buffer
-side left
-fill y
2268 # -- Commit Message Buffer Context Menu
2270 set ctxm .vpane.lower.commarea.buffer.ctxm
2271 menu
$ctxm -tearoff 0
2274 -command {tk_textCut
$ui_comm}
2277 -command {tk_textCopy
$ui_comm}
2280 -command {tk_textPaste
$ui_comm}
2283 -command {$ui_comm delete sel.first sel.last
}
2286 -label {Select All
} \
2287 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
2291 $ui_comm tag add sel
0.0 end
2292 tk_textCopy
$ui_comm
2293 $ui_comm tag remove sel
0.0 end
2299 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
2303 proc trace_current_diff_path
{varname args
} {
2304 global current_diff_path diff_actions file_states
2305 if {$current_diff_path eq
{}} {
2311 set p
$current_diff_path
2312 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
2314 set p
[escape_path
$p]
2318 .vpane.lower.
diff.header.status configure
-text $s
2319 .vpane.lower.
diff.header.
file configure
-text $f
2320 .vpane.lower.
diff.header.path configure
-text $p
2321 foreach w
$diff_actions {
2325 trace add variable current_diff_path
write trace_current_diff_path
2327 frame .vpane.lower.
diff.header
-background gold
2328 label .vpane.lower.
diff.header.status \
2330 -width $max_status_desc \
2333 label .vpane.lower.
diff.header.
file \
2337 label .vpane.lower.
diff.header.path \
2341 pack .vpane.lower.
diff.header.status
-side left
2342 pack .vpane.lower.
diff.header.
file -side left
2343 pack .vpane.lower.
diff.header.path
-fill x
2344 set ctxm .vpane.lower.
diff.header.ctxm
2345 menu
$ctxm -tearoff 0
2353 -- $current_diff_path
2355 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2356 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
2360 frame .vpane.lower.
diff.body
2361 set ui_diff .vpane.lower.
diff.body.t
2362 text
$ui_diff -background white
-borderwidth 0 \
2363 -width 80 -height 15 -wrap none \
2365 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
2366 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
2368 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
2369 -command [list
$ui_diff xview
]
2370 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
2371 -command [list
$ui_diff yview
]
2372 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
2373 pack .vpane.lower.
diff.body.sby
-side right
-fill y
2374 pack
$ui_diff -side left
-fill both
-expand 1
2375 pack .vpane.lower.
diff.header
-side top
-fill x
2376 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
2378 $ui_diff tag conf d_cr
-elide true
2379 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
2380 $ui_diff tag conf d_
+ -foreground {#00a000}
2381 $ui_diff tag conf d_-
-foreground red
2383 $ui_diff tag conf d_
++ -foreground {#00a000}
2384 $ui_diff tag conf d_--
-foreground red
2385 $ui_diff tag conf d_
+s \
2386 -foreground {#00a000} \
2387 -background {#e2effa}
2388 $ui_diff tag conf d_-s \
2390 -background {#e2effa}
2391 $ui_diff tag conf d_s
+ \
2392 -foreground {#00a000} \
2394 $ui_diff tag conf d_s- \
2398 $ui_diff tag conf d
<<<<<<< \
2399 -foreground orange \
2401 $ui_diff tag conf d
======= \
2402 -foreground orange \
2404 $ui_diff tag conf d
>>>>>>> \
2405 -foreground orange \
2408 $ui_diff tag raise sel
2410 # -- Diff Body Context Menu
2412 set ctxm .vpane.lower.
diff.body.ctxm
2413 menu
$ctxm -tearoff 0
2416 -command reshow_diff
2417 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2420 -command {tk_textCopy
$ui_diff}
2421 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2423 -label {Select All
} \
2424 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
2425 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2429 $ui_diff tag add sel
0.0 end
2430 tk_textCopy
$ui_diff
2431 $ui_diff tag remove sel
0.0 end
2433 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2436 -label {Apply
/Reverse Hunk
} \
2437 -command {apply_hunk
$cursorX $cursorY}
2438 set ui_diff_applyhunk
[$ctxm index last
]
2439 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
2442 -label {Decrease Font Size
} \
2443 -command {incr_font_size font_diff
-1}
2444 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2446 -label {Increase Font Size
} \
2447 -command {incr_font_size font_diff
1}
2448 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2451 -label {Show Less Context
} \
2452 -command {if {$repo_config(gui.diffcontext
) >= 1} {
2453 incr repo_config
(gui.diffcontext
) -1
2456 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2458 -label {Show More Context
} \
2459 -command {if {$repo_config(gui.diffcontext
) < 99} {
2460 incr repo_config
(gui.diffcontext
)
2463 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2465 $ctxm add
command -label {Options...
} \
2467 proc popup_diff_menu
{ctxm x y X Y
} {
2468 global current_diff_path file_states
2471 if {$
::ui_index eq $
::current_diff_side
} {
2472 set l
"Unstage Hunk From Commit"
2474 set l
"Stage Hunk For Commit"
2477 ||
$current_diff_path eq
{}
2478 ||
![info exists file_states
($current_diff_path)]
2479 ||
{_O
} eq
[lindex
$file_states($current_diff_path) 0]} {
2484 $ctxm entryconf $
::ui_diff_applyhunk
-state $s -label $l
2485 tk_popup
$ctxm $X $Y
2487 bind_button3
$ui_diff [list popup_diff_menu
$ctxm %x
%y
%X
%Y
]
2491 set main_status
[::status_bar
::new .status
]
2492 pack .status
-anchor w
-side bottom
-fill x
2493 $main_status show
{Initializing...
}
2498 set gm
$repo_config(gui.geometry
)
2499 wm geometry .
[lindex
$gm 0]
2500 .vpane sash place
0 \
2501 [lindex
[.vpane sash coord
0] 0] \
2503 .vpane.files sash place
0 \
2505 [lindex
[.vpane.files sash coord
0] 1]
2511 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
2512 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
2513 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
2514 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
2515 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
2516 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
2517 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
2518 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
2519 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
2520 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2521 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2523 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
2524 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
2525 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
2526 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
2527 bind $ui_diff <$M1B-Key-v> {break}
2528 bind $ui_diff <$M1B-Key-V> {break}
2529 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2530 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2531 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
2532 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
2533 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
2534 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
2535 bind $ui_diff <Key-k
> {catch
{%W yview scroll
-1 units
};break}
2536 bind $ui_diff <Key-j
> {catch
{%W yview scroll
1 units
};break}
2537 bind $ui_diff <Key-h
> {catch
{%W xview scroll
-1 units
};break}
2538 bind $ui_diff <Key-l
> {catch
{%W xview scroll
1 units
};break}
2539 bind $ui_diff <Control-Key-b
> {catch
{%W yview scroll
-1 pages
};break}
2540 bind $ui_diff <Control-Key-f
> {catch
{%W yview scroll
1 pages
};break}
2541 bind $ui_diff <Button-1
> {focus
%W
}
2543 if {[is_enabled branch
]} {
2544 bind .
<$M1B-Key-n> branch_create
::dialog
2545 bind .
<$M1B-Key-N> branch_create
::dialog
2546 bind .
<$M1B-Key-o> branch_checkout
::dialog
2547 bind .
<$M1B-Key-O> branch_checkout
::dialog
2548 bind .
<$M1B-Key-m> merge
::dialog
2549 bind .
<$M1B-Key-M> merge
::dialog
2551 if {[is_enabled transport
]} {
2552 bind .
<$M1B-Key-p> do_push_anywhere
2553 bind .
<$M1B-Key-P> do_push_anywhere
2556 bind .
<Key-F5
> do_rescan
2557 bind .
<$M1B-Key-r> do_rescan
2558 bind .
<$M1B-Key-R> do_rescan
2559 bind .
<$M1B-Key-s> do_signoff
2560 bind .
<$M1B-Key-S> do_signoff
2561 bind .
<$M1B-Key-i> do_add_all
2562 bind .
<$M1B-Key-I> do_add_all
2563 bind .
<$M1B-Key-Return> do_commit
2564 foreach i
[list
$ui_index $ui_workdir] {
2565 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
2566 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
2567 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
2571 set file_lists
($ui_index) [list
]
2572 set file_lists
($ui_workdir) [list
]
2574 wm title .
"[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"
2575 focus
-force $ui_comm
2577 # -- Warn the user about environmental problems. Cygwin's Tcl
2578 # does *not* pass its env array onto any processes it spawns.
2579 # This means that git processes get none of our environment.
2584 set msg
"Possible environment issues exist.
2586 The following environment variables are probably
2587 going to be ignored by any Git subprocess run
2591 foreach name
[array names env
] {
2592 switch
-regexp -- $name {
2593 {^GIT_INDEX_FILE$
} -
2594 {^GIT_OBJECT_DIRECTORY$
} -
2595 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
2597 {^GIT_EXTERNAL_DIFF$
} -
2601 {^GIT_CONFIG_LOCAL$
} -
2602 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
2603 append msg
" - $name\n"
2606 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
2607 append msg
" - $name\n"
2609 set suggest_user
$name
2613 if {$ignored_env > 0} {
2615 This is due to a known issue with the
2616 Tcl binary distributed by Cygwin."
2618 if {$suggest_user ne
{}} {
2621 A good replacement for $suggest_user
2622 is placing values for the user.name and
2623 user.email settings into your personal
2629 unset ignored_env msg suggest_user name
2632 # -- Only initialize complex UI if we are going to stay running.
2634 if {[is_enabled transport
]} {
2641 if {[winfo exists
$ui_comm]} {
2642 set GITGUI_BCK_exists
[load_message GITGUI_BCK
]
2644 # -- If both our backup and message files exist use the
2645 # newer of the two files to initialize the buffer.
2647 if {$GITGUI_BCK_exists} {
2648 set m
[gitdir GITGUI_MSG
]
2649 if {[file isfile
$m]} {
2650 if {[file mtime
[gitdir GITGUI_BCK
]] > [file mtime
$m]} {
2651 catch
{file delete
[gitdir GITGUI_MSG
]}
2653 $ui_comm delete
0.0 end
2655 $ui_comm edit modified false
2656 catch
{file delete
[gitdir GITGUI_BCK
]}
2657 set GITGUI_BCK_exists
0
2663 proc backup_commit_buffer
{} {
2664 global ui_comm GITGUI_BCK_exists
2666 set m
[$ui_comm edit modified
]
2667 if {$m ||
$GITGUI_BCK_exists} {
2668 set msg
[string trim
[$ui_comm get
0.0 end
]]
2669 regsub
-all -line {[ \r\t]+$
} $msg {} msg
2672 if {$GITGUI_BCK_exists} {
2673 catch
{file delete
[gitdir GITGUI_BCK
]}
2674 set GITGUI_BCK_exists
0
2678 set fd
[open
[gitdir GITGUI_BCK
] w
]
2679 puts
-nonewline $fd $msg
2681 set GITGUI_BCK_exists
1
2685 $ui_comm edit modified false
2688 set ::GITGUI_BCK_i
[after
2000 backup_commit_buffer
]
2691 backup_commit_buffer
2694 lock_index begin-read
2695 if {![winfo ismapped .
]} {
2699 if {[is_enabled multicommit
]} {