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 ######################################################################
47 ## enable verbose loading?
49 if {![catch
{set _verbose
$env(GITGUI_VERBOSE
)}]} {
51 rename auto_load real__auto_load
52 proc auto_load
{name args
} {
53 puts stderr
"auto_load $name"
54 return [uplevel
1 real__auto_load
$name $args]
56 rename
source real__source
58 puts stderr
"source $name"
59 uplevel
1 real__source
$name
63 ######################################################################
67 set _appname
[lindex
[file split $argv0] end
]
84 return [eval [list
file join $_gitdir] $args]
89 if {$_gitexec eq
{}} {
90 if {[catch
{set _gitexec
[git
--exec-path]} err
]} {
91 error
"Git not installed?\n\n$err"
94 set _gitexec
[exec cygpath \
99 set _gitexec
[file normalize
$_gitexec]
105 return [eval [list
file join $_gitexec] $args]
113 if {[tk windowingsystem
] eq
{aqua
}} {
120 if {$
::tcl_platform
(platform
) eq
{windows
}} {
128 if {$_iscygwin eq
{}} {
129 if {$
::tcl_platform
(platform
) eq
{windows
}} {
130 if {[catch
{set p
[exec cygpath
--windir]} err
]} {
142 proc is_enabled
{option
} {
143 global enabled_options
144 if {[catch
{set on
$enabled_options($option)}]} {return 0}
148 proc enable_option
{option
} {
149 global enabled_options
150 set enabled_options
($option) 1
153 proc disable_option
{option
} {
154 global enabled_options
155 set enabled_options
($option) 0
158 ######################################################################
162 proc is_many_config
{name
} {
163 switch
-glob -- $name {
172 proc is_config_true
{name
} {
174 if {[catch
{set v
$repo_config($name)}]} {
176 } elseif
{$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes}} {
183 proc get_config
{name
} {
185 if {[catch
{set v
$repo_config($name)}]} {
192 proc load_config
{include_global
} {
193 global repo_config global_config default_config
195 array
unset global_config
196 if {$include_global} {
198 set fd_rc
[git_read config
--global --list]
199 while {[gets
$fd_rc line
] >= 0} {
200 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
201 if {[is_many_config
$name]} {
202 lappend global_config
($name) $value
204 set global_config
($name) $value
212 array
unset repo_config
214 set fd_rc
[git_read config
--list]
215 while {[gets
$fd_rc line
] >= 0} {
216 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
217 if {[is_many_config
$name]} {
218 lappend repo_config
($name) $value
220 set repo_config
($name) $value
227 foreach name
[array names default_config
] {
228 if {[catch
{set v
$global_config($name)}]} {
229 set global_config
($name) $default_config($name)
231 if {[catch
{set v
$repo_config($name)}]} {
232 set repo_config
($name) $default_config($name)
237 ######################################################################
241 proc _git_cmd
{name
} {
244 if {[catch
{set v
$_git_cmd_path($name)}]} {
248 --exec-path { return [list $
::_git
$name] }
251 set p
[gitexec git-
$name$
::_search_exe
]
252 if {[file exists
$p]} {
254 } elseif
{[is_Windows
] && [file exists
[gitexec git-
$name]]} {
255 # Try to determine what sort of magic will make
256 # git-$name go and do its thing, because native
257 # Tcl on Windows doesn't know it.
259 set p
[gitexec git-
$name]
266 #!*perl { set i perl }
267 #!*python { set i python }
268 default
{ error
"git-$name is not supported: $s" }
272 if {![info exists interp
]} {
273 set interp
[_which
$i]
276 error
"git-$name requires $i (not in PATH)"
278 set v
[list
$interp $p]
280 # Assume it is builtin to git somehow and we
281 # aren't actually able to see a file for it.
283 set v
[list $
::_git
$name]
285 set _git_cmd_path
($name) $v
291 global env _search_exe _search_path
293 if {$_search_path eq
{}} {
295 set _search_path
[split [exec cygpath \
301 } elseif
{[is_Windows
]} {
302 set _search_path
[split $env(PATH
) {;}]
305 set _search_path
[split $env(PATH
) :]
310 foreach p
$_search_path {
311 set p
[file join $p $what$_search_exe]
312 if {[file exists
$p]} {
313 return [file normalize
$p]
319 proc _lappend_nice
{cmd_var
} {
323 if {![info exists _nice
]} {
324 set _nice
[_which nice
]
335 switch
-- [lindex
$args 0] {
346 set args
[lrange
$args 1 end
]
349 set cmdp
[_git_cmd
[lindex
$args 0]]
350 set args
[lrange
$args 1 end
]
352 return [eval $opt $cmdp $args]
355 proc _open_stdout_stderr
{cmd
} {
359 if { [lindex
$cmd end
] eq
{2>@
1}
360 && $err eq
{can not
find channel named
"1"}
362 # Older versions of Tcl 8.4 don't have this 2>@1 IO
363 # redirect operator. Fallback to |& cat for those.
364 # The command was not actually started, so its safe
365 # to try to start it a second time.
367 set fd
[open
[concat \
368 [lrange
$cmd 0 end-1
] \
375 fconfigure
$fd -eofchar {}
379 proc git_read
{args
} {
383 switch
-- [lindex
$args 0] {
398 set args
[lrange
$args 1 end
]
401 set cmdp
[_git_cmd
[lindex
$args 0]]
402 set args
[lrange
$args 1 end
]
404 return [_open_stdout_stderr
[concat
$opt $cmdp $args]]
407 proc git_write
{args
} {
411 switch
-- [lindex
$args 0] {
422 set args
[lrange
$args 1 end
]
425 set cmdp
[_git_cmd
[lindex
$args 0]]
426 set args
[lrange
$args 1 end
]
428 return [open
[concat
$opt $cmdp $args] w
]
432 regsub
-all ' $value "'\\''" value
436 proc load_current_branch {} {
437 global current_branch is_detached
439 set fd [open [gitdir HEAD] r]
440 if {[gets $fd ref] < 1} {
445 set pfx {ref: refs/heads/}
446 set len [string length $pfx]
447 if {[string equal -length $len $pfx $ref]} {
448 # We're on a branch. It might not exist. But
449 # HEAD looks good enough to be a branch.
451 set current_branch [string range $ref $len end]
454 # Assume this is a detached head.
456 set current_branch HEAD
461 auto_load tk_optionMenu
462 rename tk_optionMenu real__tkOptionMenu
463 proc tk_optionMenu {w varName args} {
464 set m [eval real__tkOptionMenu $w $varName $args]
465 $m configure -font font_ui
466 $w configure -font font_ui
470 ######################################################################
474 set _git [_which git]
476 catch {wm withdraw .}
477 error_popup "Cannot
find git
in PATH.
"
481 ######################################################################
485 if {[catch {set _git_version [git --version]} err]} {
486 catch {wm withdraw .}
490 -title "git-gui
: fatal error
" \
491 -message "Cannot determine Git version
:
495 [appname
] requires Git
1.5.0 or later.
"
498 if {![regsub {^git version } $_git_version {} _git_version]} {
499 catch {wm withdraw .}
503 -title "git-gui
: fatal error
" \
504 -message "Cannot parse Git version string
:\n\n$_git_version"
508 set _real_git_version $_git_version
509 regsub -- {-dirty$} $_git_version {} _git_version
510 regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version
511 regsub {\.rc[0-9]+$} $_git_version {} _git_version
512 regsub {\.GIT$} $_git_version {} _git_version
514 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
515 catch {wm withdraw .}
520 -title "[appname
]: warning
" \
521 -message "Git version cannot be determined.
523 $_git claims it is version
'$_real_git_version'.
525 [appname
] requires
at least Git
1.5.0 or later.
527 Assume
'$_real_git_version' is version
1.5.0?
529 set _git_version 1.5.0
534 unset _real_git_version
536 proc git-version {args} {
539 switch [llength $args] {
545 set op [lindex $args 0]
546 set vr [lindex $args 1]
547 set cm [package vcompare $_git_version $vr]
548 return [expr $cm $op 0]
552 set type [lindex $args 0]
553 set name [lindex $args 1]
554 set parm [lindex $args 2]
555 set body [lindex $args 3]
557 if {($type ne {proc} && $type ne {method})} {
558 error "Invalid arguments to git-version
"
560 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
561 error "Last arm of
$type $name must be default
"
564 foreach {op vr cb} [lrange $body 0 end-2] {
565 if {[git-version $op $vr]} {
566 return [uplevel [list $type $name $parm $cb]]
570 return [uplevel [list $type $name $parm [lindex $body end]]]
574 error "git-version
>= x
"
580 if {[git-version < 1.5]} {
581 catch {wm withdraw .}
585 -title "git-gui
: fatal error
" \
586 -message "[appname
] requires Git
1.5.0 or later.
588 You are using
[git-version
]:
594 ######################################################################
596 ## configure our library
598 set oguilib {@@GITGUI_LIBDIR@@}
599 set oguirel {@@GITGUI_RELATIVE@@}
600 if {$oguirel eq {1}} {
601 set oguilib [file dirname [file dirname [file normalize $argv0]]]
602 set oguilib [file join $oguilib share git-gui lib]
603 } elseif {[string match @@* $oguirel]} {
604 set oguilib [file join [file dirname [file normalize $argv0]] lib]
607 set idx [file join $oguilib tclIndex]
608 if {[catch {set fd [open $idx r]} err]} {
609 catch {wm withdraw .}
613 -title "git-gui
: fatal error
" \
617 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
619 while {[gets $fd n] >= 0} {
620 if {$n ne {} && ![string match #* $n]} {
632 if {[lsearch -exact $loaded $p] >= 0} continue
633 source [file join $oguilib $p]
638 set auto_path [concat [list $oguilib] $auto_path]
640 unset -nocomplain oguirel idx fd
642 ######################################################################
644 ## feature option selection
646 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
651 if {$subcommand eq {gui.sh}} {
654 if {$subcommand eq {gui} && [llength $argv] > 0} {
655 set subcommand [lindex $argv 0]
656 set argv [lrange $argv 1 end]
659 enable_option multicommit
661 enable_option transport
664 switch -- $subcommand {
669 disable_option multicommit
670 disable_option branch
671 disable_option transport
674 enable_option singlecommit
676 disable_option multicommit
677 disable_option branch
678 disable_option transport
682 ######################################################################
687 set _gitdir $env(GIT_DIR)
691 set _gitdir [git rev-parse --git-dir]
692 set _prefix [git rev-parse --show-prefix]
694 catch {wm withdraw .}
695 error_popup "Cannot
find the git directory
:\n\n$err"
698 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
699 catch {set _gitdir [exec cygpath --unix $_gitdir]}
701 if {![file isdirectory $_gitdir]} {
702 catch {wm withdraw .}
703 error_popup "Git directory not found
:\n\n$_gitdir"
706 if {![is_enabled bare]} {
707 if {[lindex [file split $_gitdir] end] ne {.git}} {
708 catch {wm withdraw .}
709 error_popup "Cannot use funny .git directory
:\n\n$_gitdir"
712 if {[catch {cd [file dirname $_gitdir]} err]} {
713 catch {wm withdraw .}
714 error_popup "No working directory
[file dirname $_gitdir]:\n\n$err"
718 set _reponame [file split [file normalize $_gitdir]]
719 if {[lindex $_reponame end] eq {.git}} {
720 set _reponame [lindex $_reponame end-1]
722 set _reponame [lindex $_reponame end]
725 ######################################################################
729 set current_diff_path {}
730 set current_diff_side {}
731 set diff_actions [list]
735 set MERGE_HEAD [list]
738 set current_branch {}
740 set current_diff_path {}
741 set selected_commit_type new
743 ######################################################################
751 set disable_on_lock [list]
752 set index_lock_type none
754 proc lock_index {type} {
755 global index_lock_type disable_on_lock
757 if {$index_lock_type eq {none}} {
758 set index_lock_type $type
759 foreach w $disable_on_lock {
760 uplevel #0 $w disabled
763 } elseif {$index_lock_type eq "begin-
$type"} {
764 set index_lock_type $type
770 proc unlock_index {} {
771 global index_lock_type disable_on_lock
773 set index_lock_type none
774 foreach w $disable_on_lock {
779 ######################################################################
783 proc repository_state {ctvar hdvar mhvar} {
784 global current_branch
785 upvar $ctvar ct $hdvar hd $mhvar mh
790 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
796 set merge_head [gitdir MERGE_HEAD]
797 if {[file exists $merge_head]} {
799 set fd_mh [open $merge_head r]
800 while {[gets $fd_mh line] >= 0} {
811 global PARENT empty_tree
813 set p [lindex $PARENT 0]
817 if {$empty_tree eq {}} {
818 set empty_tree [git mktree << {}]
823 proc rescan {after {honor_trustmtime 1}} {
824 global HEAD PARENT MERGE_HEAD commit_type
825 global ui_index ui_workdir ui_comm
826 global rescan_active file_states
829 if {$rescan_active > 0 || ![lock_index read]} return
831 repository_state newType newHEAD newMERGE_HEAD
832 if {[string match amend* $commit_type]
833 && $newType eq {normal}
834 && $newHEAD eq $HEAD} {
838 set MERGE_HEAD $newMERGE_HEAD
839 set commit_type $newType
842 array unset file_states
844 if {!$::GITGUI_BCK_exists &&
845 (![$ui_comm edit modified]
846 || [string trim [$ui_comm get 0.0 end]] eq {})} {
847 if {[string match amend* $commit_type]} {
848 } elseif {[load_message GITGUI_MSG]} {
849 } elseif {[load_message MERGE_MSG]} {
850 } elseif {[load_message SQUASH_MSG]} {
853 $ui_comm edit modified false
856 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
857 rescan_stage2 {} $after
860 ui_status {Refreshing file status...}
861 set fd_rf [git_read update-index \
867 fconfigure $fd_rf -blocking 0 -translation binary
868 fileevent $fd_rf readable \
869 [list rescan_stage2 $fd_rf $after]
873 proc rescan_stage2 {fd after} {
874 global rescan_active buf_rdi buf_rdf buf_rlo
878 if {![eof $fd]} return
882 set ls_others [list --exclude-per-directory=.gitignore]
883 set info_exclude [gitdir info exclude]
884 if {[file readable $info_exclude]} {
885 lappend ls_others "--exclude-from=$info_exclude"
887 set user_exclude [get_config core.excludesfile]
888 if {$user_exclude ne {} && [file readable $user_exclude]} {
889 lappend ls_others "--exclude-from=$user_exclude"
897 ui_status {Scanning for modified files ...}
898 set fd_di [git_read diff-index --cached -z [PARENT]]
899 set fd_df [git_read diff-files -z]
900 set fd_lo [eval git_read ls-files --others -z $ls_others]
902 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
903 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
904 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
905 fileevent $fd_di readable [list read_diff_index $fd_di $after]
906 fileevent $fd_df readable [list read_diff_files $fd_df $after]
907 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
910 proc load_message {file} {
914 if {[file isfile $f]} {
915 if {[catch {set fd [open $f r]}]} {
918 fconfigure $fd -eofchar {}
919 set content [string trim [read $fd]]
921 regsub -all -line {[ \r\t]+$} $content {} content
922 $ui_comm delete 0.0 end
923 $ui_comm insert end $content
929 proc read_diff_index {fd after} {
932 append buf_rdi [read $fd]
934 set n [string length $buf_rdi]
936 set z1 [string first "\
0" $buf_rdi $c]
939 set z2 [string first "\
0" $buf_rdi $z1]
943 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
944 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
946 [encoding convertfrom $p] \
948 [list [lindex $i 0] [lindex $i 2]] \
954 set buf_rdi [string range $buf_rdi $c end]
959 rescan_done $fd buf_rdi $after
962 proc read_diff_files {fd after} {
965 append buf_rdf [read $fd]
967 set n [string length $buf_rdf]
969 set z1 [string first "\
0" $buf_rdf $c]
972 set z2 [string first "\
0" $buf_rdf $z1]
976 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
977 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
979 [encoding convertfrom $p] \
982 [list [lindex $i 0] [lindex $i 2]]
987 set buf_rdf [string range $buf_rdf $c end]
992 rescan_done $fd buf_rdf $after
995 proc read_ls_others {fd after} {
998 append buf_rlo [read $fd]
999 set pck [split $buf_rlo "\
0"]
1000 set buf_rlo [lindex $pck end]
1001 foreach p [lrange $pck 0 end-1] {
1002 merge_state [encoding convertfrom $p] ?O
1004 rescan_done $fd buf_rlo $after
1007 proc rescan_done {fd buf after} {
1008 global rescan_active current_diff_path
1009 global file_states repo_config
1012 if {![eof $fd]} return
1015 if {[incr rescan_active -1] > 0} return
1020 if {$current_diff_path ne {}} reshow_diff
1024 proc prune_selection {} {
1025 global file_states selected_paths
1027 foreach path [array names selected_paths] {
1028 if {[catch {set still_here $file_states($path)}]} {
1029 unset selected_paths($path)
1034 ######################################################################
1038 proc mapicon {w state path} {
1041 if {[catch {set r $all_icons($state$w)}]} {
1042 puts "error
: no icon
for $w state
={$state} $path"
1048 proc mapdesc {state path} {
1051 if {[catch {set r $all_descs($state)}]} {
1052 puts "error
: no desc
for state
={$state} $path"
1058 proc ui_status {msg} {
1059 $::main_status show $msg
1062 proc ui_ready {{test {}}} {
1063 $::main_status show {Ready.} $test
1066 proc escape_path {path} {
1067 regsub -all {\\} $path "\\\\" path
1068 regsub -all "\n" $path "\\n
" path
1072 proc short_path {path} {
1073 return [escape_path [lindex [file split $path] end]]
1077 set null_sha1 [string repeat 0 40]
1079 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1080 global file_states next_icon_id null_sha1
1082 set s0 [string index $new_state 0]
1083 set s1 [string index $new_state 1]
1085 if {[catch {set info $file_states($path)}]} {
1087 set icon n[incr next_icon_id]
1089 set state [lindex $info 0]
1090 set icon [lindex $info 1]
1091 if {$head_info eq {}} {set head_info [lindex $info 2]}
1092 if {$index_info eq {}} {set index_info [lindex $info 3]}
1095 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1096 elseif {$s0 eq {_}} {set s0 _}
1098 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1099 elseif {$s1 eq {_}} {set s1 _}
1101 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1102 set head_info [list 0 $null_sha1]
1103 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1104 && $head_info eq {}} {
1105 set head_info $index_info
1108 set file_states($path) [list $s0$s1 $icon \
1109 $head_info $index_info \
1114 proc display_file_helper {w path icon_name old_m new_m} {
1117 if {$new_m eq {_}} {
1118 set lno [lsearch -sorted -exact $file_lists($w) $path]
1120 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1122 $w conf -state normal
1123 $w delete $lno.0 [expr {$lno + 1}].0
1124 $w conf -state disabled
1126 } elseif {$old_m eq {_} && $new_m ne {_}} {
1127 lappend file_lists($w) $path
1128 set file_lists($w) [lsort -unique $file_lists($w)]
1129 set lno [lsearch -sorted -exact $file_lists($w) $path]
1131 $w conf -state normal
1132 $w image create $lno.0 \
1133 -align center -padx 5 -pady 1 \
1135 -image [mapicon $w $new_m $path]
1136 $w insert $lno.1 "[escape_path
$path]\n"
1137 $w conf -state disabled
1138 } elseif {$old_m ne $new_m} {
1139 $w conf -state normal
1140 $w image conf $icon_name -image [mapicon $w $new_m $path]
1141 $w conf -state disabled
1145 proc display_file {path state} {
1146 global file_states selected_paths
1147 global ui_index ui_workdir
1149 set old_m [merge_state $path $state]
1150 set s $file_states($path)
1151 set new_m [lindex $s 0]
1152 set icon_name [lindex $s 1]
1154 set o [string index $old_m 0]
1155 set n [string index $new_m 0]
1162 display_file_helper $ui_index $path $icon_name $o $n
1164 if {[string index $old_m 0] eq {U}} {
1167 set o [string index $old_m 1]
1169 if {[string index $new_m 0] eq {U}} {
1172 set n [string index $new_m 1]
1174 display_file_helper $ui_workdir $path $icon_name $o $n
1176 if {$new_m eq {__}} {
1177 unset file_states($path)
1178 catch {unset selected_paths($path)}
1182 proc display_all_files_helper {w path icon_name m} {
1185 lappend file_lists($w) $path
1186 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1187 $w image create end \
1188 -align center -padx 5 -pady 1 \
1190 -image [mapicon $w $m $path]
1191 $w insert end "[escape_path
$path]\n"
1194 proc display_all_files {} {
1195 global ui_index ui_workdir
1196 global file_states file_lists
1199 $ui_index conf -state normal
1200 $ui_workdir conf -state normal
1202 $ui_index delete 0.0 end
1203 $ui_workdir delete 0.0 end
1206 set file_lists($ui_index) [list]
1207 set file_lists($ui_workdir) [list]
1209 foreach path [lsort [array names file_states]] {
1210 set s $file_states($path)
1212 set icon_name [lindex $s 1]
1214 set s [string index $m 0]
1215 if {$s ne {U} && $s ne {_}} {
1216 display_all_files_helper $ui_index $path \
1220 if {[string index $m 0] eq {U}} {
1223 set s [string index $m 1]
1226 display_all_files_helper $ui_workdir $path \
1231 $ui_index conf -state disabled
1232 $ui_workdir conf -state disabled
1235 ######################################################################
1240 #define mask_width 14
1241 #define mask_height 15
1242 static unsigned char mask_bits[] = {
1243 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1244 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1245 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1248 image create bitmap file_plain -background white -foreground black -data {
1249 #define plain_width 14
1250 #define plain_height 15
1251 static unsigned char plain_bits[] = {
1252 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1253 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1254 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1255 } -maskdata $filemask
1257 image create bitmap file_mod -background white -foreground blue -data {
1258 #define mod_width 14
1259 #define mod_height 15
1260 static unsigned char mod_bits[] = {
1261 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1262 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1263 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1264 } -maskdata $filemask
1266 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1267 #define file_fulltick_width 14
1268 #define file_fulltick_height 15
1269 static unsigned char file_fulltick_bits
[] = {
1270 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1271 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1272 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1273 } -maskdata $filemask
1275 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
1276 #define parttick_width 14
1277 #define parttick_height 15
1278 static unsigned char parttick_bits
[] = {
1279 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1280 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
1281 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1282 } -maskdata $filemask
1284 image create bitmap file_question
-background white
-foreground black
-data {
1285 #define file_question_width 14
1286 #define file_question_height 15
1287 static unsigned char file_question_bits
[] = {
1288 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1289 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1290 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1291 } -maskdata $filemask
1293 image create bitmap file_removed
-background white
-foreground red
-data {
1294 #define file_removed_width 14
1295 #define file_removed_height 15
1296 static unsigned char file_removed_bits
[] = {
1297 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1298 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1299 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1300 } -maskdata $filemask
1302 image create bitmap file_merge
-background white
-foreground blue
-data {
1303 #define file_merge_width 14
1304 #define file_merge_height 15
1305 static unsigned char file_merge_bits
[] = {
1306 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1307 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1308 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1309 } -maskdata $filemask
1311 set ui_index .vpane.files.index.list
1312 set ui_workdir .vpane.files.workdir.list
1314 set all_icons
(_
$ui_index) file_plain
1315 set all_icons
(A
$ui_index) file_fulltick
1316 set all_icons
(M
$ui_index) file_fulltick
1317 set all_icons
(D
$ui_index) file_removed
1318 set all_icons
(U
$ui_index) file_merge
1320 set all_icons
(_
$ui_workdir) file_plain
1321 set all_icons
(M
$ui_workdir) file_mod
1322 set all_icons
(D
$ui_workdir) file_question
1323 set all_icons
(U
$ui_workdir) file_merge
1324 set all_icons
(O
$ui_workdir) file_plain
1326 set max_status_desc
0
1330 {_M
"Modified, not staged"}
1331 {M_
"Staged for commit"}
1332 {MM
"Portions staged for commit"}
1333 {MD
"Staged for commit, missing"}
1335 {_O
"Untracked, not staged"}
1336 {A_
"Staged for commit"}
1337 {AM
"Portions staged for commit"}
1338 {AD
"Staged for commit, missing"}
1341 {D_
"Staged for removal"}
1342 {DO
"Staged for removal, still present"}
1344 {U_
"Requires merge resolution"}
1345 {UU
"Requires merge resolution"}
1346 {UM
"Requires merge resolution"}
1347 {UD
"Requires merge resolution"}
1349 if {$max_status_desc < [string length
[lindex
$i 1]]} {
1350 set max_status_desc
[string length
[lindex
$i 1]]
1352 set all_descs
([lindex
$i 0]) [lindex
$i 1]
1356 ######################################################################
1360 proc bind_button3
{w cmd
} {
1361 bind $w <Any-Button-3
> $cmd
1363 # Mac OS X sends Button-2 on right click through three-button mouse,
1364 # or through trackpad right-clicking (two-finger touch + click).
1365 bind $w <Any-Button-2
> $cmd
1366 bind $w <Control-Button-1
> $cmd
1370 proc scrollbar2many
{list mode args
} {
1371 foreach w
$list {eval $w $mode $args}
1374 proc many2scrollbar
{list mode sb top bottom
} {
1375 $sb set $top $bottom
1376 foreach w
$list {$w $mode moveto
$top}
1379 proc incr_font_size
{font
{amt
1}} {
1380 set sz
[font configure
$font -size]
1382 font configure
$font -size $sz
1383 font configure
${font}bold
-size $sz
1384 font configure
${font}italic
-size $sz
1387 ######################################################################
1391 set starting_gitk_msg
{Starting gitk... please
wait...
}
1393 proc do_gitk
{revs
} {
1394 # -- Always start gitk through whatever we were loaded with. This
1395 # lets us bypass using shell process on Windows systems.
1397 set exe
[file join [file dirname $
::_git
] gitk
]
1398 set cmd
[list
[info nameofexecutable
] $exe]
1399 if {! [file exists
$exe]} {
1400 error_popup
"Unable to start gitk:\n\n$exe does not exist"
1402 eval exec $cmd $revs &
1403 ui_status $
::starting_gitk_msg
1405 ui_ready
$starting_gitk_msg
1413 global ui_comm is_quitting repo_config commit_type
1414 global GITGUI_BCK_exists GITGUI_BCK_i
1416 if {$is_quitting} return
1419 if {[winfo exists
$ui_comm]} {
1420 # -- Stash our current commit buffer.
1422 set save
[gitdir GITGUI_MSG
]
1423 if {$GITGUI_BCK_exists && ![$ui_comm edit modified
]} {
1424 file rename
-force [gitdir GITGUI_BCK
] $save
1425 set GITGUI_BCK_exists
0
1427 set msg
[string trim
[$ui_comm get
0.0 end
]]
1428 regsub
-all -line {[ \r\t]+$
} $msg {} msg
1429 if {(![string match amend
* $commit_type]
1430 ||
[$ui_comm edit modified
])
1433 set fd
[open
$save w
]
1434 puts
-nonewline $fd $msg
1438 catch
{file delete
$save}
1442 # -- Remove our editor backup, its not needed.
1444 after cancel
$GITGUI_BCK_i
1445 if {$GITGUI_BCK_exists} {
1446 catch
{file delete
[gitdir GITGUI_BCK
]}
1449 # -- Stash our current window geometry into this repository.
1451 set cfg_geometry
[list
]
1452 lappend cfg_geometry
[wm geometry .
]
1453 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
1454 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
1455 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
1458 if {$cfg_geometry ne
$rc_geometry} {
1459 catch
{git config gui.geometry
$cfg_geometry}
1474 proc toggle_or_diff
{w x y
} {
1475 global file_states file_lists current_diff_path ui_index ui_workdir
1476 global last_clicked selected_paths
1478 set pos
[split [$w index @
$x,$y] .
]
1479 set lno
[lindex
$pos 0]
1480 set col [lindex
$pos 1]
1481 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
1487 set last_clicked
[list
$w $lno]
1488 array
unset selected_paths
1489 $ui_index tag remove in_sel
0.0 end
1490 $ui_workdir tag remove in_sel
0.0 end
1493 if {$current_diff_path eq
$path} {
1494 set after
{reshow_diff
;}
1498 if {$w eq
$ui_index} {
1500 "Unstaging [short_path $path] from commit" \
1502 [concat
$after [list ui_ready
]]
1503 } elseif
{$w eq
$ui_workdir} {
1505 "Adding [short_path $path]" \
1507 [concat
$after [list ui_ready
]]
1510 show_diff
$path $w $lno
1514 proc add_one_to_selection
{w x y
} {
1515 global file_lists last_clicked selected_paths
1517 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
1518 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
1524 if {$last_clicked ne
{}
1525 && [lindex
$last_clicked 0] ne
$w} {
1526 array
unset selected_paths
1527 [lindex
$last_clicked 0] tag remove in_sel
0.0 end
1530 set last_clicked
[list
$w $lno]
1531 if {[catch
{set in_sel
$selected_paths($path)}]} {
1535 unset selected_paths
($path)
1536 $w tag remove in_sel
$lno.0 [expr {$lno + 1}].0
1538 set selected_paths
($path) 1
1539 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
1543 proc add_range_to_selection
{w x y
} {
1544 global file_lists last_clicked selected_paths
1546 if {[lindex
$last_clicked 0] ne
$w} {
1547 toggle_or_diff
$w $x $y
1551 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
1552 set lc
[lindex
$last_clicked 1]
1561 foreach path
[lrange
$file_lists($w) \
1562 [expr {$begin - 1}] \
1563 [expr {$end - 1}]] {
1564 set selected_paths
($path) 1
1566 $w tag add in_sel
$begin.0 [expr {$end + 1}].0
1569 ######################################################################
1573 set cursor_ptr arrow
1574 font create font_diff
-family Courier
-size 10
1578 eval font configure font_ui
[font actual
[.dummy cget
-font]]
1582 font create font_uiitalic
1583 font create font_uibold
1584 font create font_diffbold
1585 font create font_diffitalic
1587 foreach class
{Button Checkbutton Entry Label
1588 Labelframe Listbox Menu Message
1589 Radiobutton Spinbox Text
} {
1590 option add
*$class.font font_ui
1594 if {[is_Windows
] ||
[is_MacOSX
]} {
1595 option add
*Menu.tearOff
0
1606 proc apply_config
{} {
1607 global repo_config font_descs
1609 foreach option
$font_descs {
1610 set name
[lindex
$option 0]
1611 set font
[lindex
$option 1]
1613 foreach
{cn cv
} $repo_config(gui.
$name) {
1614 font configure
$font $cn $cv
1617 error_popup
"Invalid font specified in gui.$name:\n\n$err"
1619 foreach
{cn cv
} [font configure
$font] {
1620 font configure
${font}bold
$cn $cv
1621 font configure
${font}italic
$cn $cv
1623 font configure
${font}bold
-weight bold
1624 font configure
${font}italic
-slant italic
1628 set default_config
(merge.diffstat
) true
1629 set default_config
(merge.summary
) false
1630 set default_config
(merge.verbosity
) 2
1631 set default_config
(user.name
) {}
1632 set default_config
(user.email
) {}
1634 set default_config
(gui.matchtrackingbranch
) false
1635 set default_config
(gui.pruneduringfetch
) false
1636 set default_config
(gui.trustmtime
) false
1637 set default_config
(gui.diffcontext
) 5
1638 set default_config
(gui.newbranchtemplate
) {}
1639 set default_config
(gui.fontui
) [font configure font_ui
]
1640 set default_config
(gui.fontdiff
) [font configure font_diff
]
1642 {fontui font_ui
{Main Font
}}
1643 {fontdiff font_diff
{Diff
/Console Font
}}
1648 ######################################################################
1656 menu .mbar
-tearoff 0
1657 .mbar add cascade
-label Repository
-menu .mbar.repository
1658 .mbar add cascade
-label Edit
-menu .mbar.edit
1659 if {[is_enabled branch
]} {
1660 .mbar add cascade
-label Branch
-menu .mbar.branch
1662 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
1663 .mbar add cascade
-label Commit
-menu .mbar.commit
1665 if {[is_enabled transport
]} {
1666 .mbar add cascade
-label Merge
-menu .mbar.merge
1667 .mbar add cascade
-label Fetch
-menu .mbar.fetch
1668 .mbar add cascade
-label Push
-menu .mbar.push
1670 . configure
-menu .mbar
1672 # -- Repository Menu
1674 menu .mbar.repository
1676 .mbar.repository add
command \
1677 -label {Browse Current Branch
's Files} \
1678 -command {browser::new $current_branch}
1679 set ui_browse_current [.mbar.repository index last]
1680 .mbar.repository add command \
1681 -label {Browse Branch Files...} \
1682 -command browser_open::dialog
1683 .mbar.repository add separator
1685 .mbar.repository add command \
1686 -label {Visualize Current Branch's History
} \
1687 -command {do_gitk
$current_branch}
1688 set ui_visualize_current
[.mbar.repository index last
]
1689 .mbar.repository add
command \
1690 -label {Visualize All Branch History
} \
1691 -command {do_gitk
--all}
1692 .mbar.repository add separator
1694 proc current_branch_write
{args
} {
1695 global current_branch
1696 .mbar.repository entryconf $
::ui_browse_current \
1697 -label "Browse $current_branch's Files"
1698 .mbar.repository entryconf $
::ui_visualize_current \
1699 -label "Visualize $current_branch's History"
1701 trace add variable current_branch
write current_branch_write
1703 if {[is_enabled multicommit
]} {
1704 .mbar.repository add
command -label {Database Statistics
} \
1707 .mbar.repository add
command -label {Compress Database
} \
1710 .mbar.repository add
command -label {Verify Database
} \
1711 -command do_fsck_objects
1713 .mbar.repository add separator
1716 .mbar.repository add
command \
1717 -label {Create Desktop Icon
} \
1718 -command do_cygwin_shortcut
1719 } elseif
{[is_Windows
]} {
1720 .mbar.repository add
command \
1721 -label {Create Desktop Icon
} \
1722 -command do_windows_shortcut
1723 } elseif
{[is_MacOSX
]} {
1724 .mbar.repository add
command \
1725 -label {Create Desktop Icon
} \
1726 -command do_macosx_app
1730 .mbar.repository add
command -label Quit \
1737 .mbar.edit add
command -label Undo \
1738 -command {catch
{[focus
] edit undo
}} \
1740 .mbar.edit add
command -label Redo \
1741 -command {catch
{[focus
] edit redo
}} \
1743 .mbar.edit add separator
1744 .mbar.edit add
command -label Cut \
1745 -command {catch
{tk_textCut
[focus
]}} \
1747 .mbar.edit add
command -label Copy \
1748 -command {catch
{tk_textCopy
[focus
]}} \
1750 .mbar.edit add
command -label Paste \
1751 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
1753 .mbar.edit add
command -label Delete \
1754 -command {catch
{[focus
] delete sel.first sel.last
}} \
1756 .mbar.edit add separator
1757 .mbar.edit add
command -label {Select All
} \
1758 -command {catch
{[focus
] tag add sel
0.0 end
}} \
1763 if {[is_enabled branch
]} {
1766 .mbar.branch add
command -label {Create...
} \
1767 -command branch_create
::dialog \
1769 lappend disable_on_lock
[list .mbar.branch entryconf \
1770 [.mbar.branch index last
] -state]
1772 .mbar.branch add
command -label {Checkout...
} \
1773 -command branch_checkout
::dialog \
1775 lappend disable_on_lock
[list .mbar.branch entryconf \
1776 [.mbar.branch index last
] -state]
1778 .mbar.branch add
command -label {Rename...
} \
1779 -command branch_rename
::dialog
1780 lappend disable_on_lock
[list .mbar.branch entryconf \
1781 [.mbar.branch index last
] -state]
1783 .mbar.branch add
command -label {Delete...
} \
1784 -command branch_delete
::dialog
1785 lappend disable_on_lock
[list .mbar.branch entryconf \
1786 [.mbar.branch index last
] -state]
1788 .mbar.branch add
command -label {Reset...
} \
1789 -command merge
::reset_hard
1790 lappend disable_on_lock
[list .mbar.branch entryconf \
1791 [.mbar.branch index last
] -state]
1796 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
1799 .mbar.commit add radiobutton \
1800 -label {New Commit
} \
1801 -command do_select_commit_type \
1802 -variable selected_commit_type \
1804 lappend disable_on_lock \
1805 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1807 .mbar.commit add radiobutton \
1808 -label {Amend Last Commit
} \
1809 -command do_select_commit_type \
1810 -variable selected_commit_type \
1812 lappend disable_on_lock \
1813 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1815 .mbar.commit add separator
1817 .mbar.commit add
command -label Rescan \
1818 -command do_rescan \
1820 lappend disable_on_lock \
1821 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1823 .mbar.commit add
command -label {Stage To Commit
} \
1824 -command do_add_selection
1825 lappend disable_on_lock \
1826 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1828 .mbar.commit add
command -label {Stage Changed Files To Commit
} \
1829 -command do_add_all \
1831 lappend disable_on_lock \
1832 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1834 .mbar.commit add
command -label {Unstage From Commit
} \
1835 -command do_unstage_selection
1836 lappend disable_on_lock \
1837 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1839 .mbar.commit add
command -label {Revert Changes
} \
1840 -command do_revert_selection
1841 lappend disable_on_lock \
1842 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1844 .mbar.commit add separator
1846 .mbar.commit add
command -label {Sign Off
} \
1847 -command do_signoff \
1850 .mbar.commit add
command -label Commit \
1851 -command do_commit \
1852 -accelerator $M1T-Return
1853 lappend disable_on_lock \
1854 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1859 if {[is_enabled branch
]} {
1861 .mbar.merge add
command -label {Local Merge...
} \
1862 -command merge
::dialog \
1864 lappend disable_on_lock \
1865 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
1866 .mbar.merge add
command -label {Abort Merge...
} \
1867 -command merge
::reset_hard
1868 lappend disable_on_lock \
1869 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
1874 if {[is_enabled transport
]} {
1878 .mbar.push add
command -label {Push...
} \
1879 -command do_push_anywhere \
1881 .mbar.push add
command -label {Delete...
} \
1882 -command remote_branch_delete
::dialog
1886 # -- Apple Menu (Mac OS X only)
1888 .mbar add cascade
-label Apple
-menu .mbar.apple
1891 .mbar.apple add
command -label "About [appname]" \
1893 .mbar.apple add
command -label "Options..." \
1898 .mbar.edit add separator
1899 .mbar.edit add
command -label {Options...
} \
1905 .mbar add cascade
-label Help
-menu .mbar.
help
1909 .mbar.
help add
command -label "About [appname]" \
1914 catch
{set browser
$repo_config(instaweb.browser
)}
1915 set doc_path
[file dirname [gitexec
]]
1916 set doc_path
[file join $doc_path Documentation index.html
]
1919 set doc_path
[exec cygpath
--mixed $doc_path]
1922 if {$browser eq
{}} {
1925 } elseif
{[is_Cygwin
]} {
1926 set program_files
[file dirname [exec cygpath
--windir]]
1927 set program_files
[file join $program_files {Program Files
}]
1928 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
1929 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
1930 if {[file exists
$firefox]} {
1931 set browser
$firefox
1932 } elseif
{[file exists
$ie]} {
1935 unset program_files firefox ie
1939 if {[file isfile
$doc_path]} {
1940 set doc_url
"file:$doc_path"
1942 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
1945 if {$browser ne
{}} {
1946 .mbar.
help add
command -label {Online Documentation
} \
1947 -command [list
exec $browser $doc_url &]
1949 unset browser doc_path doc_url
1952 bind .
<Visibility
> {
1953 bind .
<Visibility
> {}
1957 # -- Standard bindings
1959 wm protocol . WM_DELETE_WINDOW do_quit
1960 bind all
<$M1B-Key-q> do_quit
1961 bind all
<$M1B-Key-Q> do_quit
1962 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
1963 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
1965 set subcommand_args
{}
1967 puts stderr
"usage: $::argv0 $::subcommand $::subcommand_args"
1971 # -- Not a normal commit type invocation? Do that instead!
1973 switch
-- $subcommand {
1976 set subcommand_args
{rev? path
}
1977 if {$argv eq
{}} usage
1982 if {$is_path ||
[file exists
$_prefix$a]} {
1983 if {$path ne
{}} usage
1986 } elseif
{$a eq
{--}} {
1988 if {$head ne
{}} usage
1993 } elseif
{$head eq
{}} {
1994 if {$head ne
{}} usage
2003 if {$head ne
{} && $path eq
{}} {
2004 set path
$_prefix$head
2011 if {[regexp
{^
[0-9a-f]{1,39}$
} $head]} {
2013 set head [git rev-parse
--verify $head]
2019 set current_branch
$head
2022 switch
-- $subcommand {
2025 if {$path ne
{} && [file isdirectory
$path]} {
2026 set head $current_branch
2032 browser
::new
$head $path
2035 if {$head eq
{} && ![file exists
$path]} {
2036 puts stderr
"fatal: cannot stat path $path: No such file or directory"
2039 blame
::new
$head $path
2046 if {[llength
$argv] != 0} {
2047 puts
-nonewline stderr
"usage: $argv0"
2048 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
2049 puts
-nonewline stderr
" $subcommand"
2054 # fall through to setup UI for commits
2057 puts stderr
"usage: $argv0 \[{blame|browser|citool}\]"
2068 -text {Current Branch
:} \
2072 -textvariable current_branch \
2075 pack .branch.l1
-side left
2076 pack .branch.cb
-side left
-fill x
2077 pack .branch
-side top
-fill x
2079 # -- Main Window Layout
2081 panedwindow .vpane
-orient vertical
2082 panedwindow .vpane.files
-orient horizontal
2083 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
2084 pack .vpane
-anchor n
-side top
-fill both
-expand 1
2086 # -- Index File List
2088 frame .vpane.files.index
-height 100 -width 200
2089 label .vpane.files.index.title
-text {Staged Changes
(Will Be Committed
)} \
2090 -background lightgreen
2091 text
$ui_index -background white
-borderwidth 0 \
2092 -width 20 -height 10 \
2094 -cursor $cursor_ptr \
2095 -xscrollcommand {.vpane.files.index.sx
set} \
2096 -yscrollcommand {.vpane.files.index.sy
set} \
2098 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
2099 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
2100 pack .vpane.files.index.title
-side top
-fill x
2101 pack .vpane.files.index.sx
-side bottom
-fill x
2102 pack .vpane.files.index.sy
-side right
-fill y
2103 pack
$ui_index -side left
-fill both
-expand 1
2104 .vpane.files add .vpane.files.index
-sticky nsew
2106 # -- Working Directory File List
2108 frame .vpane.files.workdir
-height 100 -width 200
2109 label .vpane.files.workdir.title
-text {Unstaged Changes
(Will Not Be Committed
)} \
2110 -background lightsalmon
2111 text
$ui_workdir -background white
-borderwidth 0 \
2112 -width 20 -height 10 \
2114 -cursor $cursor_ptr \
2115 -xscrollcommand {.vpane.files.workdir.sx
set} \
2116 -yscrollcommand {.vpane.files.workdir.sy
set} \
2118 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
2119 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
2120 pack .vpane.files.workdir.title
-side top
-fill x
2121 pack .vpane.files.workdir.sx
-side bottom
-fill x
2122 pack .vpane.files.workdir.sy
-side right
-fill y
2123 pack
$ui_workdir -side left
-fill both
-expand 1
2124 .vpane.files add .vpane.files.workdir
-sticky nsew
2126 foreach i
[list
$ui_index $ui_workdir] {
2127 $i tag conf in_diff
-background lightgray
2128 $i tag conf in_sel
-background lightgray
2132 # -- Diff and Commit Area
2134 frame .vpane.lower
-height 300 -width 400
2135 frame .vpane.lower.commarea
2136 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
2137 pack .vpane.lower.commarea
-side top
-fill x
2138 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
2139 .vpane add .vpane.lower
-sticky nsew
2141 # -- Commit Area Buttons
2143 frame .vpane.lower.commarea.buttons
2144 label .vpane.lower.commarea.buttons.l
-text {} \
2147 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
2148 pack .vpane.lower.commarea.buttons
-side left
-fill y
2150 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
2152 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
2153 lappend disable_on_lock \
2154 {.vpane.lower.commarea.buttons.rescan conf
-state}
2156 button .vpane.lower.commarea.buttons.incall
-text {Stage Changed
} \
2158 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
2159 lappend disable_on_lock \
2160 {.vpane.lower.commarea.buttons.incall conf
-state}
2162 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
2164 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
2166 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
2168 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
2169 lappend disable_on_lock \
2170 {.vpane.lower.commarea.buttons.commit conf
-state}
2172 button .vpane.lower.commarea.buttons.push
-text {Push
} \
2173 -command do_push_anywhere
2174 pack .vpane.lower.commarea.buttons.push
-side top
-fill x
2176 # -- Commit Message Buffer
2178 frame .vpane.lower.commarea.buffer
2179 frame .vpane.lower.commarea.buffer.header
2180 set ui_comm .vpane.lower.commarea.buffer.t
2181 set ui_coml .vpane.lower.commarea.buffer.header.l
2182 radiobutton .vpane.lower.commarea.buffer.header.new \
2183 -text {New Commit
} \
2184 -command do_select_commit_type \
2185 -variable selected_commit_type \
2187 lappend disable_on_lock \
2188 [list .vpane.lower.commarea.buffer.header.new conf
-state]
2189 radiobutton .vpane.lower.commarea.buffer.header.amend \
2190 -text {Amend Last Commit
} \
2191 -command do_select_commit_type \
2192 -variable selected_commit_type \
2194 lappend disable_on_lock \
2195 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
2199 proc trace_commit_type
{varname args
} {
2200 global ui_coml commit_type
2201 switch
-glob -- $commit_type {
2202 initial
{set txt
{Initial Commit Message
:}}
2203 amend
{set txt
{Amended Commit Message
:}}
2204 amend-initial
{set txt
{Amended Initial Commit Message
:}}
2205 amend-merge
{set txt
{Amended Merge Commit Message
:}}
2206 merge
{set txt
{Merge Commit Message
:}}
2207 * {set txt
{Commit Message
:}}
2209 $ui_coml conf
-text $txt
2211 trace add variable commit_type
write trace_commit_type
2212 pack
$ui_coml -side left
-fill x
2213 pack .vpane.lower.commarea.buffer.header.amend
-side right
2214 pack .vpane.lower.commarea.buffer.header.new
-side right
2216 text
$ui_comm -background white
-borderwidth 1 \
2219 -autoseparators true \
2221 -width 75 -height 9 -wrap none \
2223 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
2224 scrollbar .vpane.lower.commarea.buffer.sby \
2225 -command [list
$ui_comm yview
]
2226 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
2227 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
2228 pack
$ui_comm -side left
-fill y
2229 pack .vpane.lower.commarea.buffer
-side left
-fill y
2231 # -- Commit Message Buffer Context Menu
2233 set ctxm .vpane.lower.commarea.buffer.ctxm
2234 menu
$ctxm -tearoff 0
2237 -command {tk_textCut
$ui_comm}
2240 -command {tk_textCopy
$ui_comm}
2243 -command {tk_textPaste
$ui_comm}
2246 -command {$ui_comm delete sel.first sel.last
}
2249 -label {Select All
} \
2250 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
2254 $ui_comm tag add sel
0.0 end
2255 tk_textCopy
$ui_comm
2256 $ui_comm tag remove sel
0.0 end
2262 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
2266 proc trace_current_diff_path
{varname args
} {
2267 global current_diff_path diff_actions file_states
2268 if {$current_diff_path eq
{}} {
2274 set p
$current_diff_path
2275 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
2277 set p
[escape_path
$p]
2281 .vpane.lower.
diff.header.status configure
-text $s
2282 .vpane.lower.
diff.header.
file configure
-text $f
2283 .vpane.lower.
diff.header.path configure
-text $p
2284 foreach w
$diff_actions {
2288 trace add variable current_diff_path
write trace_current_diff_path
2290 frame .vpane.lower.
diff.header
-background gold
2291 label .vpane.lower.
diff.header.status \
2293 -width $max_status_desc \
2296 label .vpane.lower.
diff.header.
file \
2300 label .vpane.lower.
diff.header.path \
2304 pack .vpane.lower.
diff.header.status
-side left
2305 pack .vpane.lower.
diff.header.
file -side left
2306 pack .vpane.lower.
diff.header.path
-fill x
2307 set ctxm .vpane.lower.
diff.header.ctxm
2308 menu
$ctxm -tearoff 0
2316 -- $current_diff_path
2318 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2319 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
2323 frame .vpane.lower.
diff.body
2324 set ui_diff .vpane.lower.
diff.body.t
2325 text
$ui_diff -background white
-borderwidth 0 \
2326 -width 80 -height 15 -wrap none \
2328 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
2329 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
2331 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
2332 -command [list
$ui_diff xview
]
2333 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
2334 -command [list
$ui_diff yview
]
2335 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
2336 pack .vpane.lower.
diff.body.sby
-side right
-fill y
2337 pack
$ui_diff -side left
-fill both
-expand 1
2338 pack .vpane.lower.
diff.header
-side top
-fill x
2339 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
2341 $ui_diff tag conf d_cr
-elide true
2342 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
2343 $ui_diff tag conf d_
+ -foreground {#00a000}
2344 $ui_diff tag conf d_-
-foreground red
2346 $ui_diff tag conf d_
++ -foreground {#00a000}
2347 $ui_diff tag conf d_--
-foreground red
2348 $ui_diff tag conf d_
+s \
2349 -foreground {#00a000} \
2350 -background {#e2effa}
2351 $ui_diff tag conf d_-s \
2353 -background {#e2effa}
2354 $ui_diff tag conf d_s
+ \
2355 -foreground {#00a000} \
2357 $ui_diff tag conf d_s- \
2361 $ui_diff tag conf d
<<<<<<< \
2362 -foreground orange \
2364 $ui_diff tag conf d
======= \
2365 -foreground orange \
2367 $ui_diff tag conf d
>>>>>>> \
2368 -foreground orange \
2371 $ui_diff tag raise sel
2373 # -- Diff Body Context Menu
2375 set ctxm .vpane.lower.
diff.body.ctxm
2376 menu
$ctxm -tearoff 0
2379 -command reshow_diff
2380 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2383 -command {tk_textCopy
$ui_diff}
2384 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2386 -label {Select All
} \
2387 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
2388 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2392 $ui_diff tag add sel
0.0 end
2393 tk_textCopy
$ui_diff
2394 $ui_diff tag remove sel
0.0 end
2396 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2399 -label {Apply
/Reverse Hunk
} \
2400 -command {apply_hunk
$cursorX $cursorY}
2401 set ui_diff_applyhunk
[$ctxm index last
]
2402 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
2405 -label {Decrease Font Size
} \
2406 -command {incr_font_size font_diff
-1}
2407 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2409 -label {Increase Font Size
} \
2410 -command {incr_font_size font_diff
1}
2411 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2414 -label {Show Less Context
} \
2415 -command {if {$repo_config(gui.diffcontext
) >= 1} {
2416 incr repo_config
(gui.diffcontext
) -1
2419 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2421 -label {Show More Context
} \
2422 -command {if {$repo_config(gui.diffcontext
) < 99} {
2423 incr repo_config
(gui.diffcontext
)
2426 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2428 $ctxm add
command -label {Options...
} \
2430 proc popup_diff_menu
{ctxm x y X Y
} {
2431 global current_diff_path file_states
2434 if {$
::ui_index eq $
::current_diff_side
} {
2435 $ctxm entryconf $
::ui_diff_applyhunk \
2437 -label {Unstage Hunk From Commit
}
2438 } elseif
{$current_diff_path eq
{}
2439 ||
![info exists file_states
($current_diff_path)]
2440 ||
{_O
} eq
[lindex
$file_states($current_diff_path) 0]} {
2441 $ctxm entryconf $
::ui_diff_applyhunk \
2443 -label {Stage Hunk For Commit
}
2445 $ctxm entryconf $
::ui_diff_applyhunk \
2447 -label {Stage Hunk For Commit
}
2449 tk_popup
$ctxm $X $Y
2451 bind_button3
$ui_diff [list popup_diff_menu
$ctxm %x
%y
%X
%Y
]
2455 set main_status
[::status_bar
::new .status
]
2456 pack .status
-anchor w
-side bottom
-fill x
2457 $main_status show
{Initializing...
}
2462 set gm
$repo_config(gui.geometry
)
2463 wm geometry .
[lindex
$gm 0]
2464 .vpane sash place
0 \
2465 [lindex
[.vpane sash coord
0] 0] \
2467 .vpane.files sash place
0 \
2469 [lindex
[.vpane.files sash coord
0] 1]
2475 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
2476 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
2477 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
2478 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
2479 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
2480 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
2481 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
2482 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
2483 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
2484 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2485 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2487 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
2488 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
2489 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
2490 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
2491 bind $ui_diff <$M1B-Key-v> {break}
2492 bind $ui_diff <$M1B-Key-V> {break}
2493 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2494 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2495 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
2496 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
2497 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
2498 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
2499 bind $ui_diff <Key-k
> {catch
{%W yview scroll
-1 units
};break}
2500 bind $ui_diff <Key-j
> {catch
{%W yview scroll
1 units
};break}
2501 bind $ui_diff <Key-h
> {catch
{%W xview scroll
-1 units
};break}
2502 bind $ui_diff <Key-l
> {catch
{%W xview scroll
1 units
};break}
2503 bind $ui_diff <Control-Key-b
> {catch
{%W yview scroll
-1 pages
};break}
2504 bind $ui_diff <Control-Key-f
> {catch
{%W yview scroll
1 pages
};break}
2505 bind $ui_diff <Button-1
> {focus
%W
}
2507 if {[is_enabled branch
]} {
2508 bind .
<$M1B-Key-n> branch_create
::dialog
2509 bind .
<$M1B-Key-N> branch_create
::dialog
2510 bind .
<$M1B-Key-o> branch_checkout
::dialog
2511 bind .
<$M1B-Key-O> branch_checkout
::dialog
2512 bind .
<$M1B-Key-m> merge
::dialog
2513 bind .
<$M1B-Key-M> merge
::dialog
2515 if {[is_enabled transport
]} {
2516 bind .
<$M1B-Key-p> do_push_anywhere
2517 bind .
<$M1B-Key-P> do_push_anywhere
2520 bind .
<Key-F5
> do_rescan
2521 bind .
<$M1B-Key-r> do_rescan
2522 bind .
<$M1B-Key-R> do_rescan
2523 bind .
<$M1B-Key-s> do_signoff
2524 bind .
<$M1B-Key-S> do_signoff
2525 bind .
<$M1B-Key-i> do_add_all
2526 bind .
<$M1B-Key-I> do_add_all
2527 bind .
<$M1B-Key-Return> do_commit
2528 foreach i
[list
$ui_index $ui_workdir] {
2529 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
2530 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
2531 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
2535 set file_lists
($ui_index) [list
]
2536 set file_lists
($ui_workdir) [list
]
2538 wm title .
"[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"
2539 focus
-force $ui_comm
2541 # -- Warn the user about environmental problems. Cygwin's Tcl
2542 # does *not* pass its env array onto any processes it spawns.
2543 # This means that git processes get none of our environment.
2548 set msg
"Possible environment issues exist.
2550 The following environment variables are probably
2551 going to be ignored by any Git subprocess run
2555 foreach name
[array names env
] {
2556 switch
-regexp -- $name {
2557 {^GIT_INDEX_FILE$
} -
2558 {^GIT_OBJECT_DIRECTORY$
} -
2559 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
2561 {^GIT_EXTERNAL_DIFF$
} -
2565 {^GIT_CONFIG_LOCAL$
} -
2566 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
2567 append msg
" - $name\n"
2570 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
2571 append msg
" - $name\n"
2573 set suggest_user
$name
2577 if {$ignored_env > 0} {
2579 This is due to a known issue with the
2580 Tcl binary distributed by Cygwin."
2582 if {$suggest_user ne
{}} {
2585 A good replacement for $suggest_user
2586 is placing values for the user.name and
2587 user.email settings into your personal
2593 unset ignored_env msg suggest_user name
2596 # -- Only initialize complex UI if we are going to stay running.
2598 if {[is_enabled transport
]} {
2605 if {[winfo exists
$ui_comm]} {
2606 set GITGUI_BCK_exists
[load_message GITGUI_BCK
]
2608 # -- If both our backup and message files exist use the
2609 # newer of the two files to initialize the buffer.
2611 if {$GITGUI_BCK_exists} {
2612 set m
[gitdir GITGUI_MSG
]
2613 if {[file isfile
$m]} {
2614 if {[file mtime
[gitdir GITGUI_BCK
]] > [file mtime
$m]} {
2615 catch
{file delete
[gitdir GITGUI_MSG
]}
2617 $ui_comm delete
0.0 end
2619 $ui_comm edit modified false
2620 catch
{file delete
[gitdir GITGUI_BCK
]}
2621 set GITGUI_BCK_exists
0
2627 proc backup_commit_buffer
{} {
2628 global ui_comm GITGUI_BCK_exists
2630 set m
[$ui_comm edit modified
]
2631 if {$m ||
$GITGUI_BCK_exists} {
2632 set msg
[string trim
[$ui_comm get
0.0 end
]]
2633 regsub
-all -line {[ \r\t]+$
} $msg {} msg
2636 if {$GITGUI_BCK_exists} {
2637 catch
{file delete
[gitdir GITGUI_BCK
]}
2638 set GITGUI_BCK_exists
0
2642 set fd
[open
[gitdir GITGUI_BCK
] w
]
2643 puts
-nonewline $fd $msg
2645 set GITGUI_BCK_exists
1
2649 $ui_comm edit modified false
2652 set ::GITGUI_BCK_i
[after
2000 backup_commit_buffer
]
2655 backup_commit_buffer
2658 lock_index begin-read
2659 if {![winfo ismapped .
]} {
2663 if {[is_enabled multicommit
]} {