2 # Tcl ignores the next line -*- tcl -*- \
5 set appvers {@@GIT_VERSION@@}
7 Copyright © 2006, 2007 Shawn Pearce, Paul Mackerras.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}
23 ######################################################################
27 set _appname [lindex [file split $argv0] end]
43 return [eval [concat [list file join $_gitdir] $args]]
48 if {$_gitexec eq {}} {
49 if {[catch {set _gitexec [exec git --exec-path]} err]} {
50 error "Git not installed?\n\n$err"
56 return [eval [concat [list file join $_gitexec] $args]]
65 global tcl_platform tk_library
66 if {[tk windowingsystem] eq {aqua}} {
74 if {$tcl_platform(platform) eq {windows}} {
81 global tcl_platform _iscygwin
82 if {$_iscygwin eq {}} {
83 if {$tcl_platform(platform) eq {windows}} {
84 if {[catch {set p [exec cygpath --windir]} err]} {
96 proc is_enabled {option} {
97 global enabled_options
98 if {[catch {set on $enabled_options($option)}]} {return 0}
102 proc enable_option {option} {
103 global enabled_options
104 set enabled_options($option) 1
107 proc disable_option {option} {
108 global enabled_options
109 set enabled_options($option) 0
112 ######################################################################
116 proc is_many_config {name} {
117 switch -glob -- $name {
126 proc is_config_true {name} {
128 if {[catch {set v $repo_config($name)}]} {
130 } elseif {$v eq {true} || $v eq {1} || $v eq {yes}} {
137 proc load_config {include_global} {
138 global repo_config global_config default_config
140 array unset global_config
141 if {$include_global} {
143 set fd_rc [open "| git config --global --list" r]
144 while {[gets $fd_rc line] >= 0} {
145 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
146 if {[is_many_config $name]} {
147 lappend global_config($name) $value
149 set global_config($name) $value
157 array unset repo_config
159 set fd_rc [open "| git config --list" r]
160 while {[gets $fd_rc line] >= 0} {
161 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
162 if {[is_many_config $name]} {
163 lappend repo_config($name) $value
165 set repo_config($name) $value
172 foreach name [array names default_config] {
173 if {[catch {set v $global_config($name)}]} {
174 set global_config($name) $default_config($name)
176 if {[catch {set v $repo_config($name)}]} {
177 set repo_config($name) $default_config($name)
182 proc save_config {} {
183 global default_config font_descs
184 global repo_config global_config
185 global repo_config_new global_config_new
187 foreach option $font_descs {
188 set name [lindex $option 0]
189 set font [lindex $option 1]
190 font configure $font \
191 -family $global_config_new(gui.$font^^family) \
192 -size $global_config_new(gui.$font^^size)
193 font configure ${font}bold \
194 -family $global_config_new(gui.$font^^family) \
195 -size $global_config_new(gui.$font^^size)
196 set global_config_new(gui.$name) [font configure $font]
197 unset global_config_new(gui.$font^^family)
198 unset global_config_new(gui.$font^^size)
201 foreach name [array names default_config] {
202 set value $global_config_new($name)
203 if {$value ne $global_config($name)} {
204 if {$value eq $default_config($name)} {
205 catch {exec git config --global --unset $name}
207 regsub -all "\[{}\]" $value {"} value
208 exec git config --global $name $value
210 set global_config($name) $value
211 if {$value eq $repo_config($name)} {
212 catch {exec git config --unset $name}
213 set repo_config($name) $value
218 foreach name [array names default_config] {
219 set value $repo_config_new($name)
220 if {$value ne $repo_config($name)} {
221 if {$value eq $global_config($name)} {
222 catch {exec git config --unset $name}
224 regsub -all "\[{}\]" $value {"} value
225 exec git config $name $value
227 set repo_config($name) $value
232 proc error_popup {msg} {
234 if {[reponame] ne {}} {
235 append title " ([reponame])"
237 set cmd [list tk_messageBox \
240 -title "$title: error" \
242 if {[winfo ismapped .]} {
243 lappend cmd -parent .
248 proc warn_popup {msg} {
250 if {[reponame] ne {}} {
251 append title " ([reponame])"
253 set cmd [list tk_messageBox \
256 -title "$title: warning" \
258 if {[winfo ismapped .]} {
259 lappend cmd -parent .
264 proc info_popup {msg {parent .}} {
266 if {[reponame] ne {}} {
267 append title " ([reponame])"
277 proc ask_popup {msg} {
279 if {[reponame] ne {}} {
280 append title " ([reponame])"
282 return [tk_messageBox \
290 ######################################################################
294 if { [catch {set _gitdir $env(GIT_DIR)}]
295 && [catch {set _gitdir [exec git rev-parse --git-dir]} err]} {
296 catch {wm withdraw .}
297 error_popup "Cannot find the git directory:\n\n$err"
300 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
301 catch {set _gitdir [exec cygpath --unix $_gitdir]}
303 if {![file isdirectory $_gitdir]} {
304 catch {wm withdraw .}
305 error_popup "Git directory not found:\n\n$_gitdir"
308 if {[lindex [file split $_gitdir] end] ne {.git}} {
309 catch {wm withdraw .}
310 error_popup "Cannot use funny .git directory:\n\n$_gitdir"
313 if {[catch {cd [file dirname $_gitdir]} err]} {
314 catch {wm withdraw .}
315 error_popup "No working directory [file dirname $_gitdir]:\n\n$err"
318 set _reponame [lindex [file split \
319 [file normalize [file dirname $_gitdir]]] \
322 ######################################################################
330 set disable_on_lock [list]
331 set index_lock_type none
333 proc lock_index {type} {
334 global index_lock_type disable_on_lock
336 if {$index_lock_type eq {none}} {
337 set index_lock_type $type
338 foreach w $disable_on_lock {
339 uplevel #0 $w disabled
342 } elseif {$index_lock_type eq "begin-$type"} {
343 set index_lock_type $type
349 proc unlock_index {} {
350 global index_lock_type disable_on_lock
352 set index_lock_type none
353 foreach w $disable_on_lock {
358 ######################################################################
362 proc repository_state {ctvar hdvar mhvar} {
363 global current_branch
364 upvar $ctvar ct $hdvar hd $mhvar mh
368 if {[catch {set current_branch [exec git symbolic-ref HEAD]}]} {
369 set current_branch {}
371 regsub ^refs/((heads|tags|remotes)/)? \
377 if {[catch {set hd [exec git rev-parse --verify HEAD]}]} {
383 set merge_head [gitdir MERGE_HEAD]
384 if {[file exists $merge_head]} {
386 set fd_mh [open $merge_head r]
387 while {[gets $fd_mh line] >= 0} {
398 global PARENT empty_tree
400 set p [lindex $PARENT 0]
404 if {$empty_tree eq {}} {
405 set empty_tree [exec git mktree << {}]
410 proc rescan {after {honor_trustmtime 1}} {
411 global HEAD PARENT MERGE_HEAD commit_type
412 global ui_index ui_workdir ui_status_value ui_comm
413 global rescan_active file_states
416 if {$rescan_active > 0 || ![lock_index read]} return
418 repository_state newType newHEAD newMERGE_HEAD
419 if {[string match amend* $commit_type]
420 && $newType eq {normal}
421 && $newHEAD eq $HEAD} {
425 set MERGE_HEAD $newMERGE_HEAD
426 set commit_type $newType
429 array unset file_states
431 if {![$ui_comm edit modified]
432 || [string trim [$ui_comm get 0.0 end]] eq {}} {
433 if {[load_message GITGUI_MSG]} {
434 } elseif {[load_message MERGE_MSG]} {
435 } elseif {[load_message SQUASH_MSG]} {
438 $ui_comm edit modified false
441 if {[is_enabled branch]} {
446 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
447 rescan_stage2 {} $after
450 set ui_status_value {Refreshing file status...}
451 set cmd [list git update-index]
453 lappend cmd --unmerged
454 lappend cmd --ignore-missing
455 lappend cmd --refresh
456 set fd_rf [open "| $cmd" r]
457 fconfigure $fd_rf -blocking 0 -translation binary
458 fileevent $fd_rf readable \
459 [list rescan_stage2 $fd_rf $after]
463 proc rescan_stage2 {fd after} {
464 global ui_status_value
465 global rescan_active buf_rdi buf_rdf buf_rlo
469 if {![eof $fd]} return
473 set ls_others [list | git ls-files --others -z \
474 --exclude-per-directory=.gitignore]
475 set info_exclude [gitdir info exclude]
476 if {[file readable $info_exclude]} {
477 lappend ls_others "--exclude-from=$info_exclude"
485 set ui_status_value {Scanning for modified files ...}
486 set fd_di [open "| git diff-index --cached -z [PARENT]" r]
487 set fd_df [open "| git diff-files -z" r]
488 set fd_lo [open $ls_others r]
490 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
491 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
492 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
493 fileevent $fd_di readable [list read_diff_index $fd_di $after]
494 fileevent $fd_df readable [list read_diff_files $fd_df $after]
495 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
498 proc load_message {file} {
502 if {[file isfile $f]} {
503 if {[catch {set fd [open $f r]}]} {
506 set content [string trim [read $fd]]
508 regsub -all -line {[ \r\t]+$} $content {} content
509 $ui_comm delete 0.0 end
510 $ui_comm insert end $content
516 proc read_diff_index {fd after} {
519 append buf_rdi [read $fd]
521 set n [string length $buf_rdi]
523 set z1 [string first "\0" $buf_rdi $c]
526 set z2 [string first "\0" $buf_rdi $z1]
530 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
531 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
533 [encoding convertfrom $p] \
535 [list [lindex $i 0] [lindex $i 2]] \
541 set buf_rdi [string range $buf_rdi $c end]
546 rescan_done $fd buf_rdi $after
549 proc read_diff_files {fd after} {
552 append buf_rdf [read $fd]
554 set n [string length $buf_rdf]
556 set z1 [string first "\0" $buf_rdf $c]
559 set z2 [string first "\0" $buf_rdf $z1]
563 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
564 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
566 [encoding convertfrom $p] \
569 [list [lindex $i 0] [lindex $i 2]]
574 set buf_rdf [string range $buf_rdf $c end]
579 rescan_done $fd buf_rdf $after
582 proc read_ls_others {fd after} {
585 append buf_rlo [read $fd]
586 set pck [split $buf_rlo "\0"]
587 set buf_rlo [lindex $pck end]
588 foreach p [lrange $pck 0 end-1] {
589 merge_state [encoding convertfrom $p] ?O
591 rescan_done $fd buf_rlo $after
594 proc rescan_done {fd buf after} {
596 global file_states repo_config
599 if {![eof $fd]} return
602 if {[incr rescan_active -1] > 0} return
611 proc prune_selection {} {
612 global file_states selected_paths
614 foreach path [array names selected_paths] {
615 if {[catch {set still_here $file_states($path)}]} {
616 unset selected_paths($path)
621 ######################################################################
626 global ui_diff current_diff_path current_diff_header
627 global ui_index ui_workdir
629 $ui_diff conf -state normal
630 $ui_diff delete 0.0 end
631 $ui_diff conf -state disabled
633 set current_diff_path {}
634 set current_diff_header {}
636 $ui_index tag remove in_diff 0.0 end
637 $ui_workdir tag remove in_diff 0.0 end
640 proc reshow_diff {} {
641 global ui_status_value file_states file_lists
642 global current_diff_path current_diff_side
644 set p $current_diff_path
646 || $current_diff_side eq {}
647 || [catch {set s $file_states($p)}]
648 || [lsearch -sorted -exact $file_lists($current_diff_side) $p] == -1} {
651 show_diff $p $current_diff_side
655 proc handle_empty_diff {} {
656 global current_diff_path file_states file_lists
658 set path $current_diff_path
659 set s $file_states($path)
660 if {[lindex $s 0] ne {_M}} return
662 info_popup "No differences detected.
664 [short_path $path] has no changes.
666 The modification date of this file was updated
667 by another application, but the content within
668 the file was not changed.
670 A rescan will be automatically started to find
671 other files which may have the same state."
674 display_file $path __
675 rescan {set ui_status_value {Ready.}} 0
678 proc show_diff {path w {lno {}}} {
679 global file_states file_lists
680 global is_3way_diff diff_active repo_config
681 global ui_diff ui_status_value ui_index ui_workdir
682 global current_diff_path current_diff_side current_diff_header
684 if {$diff_active || ![lock_index read]} return
688 set lno [lsearch -sorted -exact $file_lists($w) $path]
694 $w tag add in_diff $lno.0 [expr {$lno + 1}].0
697 set s $file_states($path)
701 set current_diff_path $path
702 set current_diff_side $w
703 set current_diff_header {}
704 set ui_status_value "Loading diff of [escape_path $path]..."
706 # - Git won't give us the diff, there's nothing to compare to!
709 set max_sz [expr {128 * 1024}]
711 set fd [open $path r]
712 set content [read $fd $max_sz]
714 set sz [file size $path]
718 set ui_status_value "Unable to display [escape_path $path]"
719 error_popup "Error loading file:\n\n$err"
722 $ui_diff conf -state normal
723 if {![catch {set type [exec file $path]}]} {
724 set n [string length $path]
725 if {[string equal -length $n $path $type]} {
726 set type [string range $type $n end]
727 regsub {^:?\s*} $type {} type
729 $ui_diff insert end "* $type\n" d_@
731 if {[string first "\0" $content] != -1} {
732 $ui_diff insert end \
733 "* Binary file (not showing content)." \
737 $ui_diff insert end \
738 "* Untracked file is $sz bytes.
739 * Showing only first $max_sz bytes.
742 $ui_diff insert end $content
744 $ui_diff insert end "
745 * Untracked file clipped here by [appname].
746 * To see the entire file, use an external editor.
750 $ui_diff conf -state disabled
753 set ui_status_value {Ready.}
758 if {$w eq $ui_index} {
759 lappend cmd diff-index
761 } elseif {$w eq $ui_workdir} {
762 if {[string index $m 0] eq {U}} {
765 lappend cmd diff-files
770 lappend cmd --no-color
771 if {$repo_config(gui.diffcontext) > 0} {
772 lappend cmd "-U$repo_config(gui.diffcontext)"
774 if {$w eq $ui_index} {
780 if {[catch {set fd [open $cmd r]} err]} {
783 set ui_status_value "Unable to display [escape_path $path]"
784 error_popup "Error loading diff:\n\n$err"
792 fileevent $fd readable [list read_diff $fd]
795 proc read_diff {fd} {
796 global ui_diff ui_status_value diff_active
797 global is_3way_diff current_diff_header
799 $ui_diff conf -state normal
800 while {[gets $fd line] >= 0} {
801 # -- Cleanup uninteresting diff header lines.
803 if { [string match {diff --git *} $line]
804 || [string match {diff --cc *} $line]
805 || [string match {diff --combined *} $line]
806 || [string match {--- *} $line]
807 || [string match {+++ *} $line]} {
808 append current_diff_header $line "\n"
811 if {[string match {index *} $line]} continue
812 if {$line eq {deleted file mode 120000}} {
813 set line "deleted symlink"
816 # -- Automatically detect if this is a 3 way diff.
818 if {[string match {@@@ *} $line]} {set is_3way_diff 1}
820 if {[string match {mode *} $line]
821 || [string match {new file *} $line]
822 || [string match {deleted file *} $line]
823 || [string match {Binary files * and * differ} $line]
824 || $line eq {\ No newline at end of file}
825 || [regexp {^\* Unmerged path } $line]} {
827 } elseif {$is_3way_diff} {
828 set op [string range $line 0 1]
838 if {[regexp {^\+\+([<>]{7} |={7})} $line _g op]} {
839 set line [string replace $line 0 1 { }]
846 puts "error: Unhandled 3 way diff marker: {$op}"
851 set op [string index $line 0]
857 if {[regexp {^\+([<>]{7} |={7})} $line _g op]} {
858 set line [string replace $line 0 0 { }]
865 puts "error: Unhandled 2 way diff marker: {$op}"
870 $ui_diff insert end $line $tags
871 if {[string index $line end] eq "\r"} {
872 $ui_diff tag add d_cr {end - 2c}
874 $ui_diff insert end "\n" $tags
876 $ui_diff conf -state disabled
882 set ui_status_value {Ready.}
884 if {[$ui_diff index end] eq {2.0}} {
890 proc apply_hunk {x y} {
891 global current_diff_path current_diff_header current_diff_side
892 global ui_diff ui_index file_states
894 if {$current_diff_path eq {} || $current_diff_header eq {}} return
895 if {![lock_index apply_hunk]} return
897 set apply_cmd {git apply --cached --whitespace=nowarn}
898 set mi [lindex $file_states($current_diff_path) 0]
899 if {$current_diff_side eq $ui_index} {
901 lappend apply_cmd --reverse
902 if {[string index $mi 0] ne {M}} {
908 if {[string index $mi 1] ne {M}} {
914 set s_lno [lindex [split [$ui_diff index @$x,$y] .] 0]
915 set s_lno [$ui_diff search -backwards -regexp ^@@ $s_lno.0 0.0]
921 set e_lno [$ui_diff search -forwards -regexp ^@@ "$s_lno + 1 lines" end]
927 set p [open "| $apply_cmd" w]
928 fconfigure $p -translation binary -encoding binary
929 puts -nonewline $p $current_diff_header
930 puts -nonewline $p [$ui_diff get $s_lno $e_lno]
932 error_popup "Failed to $mode selected hunk.\n\n$err"
937 $ui_diff conf -state normal
938 $ui_diff delete $s_lno $e_lno
939 $ui_diff conf -state disabled
941 if {[$ui_diff get 1.0 end] eq "\n"} {
947 if {$current_diff_side eq $ui_index} {
949 } elseif {[string index $mi 0] eq {_}} {
955 display_file $current_diff_path $mi
961 ######################################################################
965 proc load_last_commit {} {
966 global HEAD PARENT MERGE_HEAD commit_type ui_comm
969 if {[llength $PARENT] == 0} {
970 error_popup {There is nothing to amend.
972 You are about to create the initial commit.
973 There is no commit before this to amend.
978 repository_state curType curHEAD curMERGE_HEAD
979 if {$curType eq {merge}} {
980 error_popup {Cannot amend while merging.
982 You are currently in the middle of a merge that
983 has not been fully completed. You cannot amend
984 the prior commit unless you first abort the
985 current merge activity.
993 set fd [open "| git cat-file commit $curHEAD" r]
994 fconfigure $fd -encoding binary -translation lf
995 if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
998 while {[gets $fd line] > 0} {
999 if {[string match {parent *} $line]} {
1000 lappend parents [string range $line 7 end]
1001 } elseif {[string match {encoding *} $line]} {
1002 set enc [string tolower [string range $line 9 end]]
1005 fconfigure $fd -encoding $enc
1006 set msg [string trim [read $fd]]
1009 error_popup "Error loading commit data for amend:\n\n$err"
1015 set MERGE_HEAD [list]
1016 switch -- [llength $parents] {
1017 0 {set commit_type amend-initial}
1018 1 {set commit_type amend}
1019 default {set commit_type amend-merge}
1022 $ui_comm delete 0.0 end
1023 $ui_comm insert end $msg
1025 $ui_comm edit modified false
1026 rescan {set ui_status_value {Ready.}}
1029 proc create_new_commit {} {
1030 global commit_type ui_comm
1032 set commit_type normal
1033 $ui_comm delete 0.0 end
1035 $ui_comm edit modified false
1036 rescan {set ui_status_value {Ready.}}
1039 set GIT_COMMITTER_IDENT {}
1041 proc committer_ident {} {
1042 global GIT_COMMITTER_IDENT
1044 if {$GIT_COMMITTER_IDENT eq {}} {
1045 if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
1046 error_popup "Unable to obtain your identity:\n\n$err"
1049 if {![regexp {^(.*) [0-9]+ [-+0-9]+$} \
1050 $me me GIT_COMMITTER_IDENT]} {
1051 error_popup "Invalid GIT_COMMITTER_IDENT:\n\n$me"
1056 return $GIT_COMMITTER_IDENT
1059 proc commit_tree {} {
1060 global HEAD commit_type file_states ui_comm repo_config
1061 global ui_status_value pch_error
1063 if {[committer_ident] eq {}} return
1064 if {![lock_index update]} return
1066 # -- Our in memory state should match the repository.
1068 repository_state curType curHEAD curMERGE_HEAD
1069 if {[string match amend* $commit_type]
1070 && $curType eq {normal}
1071 && $curHEAD eq $HEAD} {
1072 } elseif {$commit_type ne $curType || $HEAD ne $curHEAD} {
1073 info_popup {Last scanned state does not match repository state.
1075 Another Git program has modified this repository
1076 since the last scan. A rescan must be performed
1077 before another commit can be created.
1079 The rescan will be automatically started now.
1082 rescan {set ui_status_value {Ready.}}
1086 # -- At least one file should differ in the index.
1089 foreach path [array names file_states] {
1090 switch -glob -- [lindex $file_states($path) 0] {
1094 M? {set files_ready 1}
1096 error_popup "Unmerged files cannot be committed.
1098 File [short_path $path] has merge conflicts.
1099 You must resolve them and add the file before committing.
1105 error_popup "Unknown file state [lindex $s 0] detected.
1107 File [short_path $path] cannot be committed by this program.
1112 if {!$files_ready} {
1113 info_popup {No changes to commit.
1115 You must add at least 1 file before you can commit.
1121 # -- A message is required.
1123 set msg [string trim [$ui_comm get 1.0 end]]
1124 regsub -all -line {[ \t\r]+$} $msg {} msg
1126 error_popup {Please supply a commit message.
1128 A good commit message has the following format:
1130 - First line: Describe in one sentance what you did.
1131 - Second line: Blank
1132 - Remaining lines: Describe why this change is good.
1138 # -- Run the pre-commit hook.
1140 set pchook [gitdir hooks pre-commit]
1142 # On Cygwin [file executable] might lie so we need to ask
1143 # the shell if the hook is executable. Yes that's annoying.
1145 if {[is_Cygwin] && [file isfile $pchook]} {
1146 set pchook [list sh -c [concat \
1147 "if test -x \"$pchook\";" \
1148 "then exec \"$pchook\" 2>&1;" \
1150 } elseif {[file executable $pchook]} {
1151 set pchook [list $pchook |& cat]
1153 commit_writetree $curHEAD $msg
1157 set ui_status_value {Calling pre-commit hook...}
1159 set fd_ph [open "| $pchook" r]
1160 fconfigure $fd_ph -blocking 0 -translation binary
1161 fileevent $fd_ph readable \
1162 [list commit_prehook_wait $fd_ph $curHEAD $msg]
1165 proc commit_prehook_wait {fd_ph curHEAD msg} {
1166 global pch_error ui_status_value
1168 append pch_error [read $fd_ph]
1169 fconfigure $fd_ph -blocking 1
1171 if {[catch {close $fd_ph}]} {
1172 set ui_status_value {Commit declined by pre-commit hook.}
1173 hook_failed_popup pre-commit $pch_error
1176 commit_writetree $curHEAD $msg
1181 fconfigure $fd_ph -blocking 0
1184 proc commit_writetree {curHEAD msg} {
1185 global ui_status_value
1187 set ui_status_value {Committing changes...}
1188 set fd_wt [open "| git write-tree" r]
1189 fileevent $fd_wt readable \
1190 [list commit_committree $fd_wt $curHEAD $msg]
1193 proc commit_committree {fd_wt curHEAD msg} {
1194 global HEAD PARENT MERGE_HEAD commit_type
1195 global all_heads current_branch
1196 global ui_status_value ui_comm selected_commit_type
1197 global file_states selected_paths rescan_active
1201 if {$tree_id eq {} || [catch {close $fd_wt} err]} {
1202 error_popup "write-tree failed:\n\n$err"
1203 set ui_status_value {Commit failed.}
1208 # -- Build the message.
1210 set msg_p [gitdir COMMIT_EDITMSG]
1211 set msg_wt [open $msg_p w]
1212 if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
1215 fconfigure $msg_wt -encoding $enc -translation binary
1216 puts -nonewline $msg_wt $msg
1219 # -- Create the commit.
1221 set cmd [list git commit-tree $tree_id]
1222 set parents [concat $PARENT $MERGE_HEAD]
1223 if {[llength $parents] > 0} {
1224 foreach p $parents {
1228 # git commit-tree writes to stderr during initial commit.
1229 lappend cmd 2>/dev/null
1232 if {[catch {set cmt_id [eval exec $cmd]} err]} {
1233 error_popup "commit-tree failed:\n\n$err"
1234 set ui_status_value {Commit failed.}
1239 # -- Update the HEAD ref.
1242 if {$commit_type ne {normal}} {
1243 append reflogm " ($commit_type)"
1245 set i [string first "\n" $msg]
1247 append reflogm {: } [string range $msg 0 [expr {$i - 1}]]
1249 append reflogm {: } $msg
1251 set cmd [list git update-ref -m $reflogm HEAD $cmt_id $curHEAD]
1252 if {[catch {eval exec $cmd} err]} {
1253 error_popup "update-ref failed:\n\n$err"
1254 set ui_status_value {Commit failed.}
1259 # -- Make sure our current branch exists.
1261 if {$commit_type eq {initial}} {
1262 lappend all_heads $current_branch
1263 set all_heads [lsort -unique $all_heads]
1264 populate_branch_menu
1267 # -- Cleanup after ourselves.
1269 catch {file delete $msg_p}
1270 catch {file delete [gitdir MERGE_HEAD]}
1271 catch {file delete [gitdir MERGE_MSG]}
1272 catch {file delete [gitdir SQUASH_MSG]}
1273 catch {file delete [gitdir GITGUI_MSG]}
1275 # -- Let rerere do its thing.
1277 if {[file isdirectory [gitdir rr-cache]]} {
1278 catch {exec git rerere}
1281 # -- Run the post-commit hook.
1283 set pchook [gitdir hooks post-commit]
1284 if {[is_Cygwin] && [file isfile $pchook]} {
1285 set pchook [list sh -c [concat \
1286 "if test -x \"$pchook\";" \
1287 "then exec \"$pchook\";" \
1289 } elseif {![file executable $pchook]} {
1292 if {$pchook ne {}} {
1293 catch {exec $pchook &}
1296 $ui_comm delete 0.0 end
1298 $ui_comm edit modified false
1300 if {[is_enabled singlecommit]} do_quit
1302 # -- Update in memory status
1304 set selected_commit_type new
1305 set commit_type normal
1308 set MERGE_HEAD [list]
1310 foreach path [array names file_states] {
1311 set s $file_states($path)
1313 switch -glob -- $m {
1321 unset file_states($path)
1322 catch {unset selected_paths($path)}
1325 set file_states($path) [list _O [lindex $s 1] {} {}]
1331 set file_states($path) [list \
1332 _[string index $m 1] \
1343 set ui_status_value \
1344 "Changes committed as [string range $cmt_id 0 7]."
1347 ######################################################################
1351 proc fetch_from {remote} {
1352 set w [new_console \
1354 "Fetching new changes from $remote"]
1355 set cmd [list git fetch]
1357 console_exec $w $cmd console_done
1360 proc push_to {remote} {
1361 set w [new_console \
1363 "Pushing changes to $remote"]
1364 set cmd [list git push]
1367 console_exec $w $cmd console_done
1370 ######################################################################
1374 proc mapicon {w state path} {
1377 if {[catch {set r $all_icons($state$w)}]} {
1378 puts "error: no icon for $w state={$state} $path"
1384 proc mapdesc {state path} {
1387 if {[catch {set r $all_descs($state)}]} {
1388 puts "error: no desc for state={$state} $path"
1394 proc escape_path {path} {
1395 regsub -all {\\} $path "\\\\" path
1396 regsub -all "\n" $path "\\n" path
1400 proc short_path {path} {
1401 return [escape_path [lindex [file split $path] end]]
1405 set null_sha1 [string repeat 0 40]
1407 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1408 global file_states next_icon_id null_sha1
1410 set s0 [string index $new_state 0]
1411 set s1 [string index $new_state 1]
1413 if {[catch {set info $file_states($path)}]} {
1415 set icon n[incr next_icon_id]
1417 set state [lindex $info 0]
1418 set icon [lindex $info 1]
1419 if {$head_info eq {}} {set head_info [lindex $info 2]}
1420 if {$index_info eq {}} {set index_info [lindex $info 3]}
1423 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1424 elseif {$s0 eq {_}} {set s0 _}
1426 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1427 elseif {$s1 eq {_}} {set s1 _}
1429 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1430 set head_info [list 0 $null_sha1]
1431 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1432 && $head_info eq {}} {
1433 set head_info $index_info
1436 set file_states($path) [list $s0$s1 $icon \
1437 $head_info $index_info \
1442 proc display_file_helper {w path icon_name old_m new_m} {
1445 if {$new_m eq {_}} {
1446 set lno [lsearch -sorted -exact $file_lists($w) $path]
1448 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1450 $w conf -state normal
1451 $w delete $lno.0 [expr {$lno + 1}].0
1452 $w conf -state disabled
1454 } elseif {$old_m eq {_} && $new_m ne {_}} {
1455 lappend file_lists($w) $path
1456 set file_lists($w) [lsort -unique $file_lists($w)]
1457 set lno [lsearch -sorted -exact $file_lists($w) $path]
1459 $w conf -state normal
1460 $w image create $lno.0 \
1461 -align center -padx 5 -pady 1 \
1463 -image [mapicon $w $new_m $path]
1464 $w insert $lno.1 "[escape_path $path]\n"
1465 $w conf -state disabled
1466 } elseif {$old_m ne $new_m} {
1467 $w conf -state normal
1468 $w image conf $icon_name -image [mapicon $w $new_m $path]
1469 $w conf -state disabled
1473 proc display_file {path state} {
1474 global file_states selected_paths
1475 global ui_index ui_workdir
1477 set old_m [merge_state $path $state]
1478 set s $file_states($path)
1479 set new_m [lindex $s 0]
1480 set icon_name [lindex $s 1]
1482 set o [string index $old_m 0]
1483 set n [string index $new_m 0]
1490 display_file_helper $ui_index $path $icon_name $o $n
1492 if {[string index $old_m 0] eq {U}} {
1495 set o [string index $old_m 1]
1497 if {[string index $new_m 0] eq {U}} {
1500 set n [string index $new_m 1]
1502 display_file_helper $ui_workdir $path $icon_name $o $n
1504 if {$new_m eq {__}} {
1505 unset file_states($path)
1506 catch {unset selected_paths($path)}
1510 proc display_all_files_helper {w path icon_name m} {
1513 lappend file_lists($w) $path
1514 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1515 $w image create end \
1516 -align center -padx 5 -pady 1 \
1518 -image [mapicon $w $m $path]
1519 $w insert end "[escape_path $path]\n"
1522 proc display_all_files {} {
1523 global ui_index ui_workdir
1524 global file_states file_lists
1527 $ui_index conf -state normal
1528 $ui_workdir conf -state normal
1530 $ui_index delete 0.0 end
1531 $ui_workdir delete 0.0 end
1534 set file_lists($ui_index) [list]
1535 set file_lists($ui_workdir) [list]
1537 foreach path [lsort [array names file_states]] {
1538 set s $file_states($path)
1540 set icon_name [lindex $s 1]
1542 set s [string index $m 0]
1543 if {$s ne {U} && $s ne {_}} {
1544 display_all_files_helper $ui_index $path \
1548 if {[string index $m 0] eq {U}} {
1551 set s [string index $m 1]
1554 display_all_files_helper $ui_workdir $path \
1559 $ui_index conf -state disabled
1560 $ui_workdir conf -state disabled
1563 proc update_indexinfo {msg pathList after} {
1564 global update_index_cp ui_status_value
1566 if {![lock_index update]} return
1568 set update_index_cp 0
1569 set pathList [lsort $pathList]
1570 set totalCnt [llength $pathList]
1571 set batch [expr {int($totalCnt * .01) + 1}]
1572 if {$batch > 25} {set batch 25}
1574 set ui_status_value [format \
1575 "$msg... %i/%i files (%.2f%%)" \
1579 set fd [open "| git update-index -z --index-info" w]
1586 fileevent $fd writable [list \
1587 write_update_indexinfo \
1597 proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
1598 global update_index_cp ui_status_value
1599 global file_states current_diff_path
1601 if {$update_index_cp >= $totalCnt} {
1608 for {set i $batch} \
1609 {$update_index_cp < $totalCnt && $i > 0} \
1611 set path [lindex $pathList $update_index_cp]
1612 incr update_index_cp
1614 set s $file_states($path)
1615 switch -glob -- [lindex $s 0] {
1622 set info [lindex $s 2]
1623 if {$info eq {}} continue
1625 puts -nonewline $fd "$info\t[encoding convertto $path]\0"
1626 display_file $path $new
1629 set ui_status_value [format \
1630 "$msg... %i/%i files (%.2f%%)" \
1633 [expr {100.0 * $update_index_cp / $totalCnt}]]
1636 proc update_index {msg pathList after} {
1637 global update_index_cp ui_status_value
1639 if {![lock_index update]} return
1641 set update_index_cp 0
1642 set pathList [lsort $pathList]
1643 set totalCnt [llength $pathList]
1644 set batch [expr {int($totalCnt * .01) + 1}]
1645 if {$batch > 25} {set batch 25}
1647 set ui_status_value [format \
1648 "$msg... %i/%i files (%.2f%%)" \
1652 set fd [open "| git update-index --add --remove -z --stdin" w]
1659 fileevent $fd writable [list \
1660 write_update_index \
1670 proc write_update_index {fd pathList totalCnt batch msg after} {
1671 global update_index_cp ui_status_value
1672 global file_states current_diff_path
1674 if {$update_index_cp >= $totalCnt} {
1681 for {set i $batch} \
1682 {$update_index_cp < $totalCnt && $i > 0} \
1684 set path [lindex $pathList $update_index_cp]
1685 incr update_index_cp
1687 switch -glob -- [lindex $file_states($path) 0] {
1693 if {[file exists $path]} {
1702 puts -nonewline $fd "[encoding convertto $path]\0"
1703 display_file $path $new
1706 set ui_status_value [format \
1707 "$msg... %i/%i files (%.2f%%)" \
1710 [expr {100.0 * $update_index_cp / $totalCnt}]]
1713 proc checkout_index {msg pathList after} {
1714 global update_index_cp ui_status_value
1716 if {![lock_index update]} return
1718 set update_index_cp 0
1719 set pathList [lsort $pathList]
1720 set totalCnt [llength $pathList]
1721 set batch [expr {int($totalCnt * .01) + 1}]
1722 if {$batch > 25} {set batch 25}
1724 set ui_status_value [format \
1725 "$msg... %i/%i files (%.2f%%)" \
1729 set cmd [list git checkout-index]
1735 set fd [open "| $cmd " w]
1742 fileevent $fd writable [list \
1743 write_checkout_index \
1753 proc write_checkout_index {fd pathList totalCnt batch msg after} {
1754 global update_index_cp ui_status_value
1755 global file_states current_diff_path
1757 if {$update_index_cp >= $totalCnt} {
1764 for {set i $batch} \
1765 {$update_index_cp < $totalCnt && $i > 0} \
1767 set path [lindex $pathList $update_index_cp]
1768 incr update_index_cp
1769 switch -glob -- [lindex $file_states($path) 0] {
1773 puts -nonewline $fd "[encoding convertto $path]\0"
1774 display_file $path ?_
1779 set ui_status_value [format \
1780 "$msg... %i/%i files (%.2f%%)" \
1783 [expr {100.0 * $update_index_cp / $totalCnt}]]
1786 ######################################################################
1788 ## branch management
1790 proc is_tracking_branch {name} {
1791 global tracking_branches
1793 if {![catch {set info $tracking_branches($name)}]} {
1796 foreach t [array names tracking_branches] {
1797 if {[string match {*/\*} $t] && [string match $t $name]} {
1804 proc load_all_heads {} {
1807 set all_heads [list]
1808 set fd [open "| git for-each-ref --format=%(refname) refs/heads" r]
1809 while {[gets $fd line] > 0} {
1810 if {[is_tracking_branch $line]} continue
1811 if {![regsub ^refs/heads/ $line {} name]} continue
1812 lappend all_heads $name
1816 set all_heads [lsort $all_heads]
1819 proc populate_branch_menu {} {
1820 global all_heads disable_on_lock
1823 set last [$m index last]
1824 for {set i 0} {$i <= $last} {incr i} {
1825 if {[$m type $i] eq {separator}} {
1828 foreach a $disable_on_lock {
1829 if {[lindex $a 0] ne $m || [lindex $a 2] < $i} {
1833 set disable_on_lock $new_dol
1838 if {$all_heads ne {}} {
1841 foreach b $all_heads {
1842 $m add radiobutton \
1844 -command [list switch_branch $b] \
1845 -variable current_branch \
1848 lappend disable_on_lock \
1849 [list $m entryconf [$m index last] -state]
1853 proc all_tracking_branches {} {
1854 global tracking_branches
1856 set all_trackings {}
1858 foreach name [array names tracking_branches] {
1859 if {[regsub {/\*$} $name {} name]} {
1862 regsub ^refs/(heads|remotes)/ $name {} name
1863 lappend all_trackings $name
1868 set fd [open "| git for-each-ref --format=%(refname) $cmd" r]
1869 while {[gets $fd name] > 0} {
1870 regsub ^refs/(heads|remotes)/ $name {} name
1871 lappend all_trackings $name
1876 return [lsort -unique $all_trackings]
1879 proc do_create_branch_action {w} {
1880 global all_heads null_sha1 repo_config
1881 global create_branch_checkout create_branch_revtype
1882 global create_branch_head create_branch_trackinghead
1883 global create_branch_name create_branch_revexp
1885 set newbranch $create_branch_name
1886 if {$newbranch eq {}
1887 || $newbranch eq $repo_config(gui.newbranchtemplate)} {
1891 -title [wm title $w] \
1893 -message "Please supply a branch name."
1894 focus $w.desc.name_t
1897 if {![catch {exec git show-ref --verify -- "refs/heads/$newbranch"}]} {
1901 -title [wm title $w] \
1903 -message "Branch '$newbranch' already exists."
1904 focus $w.desc.name_t
1907 if {[catch {exec git check-ref-format "heads/$newbranch"}]} {
1911 -title [wm title $w] \
1913 -message "We do not like '$newbranch' as a branch name."
1914 focus $w.desc.name_t
1919 switch -- $create_branch_revtype {
1920 head {set rev $create_branch_head}
1921 tracking {set rev $create_branch_trackinghead}
1922 expression {set rev $create_branch_revexp}
1924 if {[catch {set cmt [exec git rev-parse --verify "${rev}^0"]}]} {
1928 -title [wm title $w] \
1930 -message "Invalid starting revision: $rev"
1933 set cmd [list git update-ref]
1935 lappend cmd "branch: Created from $rev"
1936 lappend cmd "refs/heads/$newbranch"
1938 lappend cmd $null_sha1
1939 if {[catch {eval exec $cmd} err]} {
1943 -title [wm title $w] \
1945 -message "Failed to create '$newbranch'.\n\n$err"
1949 lappend all_heads $newbranch
1950 set all_heads [lsort $all_heads]
1951 populate_branch_menu
1953 if {$create_branch_checkout} {
1954 switch_branch $newbranch
1958 proc radio_selector {varname value args} {
1959 upvar #0 $varname var
1963 trace add variable create_branch_head write \
1964 [list radio_selector create_branch_revtype head]
1965 trace add variable create_branch_trackinghead write \
1966 [list radio_selector create_branch_revtype tracking]
1968 trace add variable delete_branch_head write \
1969 [list radio_selector delete_branch_checktype head]
1970 trace add variable delete_branch_trackinghead write \
1971 [list radio_selector delete_branch_checktype tracking]
1973 proc do_create_branch {} {
1974 global all_heads current_branch repo_config
1975 global create_branch_checkout create_branch_revtype
1976 global create_branch_head create_branch_trackinghead
1977 global create_branch_name create_branch_revexp
1979 set w .branch_editor
1981 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
1983 label $w.header -text {Create New Branch} \
1985 pack $w.header -side top -fill x
1988 button $w.buttons.create -text Create \
1991 -command [list do_create_branch_action $w]
1992 pack $w.buttons.create -side right
1993 button $w.buttons.cancel -text {Cancel} \
1995 -command [list destroy $w]
1996 pack $w.buttons.cancel -side right -padx 5
1997 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
1999 labelframe $w.desc \
2000 -text {Branch Description} \
2002 label $w.desc.name_l -text {Name:} -font font_ui
2003 entry $w.desc.name_t \
2007 -textvariable create_branch_name \
2011 if {%d == 1 && [regexp {[~^:?*\[\0- ]} %S]} {return 0}
2014 grid $w.desc.name_l $w.desc.name_t -sticky we -padx {0 5}
2015 grid columnconfigure $w.desc 1 -weight 1
2016 pack $w.desc -anchor nw -fill x -pady 5 -padx 5
2018 labelframe $w.from \
2019 -text {Starting Revision} \
2021 radiobutton $w.from.head_r \
2022 -text {Local Branch:} \
2024 -variable create_branch_revtype \
2026 eval tk_optionMenu $w.from.head_m create_branch_head $all_heads
2027 grid $w.from.head_r $w.from.head_m -sticky w
2028 set all_trackings [all_tracking_branches]
2029 if {$all_trackings ne {}} {
2030 set create_branch_trackinghead [lindex $all_trackings 0]
2031 radiobutton $w.from.tracking_r \
2032 -text {Tracking Branch:} \
2034 -variable create_branch_revtype \
2036 eval tk_optionMenu $w.from.tracking_m \
2037 create_branch_trackinghead \
2039 grid $w.from.tracking_r $w.from.tracking_m -sticky w
2041 radiobutton $w.from.exp_r \
2042 -text {Revision Expression:} \
2044 -variable create_branch_revtype \
2046 entry $w.from.exp_t \
2050 -textvariable create_branch_revexp \
2054 if {%d == 1 && [regexp {\s} %S]} {return 0}
2055 if {%d == 1 && [string length %S] > 0} {
2056 set create_branch_revtype expression
2060 grid $w.from.exp_r $w.from.exp_t -sticky we -padx {0 5}
2061 grid columnconfigure $w.from 1 -weight 1
2062 pack $w.from -anchor nw -fill x -pady 5 -padx 5
2064 labelframe $w.postActions \
2065 -text {Post Creation Actions} \
2067 checkbutton $w.postActions.checkout \
2068 -text {Checkout after creation} \
2069 -variable create_branch_checkout \
2071 pack $w.postActions.checkout -anchor nw
2072 pack $w.postActions -anchor nw -fill x -pady 5 -padx 5
2074 set create_branch_checkout 1
2075 set create_branch_head $current_branch
2076 set create_branch_revtype head
2077 set create_branch_name $repo_config(gui.newbranchtemplate)
2078 set create_branch_revexp {}
2080 bind $w <Visibility> "
2082 $w.desc.name_t icursor end
2083 focus $w.desc.name_t
2085 bind $w <Key-Escape> "destroy $w"
2086 bind $w <Key-Return> "do_create_branch_action $w;break"
2087 wm title $w "[appname] ([reponame]): Create Branch"
2091 proc do_delete_branch_action {w} {
2093 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2096 switch -- $delete_branch_checktype {
2097 head {set check_rev $delete_branch_head}
2098 tracking {set check_rev $delete_branch_trackinghead}
2099 always {set check_rev {:none}}
2101 if {$check_rev eq {:none}} {
2103 } elseif {[catch {set check_cmt [exec git rev-parse --verify "${check_rev}^0"]}]} {
2107 -title [wm title $w] \
2109 -message "Invalid check revision: $check_rev"
2113 set to_delete [list]
2114 set not_merged [list]
2115 foreach i [$w.list.l curselection] {
2116 set b [$w.list.l get $i]
2117 if {[catch {set o [exec git rev-parse --verify $b]}]} continue
2118 if {$check_cmt ne {}} {
2119 if {$b eq $check_rev} continue
2120 if {[catch {set m [exec git merge-base $o $check_cmt]}]} continue
2122 lappend not_merged $b
2126 lappend to_delete [list $b $o]
2128 if {$not_merged ne {}} {
2129 set msg "The following branches are not completely merged into $check_rev:
2131 - [join $not_merged "\n - "]"
2135 -title [wm title $w] \
2139 if {$to_delete eq {}} return
2140 if {$delete_branch_checktype eq {always}} {
2141 set msg {Recovering deleted branches is difficult.
2143 Delete the selected branches?}
2144 if {[tk_messageBox \
2147 -title [wm title $w] \
2149 -message $msg] ne yes} {
2155 foreach i $to_delete {
2158 if {[catch {exec git update-ref -d "refs/heads/$b" $o} err]} {
2159 append failed " - $b: $err\n"
2161 set x [lsearch -sorted -exact $all_heads $b]
2163 set all_heads [lreplace $all_heads $x $x]
2168 if {$failed ne {}} {
2172 -title [wm title $w] \
2174 -message "Failed to delete branches:\n$failed"
2177 set all_heads [lsort $all_heads]
2178 populate_branch_menu
2182 proc do_delete_branch {} {
2183 global all_heads tracking_branches current_branch
2184 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2186 set w .branch_editor
2188 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
2190 label $w.header -text {Delete Local Branch} \
2192 pack $w.header -side top -fill x
2195 button $w.buttons.create -text Delete \
2197 -command [list do_delete_branch_action $w]
2198 pack $w.buttons.create -side right
2199 button $w.buttons.cancel -text {Cancel} \
2201 -command [list destroy $w]
2202 pack $w.buttons.cancel -side right -padx 5
2203 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
2205 labelframe $w.list \
2206 -text {Local Branches} \
2211 -selectmode extended \
2212 -yscrollcommand [list $w.list.sby set] \
2214 foreach h $all_heads {
2215 if {$h ne $current_branch} {
2216 $w.list.l insert end $h
2219 scrollbar $w.list.sby -command [list $w.list.l yview]
2220 pack $w.list.sby -side right -fill y
2221 pack $w.list.l -side left -fill both -expand 1
2222 pack $w.list -fill both -expand 1 -pady 5 -padx 5
2224 labelframe $w.validate \
2225 -text {Delete Only If} \
2227 radiobutton $w.validate.head_r \
2228 -text {Merged Into Local Branch:} \
2230 -variable delete_branch_checktype \
2232 eval tk_optionMenu $w.validate.head_m delete_branch_head $all_heads
2233 grid $w.validate.head_r $w.validate.head_m -sticky w
2234 set all_trackings [all_tracking_branches]
2235 if {$all_trackings ne {}} {
2236 set delete_branch_trackinghead [lindex $all_trackings 0]
2237 radiobutton $w.validate.tracking_r \
2238 -text {Merged Into Tracking Branch:} \
2240 -variable delete_branch_checktype \
2242 eval tk_optionMenu $w.validate.tracking_m \
2243 delete_branch_trackinghead \
2245 grid $w.validate.tracking_r $w.validate.tracking_m -sticky w
2247 radiobutton $w.validate.always_r \
2248 -text {Always (Do not perform merge checks)} \
2250 -variable delete_branch_checktype \
2252 grid $w.validate.always_r -columnspan 2 -sticky w
2253 grid columnconfigure $w.validate 1 -weight 1
2254 pack $w.validate -anchor nw -fill x -pady 5 -padx 5
2256 set delete_branch_head $current_branch
2257 set delete_branch_checktype head
2259 bind $w <Visibility> "grab $w; focus $w"
2260 bind $w <Key-Escape> "destroy $w"
2261 wm title $w "[appname] ([reponame]): Delete Branch"
2265 proc switch_branch {new_branch} {
2266 global HEAD commit_type current_branch repo_config
2268 if {![lock_index switch]} return
2270 # -- Our in memory state should match the repository.
2272 repository_state curType curHEAD curMERGE_HEAD
2273 if {[string match amend* $commit_type]
2274 && $curType eq {normal}
2275 && $curHEAD eq $HEAD} {
2276 } elseif {$commit_type ne $curType || $HEAD ne $curHEAD} {
2277 info_popup {Last scanned state does not match repository state.
2279 Another Git program has modified this repository
2280 since the last scan. A rescan must be performed
2281 before the current branch can be changed.
2283 The rescan will be automatically started now.
2286 rescan {set ui_status_value {Ready.}}
2290 # -- Don't do a pointless switch.
2292 if {$current_branch eq $new_branch} {
2297 if {$repo_config(gui.trustmtime) eq {true}} {
2298 switch_branch_stage2 {} $new_branch
2300 set ui_status_value {Refreshing file status...}
2301 set cmd [list git update-index]
2303 lappend cmd --unmerged
2304 lappend cmd --ignore-missing
2305 lappend cmd --refresh
2306 set fd_rf [open "| $cmd" r]
2307 fconfigure $fd_rf -blocking 0 -translation binary
2308 fileevent $fd_rf readable \
2309 [list switch_branch_stage2 $fd_rf $new_branch]
2313 proc switch_branch_stage2 {fd_rf new_branch} {
2314 global ui_status_value HEAD
2318 if {![eof $fd_rf]} return
2322 set ui_status_value "Updating working directory to '$new_branch'..."
2323 set cmd [list git read-tree]
2326 lappend cmd --exclude-per-directory=.gitignore
2328 lappend cmd $new_branch
2329 set fd_rt [open "| $cmd" r]
2330 fconfigure $fd_rt -blocking 0 -translation binary
2331 fileevent $fd_rt readable \
2332 [list switch_branch_readtree_wait $fd_rt $new_branch]
2335 proc switch_branch_readtree_wait {fd_rt new_branch} {
2336 global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
2337 global current_branch
2338 global ui_comm ui_status_value
2340 # -- We never get interesting output on stdout; only stderr.
2343 fconfigure $fd_rt -blocking 1
2344 if {![eof $fd_rt]} {
2345 fconfigure $fd_rt -blocking 0
2349 # -- The working directory wasn't in sync with the index and
2350 # we'd have to overwrite something to make the switch. A
2351 # merge is required.
2353 if {[catch {close $fd_rt} err]} {
2354 regsub {^fatal: } $err {} err
2355 warn_popup "File level merge required.
2359 Staying on branch '$current_branch'."
2360 set ui_status_value "Aborted checkout of '$new_branch' (file level merging is required)."
2365 # -- Update the symbolic ref. Core git doesn't even check for failure
2366 # here, it Just Works(tm). If it doesn't we are in some really ugly
2367 # state that is difficult to recover from within git-gui.
2369 if {[catch {exec git symbolic-ref HEAD "refs/heads/$new_branch"} err]} {
2370 error_popup "Failed to set current branch.
2372 This working directory is only partially switched.
2373 We successfully updated your files, but failed to
2374 update an internal Git file.
2376 This should not have occurred. [appname] will now
2384 # -- Update our repository state. If we were previously in amend mode
2385 # we need to toss the current buffer and do a full rescan to update
2386 # our file lists. If we weren't in amend mode our file lists are
2387 # accurate and we can avoid the rescan.
2390 set selected_commit_type new
2391 if {[string match amend* $commit_type]} {
2392 $ui_comm delete 0.0 end
2394 $ui_comm edit modified false
2395 rescan {set ui_status_value "Checked out branch '$current_branch'."}
2397 repository_state commit_type HEAD MERGE_HEAD
2399 set ui_status_value "Checked out branch '$current_branch'."
2403 ######################################################################
2405 ## remote management
2407 proc load_all_remotes {} {
2409 global all_remotes tracking_branches
2411 set all_remotes [list]
2412 array unset tracking_branches
2414 set rm_dir [gitdir remotes]
2415 if {[file isdirectory $rm_dir]} {
2416 set all_remotes [glob \
2420 -directory $rm_dir *]
2422 foreach name $all_remotes {
2424 set fd [open [file join $rm_dir $name] r]
2425 while {[gets $fd line] >= 0} {
2426 if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \
2427 $line line src dst]} continue
2428 if {![regexp ^refs/ $dst]} {
2429 set dst "refs/heads/$dst"
2431 set tracking_branches($dst) [list $name $src]
2438 foreach line [array names repo_config remote.*.url] {
2439 if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue
2440 lappend all_remotes $name
2442 if {[catch {set fl $repo_config(remote.$name.fetch)}]} {
2446 if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue
2447 if {![regexp ^refs/ $dst]} {
2448 set dst "refs/heads/$dst"
2450 set tracking_branches($dst) [list $name $src]
2454 set all_remotes [lsort -unique $all_remotes]
2457 proc populate_fetch_menu {} {
2458 global all_remotes repo_config
2461 foreach r $all_remotes {
2463 if {![catch {set a $repo_config(remote.$r.url)}]} {
2464 if {![catch {set a $repo_config(remote.$r.fetch)}]} {
2469 set fd [open [gitdir remotes $r] r]
2470 while {[gets $fd n] >= 0} {
2471 if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
2482 -label "Fetch from $r..." \
2483 -command [list fetch_from $r] \
2489 proc populate_push_menu {} {
2490 global all_remotes repo_config
2494 foreach r $all_remotes {
2496 if {![catch {set a $repo_config(remote.$r.url)}]} {
2497 if {![catch {set a $repo_config(remote.$r.push)}]} {
2502 set fd [open [gitdir remotes $r] r]
2503 while {[gets $fd n] >= 0} {
2504 if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
2518 -label "Push to $r..." \
2519 -command [list push_to $r] \
2526 proc start_push_anywhere_action {w} {
2527 global push_urltype push_remote push_url push_thin push_tags
2530 switch -- $push_urltype {
2531 remote {set r_url $push_remote}
2532 url {set r_url $push_url}
2534 if {$r_url eq {}} return
2536 set cmd [list git push]
2546 foreach i [$w.source.l curselection] {
2547 set b [$w.source.l get $i]
2548 lappend cmd "refs/heads/$b:refs/heads/$b"
2553 } elseif {$cnt == 1} {
2559 set cons [new_console "push $r_url" "Pushing $cnt $unit to $r_url"]
2560 console_exec $cons $cmd console_done
2564 trace add variable push_remote write \
2565 [list radio_selector push_urltype remote]
2567 proc do_push_anywhere {} {
2568 global all_heads all_remotes current_branch
2569 global push_urltype push_remote push_url push_thin push_tags
2573 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
2575 label $w.header -text {Push Branches} -font font_uibold
2576 pack $w.header -side top -fill x
2579 button $w.buttons.create -text Push \
2581 -command [list start_push_anywhere_action $w]
2582 pack $w.buttons.create -side right
2583 button $w.buttons.cancel -text {Cancel} \
2585 -command [list destroy $w]
2586 pack $w.buttons.cancel -side right -padx 5
2587 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
2589 labelframe $w.source \
2590 -text {Source Branches} \
2592 listbox $w.source.l \
2595 -selectmode extended \
2596 -yscrollcommand [list $w.source.sby set] \
2598 foreach h $all_heads {
2599 $w.source.l insert end $h
2600 if {$h eq $current_branch} {
2601 $w.source.l select set end
2604 scrollbar $w.source.sby -command [list $w.source.l yview]
2605 pack $w.source.sby -side right -fill y
2606 pack $w.source.l -side left -fill both -expand 1
2607 pack $w.source -fill both -expand 1 -pady 5 -padx 5
2609 labelframe $w.dest \
2610 -text {Destination Repository} \
2612 if {$all_remotes ne {}} {
2613 radiobutton $w.dest.remote_r \
2616 -variable push_urltype \
2618 eval tk_optionMenu $w.dest.remote_m push_remote $all_remotes
2619 grid $w.dest.remote_r $w.dest.remote_m -sticky w
2620 if {[lsearch -sorted -exact $all_remotes origin] != -1} {
2621 set push_remote origin
2623 set push_remote [lindex $all_remotes 0]
2625 set push_urltype remote
2627 set push_urltype url
2629 radiobutton $w.dest.url_r \
2630 -text {Arbitrary URL:} \
2632 -variable push_urltype \
2634 entry $w.dest.url_t \
2638 -textvariable push_url \
2642 if {%d == 1 && [regexp {\s} %S]} {return 0}
2643 if {%d == 1 && [string length %S] > 0} {
2644 set push_urltype url
2648 grid $w.dest.url_r $w.dest.url_t -sticky we -padx {0 5}
2649 grid columnconfigure $w.dest 1 -weight 1
2650 pack $w.dest -anchor nw -fill x -pady 5 -padx 5
2652 labelframe $w.options \
2653 -text {Transfer Options} \
2655 checkbutton $w.options.thin \
2656 -text {Use thin pack (for slow network connections)} \
2657 -variable push_thin \
2659 grid $w.options.thin -columnspan 2 -sticky w
2660 checkbutton $w.options.tags \
2661 -text {Include tags} \
2662 -variable push_tags \
2664 grid $w.options.tags -columnspan 2 -sticky w
2665 grid columnconfigure $w.options 1 -weight 1
2666 pack $w.options -anchor nw -fill x -pady 5 -padx 5
2672 bind $w <Visibility> "grab $w"
2673 bind $w <Key-Escape> "destroy $w"
2674 wm title $w "[appname] ([reponame]): Push"
2678 ######################################################################
2683 global HEAD commit_type file_states
2685 if {[string match amend* $commit_type]} {
2686 info_popup {Cannot merge while amending.
2688 You must finish amending this commit before
2689 starting any type of merge.
2694 if {[committer_ident] eq {}} {return 0}
2695 if {![lock_index merge]} {return 0}
2697 # -- Our in memory state should match the repository.
2699 repository_state curType curHEAD curMERGE_HEAD
2700 if {$commit_type ne $curType || $HEAD ne $curHEAD} {
2701 info_popup {Last scanned state does not match repository state.
2703 Another Git program has modified this repository
2704 since the last scan. A rescan must be performed
2705 before a merge can be performed.
2707 The rescan will be automatically started now.
2710 rescan {set ui_status_value {Ready.}}
2714 foreach path [array names file_states] {
2715 switch -glob -- [lindex $file_states($path) 0] {
2717 continue; # and pray it works!
2720 error_popup "You are in the middle of a conflicted merge.
2722 File [short_path $path] has merge conflicts.
2724 You must resolve them, add the file, and commit to
2725 complete the current merge. Only then can you
2726 begin another merge.
2732 error_popup "You are in the middle of a change.
2734 File [short_path $path] is modified.
2736 You should complete the current commit before
2737 starting a merge. Doing so will help you abort
2738 a failed merge, should the need arise.
2749 proc visualize_local_merge {w} {
2751 foreach i [$w.source.l curselection] {
2752 lappend revs [$w.source.l get $i]
2754 if {$revs eq {}} return
2755 lappend revs --not HEAD
2759 proc start_local_merge_action {w} {
2760 global HEAD ui_status_value current_branch
2762 set cmd [list git merge]
2765 foreach i [$w.source.l curselection] {
2766 set b [$w.source.l get $i]
2774 } elseif {$revcnt == 1} {
2776 } elseif {$revcnt <= 15} {
2782 -title [wm title $w] \
2784 -message "Too many branches selected.
2786 You have requested to merge $revcnt branches
2787 in an octopus merge. This exceeds Git's
2788 internal limit of 15 branches per merge.
2790 Please select fewer branches. To merge more
2791 than 15 branches, merge the branches in batches.
2796 set msg "Merging $current_branch, [join $names {, }]"
2797 set ui_status_value "$msg..."
2798 set cons [new_console "Merge" $msg]
2799 console_exec $cons $cmd [list finish_merge $revcnt]
2800 bind $w <Destroy> {}
2804 proc finish_merge {revcnt w ok} {
2807 set msg {Merge completed successfully.}
2810 info_popup "Octopus merge failed.
2812 Your merge of $revcnt branches has failed.
2814 There are file-level conflicts between the
2815 branches which must be resolved manually.
2817 The working directory will now be reset.
2819 You can attempt this merge again
2820 by merging only one branch at a time." $w
2822 set fd [open "| git read-tree --reset -u HEAD" r]
2823 fconfigure $fd -blocking 0 -translation binary
2824 fileevent $fd readable [list reset_hard_wait $fd]
2825 set ui_status_value {Aborting... please wait...}
2829 set msg {Merge failed. Conflict resolution is required.}
2832 rescan [list set ui_status_value $msg]
2835 proc do_local_merge {} {
2836 global current_branch
2838 if {![can_merge]} return
2842 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
2845 -text "Merge Into $current_branch" \
2847 pack $w.header -side top -fill x
2850 button $w.buttons.visualize -text Visualize \
2852 -command [list visualize_local_merge $w]
2853 pack $w.buttons.visualize -side left
2854 button $w.buttons.create -text Merge \
2856 -command [list start_local_merge_action $w]
2857 pack $w.buttons.create -side right
2858 button $w.buttons.cancel -text {Cancel} \
2860 -command [list destroy $w]
2861 pack $w.buttons.cancel -side right -padx 5
2862 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
2864 labelframe $w.source \
2865 -text {Source Branches} \
2867 listbox $w.source.l \
2870 -selectmode extended \
2871 -yscrollcommand [list $w.source.sby set] \
2873 scrollbar $w.source.sby -command [list $w.source.l yview]
2874 pack $w.source.sby -side right -fill y
2875 pack $w.source.l -side left -fill both -expand 1
2876 pack $w.source -fill both -expand 1 -pady 5 -padx 5
2878 set cmd [list git for-each-ref]
2879 lappend cmd {--format=%(objectname) %(refname)}
2880 lappend cmd refs/heads
2881 lappend cmd refs/remotes
2882 set fr_fd [open "| $cmd" r]
2883 fconfigure $fr_fd -translation binary
2884 while {[gets $fr_fd line] > 0} {
2885 set line [split $line { }]
2886 set sha1([lindex $line 0]) [lindex $line 1]
2891 set fr_fd [open "| git rev-list --all --not HEAD"]
2892 while {[gets $fr_fd line] > 0} {
2893 if {[catch {set ref $sha1($line)}]} continue
2894 regsub ^refs/(heads|remotes)/ $ref {} ref
2895 lappend to_show $ref
2899 foreach ref [lsort -unique $to_show] {
2900 $w.source.l insert end $ref
2903 bind $w <Visibility> "grab $w"
2904 bind $w <Key-Escape> "unlock_index;destroy $w"
2905 bind $w <Destroy> unlock_index
2906 wm title $w "[appname] ([reponame]): Merge"
2910 proc do_reset_hard {} {
2911 global HEAD commit_type file_states
2913 if {[string match amend* $commit_type]} {
2914 info_popup {Cannot abort while amending.
2916 You must finish amending this commit.
2921 if {![lock_index abort]} return
2923 if {[string match *merge* $commit_type]} {
2929 if {[ask_popup "Abort $op?
2931 Aborting the current $op will cause
2932 *ALL* uncommitted changes to be lost.
2934 Continue with aborting the current $op?"] eq {yes}} {
2935 set fd [open "| git read-tree --reset -u HEAD" r]
2936 fconfigure $fd -blocking 0 -translation binary
2937 fileevent $fd readable [list reset_hard_wait $fd]
2938 set ui_status_value {Aborting... please wait...}
2944 proc reset_hard_wait {fd} {
2952 $ui_comm delete 0.0 end
2953 $ui_comm edit modified false
2955 catch {file delete [gitdir MERGE_HEAD]}
2956 catch {file delete [gitdir rr-cache MERGE_RR]}
2957 catch {file delete [gitdir SQUASH_MSG]}
2958 catch {file delete [gitdir MERGE_MSG]}
2959 catch {file delete [gitdir GITGUI_MSG]}
2961 rescan {set ui_status_value {Abort completed. Ready.}}
2965 ######################################################################
2969 set next_browser_id 0
2971 proc new_browser {commit} {
2972 global next_browser_id cursor_ptr M1B
2973 global browser_commit browser_status browser_stack browser_path browser_busy
2975 set w .browser[incr next_browser_id]
2976 set w_list $w.list.l
2977 set browser_commit($w_list) $commit
2978 set browser_status($w_list) {Starting...}
2979 set browser_stack($w_list) {}
2980 set browser_path($w_list) $browser_commit($w_list):
2981 set browser_busy($w_list) 1
2984 label $w.path -textvariable browser_path($w_list) \
2990 pack $w.path -anchor w -side top -fill x
2993 text $w_list -background white -borderwidth 0 \
2994 -cursor $cursor_ptr \
2999 -xscrollcommand [list $w.list.sbx set] \
3000 -yscrollcommand [list $w.list.sby set] \
3002 $w_list tag conf in_sel \
3003 -background [$w_list cget -foreground] \
3004 -foreground [$w_list cget -background]
3005 scrollbar $w.list.sbx -orient h -command [list $w_list xview]
3006 scrollbar $w.list.sby -orient v -command [list $w_list yview]
3007 pack $w.list.sbx -side bottom -fill x
3008 pack $w.list.sby -side right -fill y
3009 pack $w_list -side left -fill both -expand 1
3010 pack $w.list -side top -fill both -expand 1
3012 label $w.status -textvariable browser_status($w_list) \
3018 pack $w.status -anchor w -side bottom -fill x
3020 bind $w_list <Button-1> "browser_click 0 $w_list @%x,%y;break"
3021 bind $w_list <Double-Button-1> "browser_click 1 $w_list @%x,%y;break"
3022 bind $w_list <$M1B-Up> "browser_parent $w_list;break"
3023 bind $w_list <$M1B-Left> "browser_parent $w_list;break"
3024 bind $w_list <Up> "browser_move -1 $w_list;break"
3025 bind $w_list <Down> "browser_move 1 $w_list;break"
3026 bind $w_list <$M1B-Right> "browser_enter $w_list;break"
3027 bind $w_list <Return> "browser_enter $w_list;break"
3028 bind $w_list <Prior> "browser_page -1 $w_list;break"
3029 bind $w_list <Next> "browser_page 1 $w_list;break"
3030 bind $w_list <Left> break
3031 bind $w_list <Right> break
3033 bind $w <Visibility> "focus $w"
3035 array unset browser_buffer $w_list
3036 array unset browser_files $w_list
3037 array unset browser_status $w_list
3038 array unset browser_stack $w_list
3039 array unset browser_path $w_list
3040 array unset browser_commit $w_list
3041 array unset browser_busy $w_list
3043 wm title $w "[appname] ([reponame]): File Browser"
3044 ls_tree $w_list $browser_commit($w_list) {}
3047 proc browser_move {dir w} {
3048 global browser_files browser_busy
3050 if {$browser_busy($w)} return
3051 set lno [lindex [split [$w index in_sel.first] .] 0]
3053 if {[lindex $browser_files($w) [expr {$lno - 1}]] ne {}} {
3054 $w tag remove in_sel 0.0 end
3055 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3060 proc browser_page {dir w} {
3061 global browser_files browser_busy
3063 if {$browser_busy($w)} return
3064 $w yview scroll $dir pages
3066 [lindex [$w yview] 0]
3067 * [llength $browser_files($w)]
3069 if {[lindex $browser_files($w) [expr {$lno - 1}]] ne {}} {
3070 $w tag remove in_sel 0.0 end
3071 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3076 proc browser_parent {w} {
3077 global browser_files browser_status browser_path
3078 global browser_stack browser_busy
3080 if {$browser_busy($w)} return
3081 set info [lindex $browser_files($w) 0]
3082 if {[lindex $info 0] eq {parent}} {
3083 set parent [lindex $browser_stack($w) end-1]
3084 set browser_stack($w) [lrange $browser_stack($w) 0 end-2]
3085 if {$browser_stack($w) eq {}} {
3086 regsub {:.*$} $browser_path($w) {:} browser_path($w)
3088 regsub {/[^/]+$} $browser_path($w) {} browser_path($w)
3090 set browser_status($w) "Loading $browser_path($w)..."
3091 ls_tree $w [lindex $parent 0] [lindex $parent 1]
3095 proc browser_enter {w} {
3096 global browser_files browser_status browser_path
3097 global browser_commit browser_stack browser_busy
3099 if {$browser_busy($w)} return
3100 set lno [lindex [split [$w index in_sel.first] .] 0]
3101 set info [lindex $browser_files($w) [expr {$lno - 1}]]
3103 switch -- [lindex $info 0] {
3108 set name [lindex $info 2]
3109 set escn [escape_path $name]
3110 set browser_status($w) "Loading $escn..."
3111 append browser_path($w) $escn
3112 ls_tree $w [lindex $info 1] $name
3115 set name [lindex $info 2]
3117 foreach n $browser_stack($w) {
3118 append p [lindex $n 1]
3121 show_blame $browser_commit($w) $p
3127 proc browser_click {was_double_click w pos} {
3128 global browser_files browser_busy
3130 if {$browser_busy($w)} return
3131 set lno [lindex [split [$w index $pos] .] 0]
3134 if {[lindex $browser_files($w) [expr {$lno - 1}]] ne {}} {
3135 $w tag remove in_sel 0.0 end
3136 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3137 if {$was_double_click} {
3143 proc ls_tree {w tree_id name} {
3144 global browser_buffer browser_files browser_stack browser_busy
3146 set browser_buffer($w) {}
3147 set browser_files($w) {}
3148 set browser_busy($w) 1
3150 $w conf -state normal
3151 $w tag remove in_sel 0.0 end
3153 if {$browser_stack($w) ne {}} {
3154 $w image create end \
3155 -align center -padx 5 -pady 1 \
3158 $w insert end {[Up To Parent]}
3159 lappend browser_files($w) parent
3161 lappend browser_stack($w) [list $tree_id $name]
3162 $w conf -state disabled
3164 set cmd [list git ls-tree -z $tree_id]
3165 set fd [open "| $cmd" r]
3166 fconfigure $fd -blocking 0 -translation binary -encoding binary
3167 fileevent $fd readable [list read_ls_tree $fd $w]
3170 proc read_ls_tree {fd w} {
3171 global browser_buffer browser_files browser_status browser_busy
3173 if {![winfo exists $w]} {
3178 append browser_buffer($w) [read $fd]
3179 set pck [split $browser_buffer($w) "\0"]
3180 set browser_buffer($w) [lindex $pck end]
3182 set n [llength $browser_files($w)]
3183 $w conf -state normal
3184 foreach p [lrange $pck 0 end-1] {
3185 set info [split $p "\t"]
3186 set path [lindex $info 1]
3187 set info [split [lindex $info 0] { }]
3188 set type [lindex $info 1]
3189 set object [lindex $info 2]
3200 set image file_question
3204 if {$n > 0} {$w insert end "\n"}
3205 $w image create end \
3206 -align center -padx 5 -pady 1 \
3207 -name icon[incr n] \
3209 $w insert end [escape_path $path]
3210 lappend browser_files($w) [list $type $object $path]
3212 $w conf -state disabled
3216 set browser_status($w) Ready.
3217 set browser_busy($w) 0
3218 array unset browser_buffer $w
3220 $w tag add in_sel 1.0 2.0
3226 proc show_blame {commit path} {
3227 global next_browser_id blame_status blame_data
3229 if {[winfo ismapped .]} {
3230 set w .browser[incr next_browser_id]
3237 set blame_status($w) {Loading current file content...}
3239 label $w.path -text "$commit:$path" \
3245 pack $w.path -side top -fill x
3248 text $w.out.linenumber_t \
3249 -background white -borderwidth 0 \
3255 $w.out.linenumber_t tag conf annotated -background grey
3256 $w.out.linenumber_t tag conf linenumber -justify right
3258 text $w.out.file_t \
3259 -background white -borderwidth 0 \
3264 -xscrollcommand [list $w.out.sbx set] \
3267 scrollbar $w.out.sbx -orient h -command [list $w.out.file_t xview]
3268 scrollbar $w.out.sby -orient v \
3269 -command [list scrollbar2many [list \
3270 $w.out.linenumber_t \
3273 grid $w.out.linenumber_t $w.out.file_t $w.out.sby -sticky nsew
3274 grid conf $w.out.sbx -column 1 -sticky we
3275 grid columnconfigure $w.out 1 -weight 1
3276 grid rowconfigure $w.out 0 -weight 1
3277 pack $w.out -fill both -expand 1
3279 label $w.status -textvariable blame_status($w) \
3285 pack $w.status -side bottom -fill x
3289 -background white -borderwidth 0 \
3294 -xscrollcommand [list $w.cm.sbx set] \
3295 -yscrollcommand [list $w.cm.sby set] \
3297 scrollbar $w.cm.sbx -orient h -command [list $w.cm.t xview]
3298 scrollbar $w.cm.sby -orient v -command [list $w.cm.t yview]
3299 pack $w.cm.sby -side right -fill y
3300 pack $w.cm.sbx -side bottom -fill x
3301 pack $w.cm.t -expand 1 -fill both
3302 pack $w.cm -side bottom -fill x
3304 menu $w.ctxm -tearoff 0
3305 $w.ctxm add command -label "Copy Commit" \
3307 -command "blame_copycommit $w \$cursorW @\$cursorX,\$cursorY"
3309 foreach i [list $w.out.linenumber_t $w.out.file_t] {
3310 $i tag conf in_sel \
3311 -background [$i cget -foreground] \
3312 -foreground [$i cget -background]
3313 $i conf -yscrollcommand \
3314 [list many2scrollbar [list \
3315 $w.out.linenumber_t \
3318 bind $i <Button-1> "
3319 blame_highlight {$w} \\
3321 $w.out.linenumber_t \\
3330 tk_popup $w.ctxm %X %Y
3334 bind $tl <Visibility> "focus $tl"
3335 bind $tl <Destroy> "
3336 array unset blame_status {$w}
3337 array unset blame_data $w,*
3339 wm title $tl "[appname] ([reponame]): File Viewer"
3341 set blame_data($w,total_lines) 0
3342 set blame_data($w,blame_lines) 0
3343 set blame_data($w,highlight_commit) {}
3344 set blame_data($w,highlight_line) -1
3345 set cmd [list git cat-file blob "$commit:$path"]
3346 set fd [open "| $cmd" r]
3347 fconfigure $fd -blocking 0 -translation lf -encoding binary
3348 fileevent $fd readable [list read_blame_catfile \
3349 $fd $w $commit $path \
3350 $w.cm.t $w.out.linenumber_t $w.out.file_t]
3353 proc read_blame_catfile {fd w commit path w_cmit w_line w_file} {
3354 global blame_status blame_data
3356 if {![winfo exists $w_file]} {
3361 set n $blame_data($w,total_lines)
3362 $w_line conf -state normal
3363 $w_file conf -state normal
3364 while {[gets $fd line] >= 0} {
3365 regsub "\r\$" $line {} line
3367 $w_line insert end "$n\n" linenumber
3368 $w_file insert end "$line\n"
3370 $w_line conf -state disabled
3371 $w_file conf -state disabled
3372 set blame_data($w,total_lines) $n
3376 blame_incremental_status $w
3377 set cmd [list git blame -M -C --incremental]
3378 lappend cmd $commit -- $path
3379 set fd [open "| $cmd" r]
3380 fconfigure $fd -blocking 0 -translation lf -encoding binary
3381 fileevent $fd readable [list read_blame_incremental $fd $w \
3382 $w_cmit $w_line $w_file]
3386 proc read_blame_incremental {fd w w_cmit w_line w_file} {
3387 global blame_status blame_data
3389 if {![winfo exists $w_file]} {
3394 while {[gets $fd line] >= 0} {
3395 if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
3396 cmit original_line final_line line_count]} {
3397 set blame_data($w,commit) $cmit
3398 set blame_data($w,original_line) $original_line
3399 set blame_data($w,final_line) $final_line
3400 set blame_data($w,line_count) $line_count
3402 if {[catch {set g $blame_data($w,$cmit,seen)}]} {
3403 $w_line tag conf g$cmit
3404 $w_file tag conf g$cmit
3405 $w_line tag raise in_sel
3406 $w_file tag raise in_sel
3407 set blame_data($w,$cmit,seen) 1
3409 } elseif {[string match {filename *} $line]} {
3410 set file [string range $line 9 end]
3411 set n $blame_data($w,line_count)
3412 set lno $blame_data($w,final_line)
3413 set cmit $blame_data($w,commit)
3416 if {[catch {set g g$blame_data($w,line$lno,commit)}]} {
3417 $w_line tag add annotated $lno.0 "$lno.0 lineend + 1c"
3419 $w_line tag remove g$g $lno.0 "$lno.0 lineend + 1c"
3420 $w_file tag remove g$g $lno.0 "$lno.0 lineend + 1c"
3423 set blame_data($w,line$lno,commit) $cmit
3424 set blame_data($w,line$lno,file) $file
3425 $w_line tag add g$cmit $lno.0 "$lno.0 lineend + 1c"
3426 $w_file tag add g$cmit $lno.0 "$lno.0 lineend + 1c"
3428 if {$blame_data($w,highlight_line) == -1} {
3429 if {[lindex [$w_file yview] 0] == 0} {
3431 blame_showcommit $w $w_cmit $w_line $w_file $lno
3433 } elseif {$blame_data($w,highlight_line) == $lno} {
3434 blame_showcommit $w $w_cmit $w_line $w_file $lno
3439 incr blame_data($w,blame_lines)
3441 } elseif {[regexp {^([a-z-]+) (.*)$} $line line header data]} {
3442 set blame_data($w,$blame_data($w,commit),$header) $data
3448 set blame_status($w) {Annotation complete.}
3450 blame_incremental_status $w
3454 proc blame_incremental_status {w} {
3455 global blame_status blame_data
3457 set blame_status($w) [format \
3458 "Loading annotations... %i of %i lines annotated (%2i%%)" \
3459 $blame_data($w,blame_lines) \
3460 $blame_data($w,total_lines) \
3461 [expr {100 * $blame_data($w,blame_lines)
3462 / $blame_data($w,total_lines)}]]
3465 proc blame_highlight {w w_cmit w_line w_file cur_w pos} {
3466 set lno [lindex [split [$cur_w index $pos] .] 0]
3467 if {$lno eq {}} return
3469 $w_line tag remove in_sel 0.0 end
3470 $w_file tag remove in_sel 0.0 end
3471 $w_line tag add in_sel $lno.0 "$lno.0 + 1 line"
3472 $w_file tag add in_sel $lno.0 "$lno.0 + 1 line"
3474 blame_showcommit $w $w_cmit $w_line $w_file $lno
3477 proc blame_showcommit {w w_cmit w_line w_file lno} {
3478 global blame_data repo_config
3480 set cmit $blame_data($w,highlight_commit)
3482 $w_line tag conf g$cmit -background white
3483 $w_file tag conf g$cmit -background white
3484 $w_line tag raise annotated g$cmit
3487 $w_cmit conf -state normal
3488 $w_cmit delete 0.0 end
3489 if {[catch {set cmit $blame_data($w,line$lno,commit)}]} {
3491 $w_cmit insert end "Computing..."
3493 $w_line tag conf g$cmit -background yellow
3494 $w_file tag conf g$cmit -background yellow
3495 $w_line tag raise g$cmit annotated
3497 if {[catch {set msg $blame_data($w,$cmit,message)}]} {
3500 set fd [open "| git cat-file commit $cmit" r]
3501 fconfigure $fd -encoding binary -translation lf
3502 if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
3505 while {[gets $fd line] > 0} {
3506 if {[string match {encoding *} $line]} {
3507 set enc [string tolower [string range $line 9 end]]
3510 fconfigure $fd -encoding $enc
3511 set msg [string trim [read $fd]]
3514 set blame_data($w,$cmit,message) $msg
3520 catch {set author_name $blame_data($w,$cmit,author)}
3521 catch {set author_email $blame_data($w,$cmit,author-mail)}
3522 catch {set author_time [clock format $blame_data($w,$cmit,author-time)]}
3524 set committer_name {}
3525 set committer_email {}
3526 set committer_time {}
3527 catch {set committer_name $blame_data($w,$cmit,committer)}
3528 catch {set committer_email $blame_data($w,$cmit,committer-mail)}
3529 catch {set committer_time [clock format $blame_data($w,$cmit,committer-time)]}
3531 $w_cmit insert end "commit $cmit\n"
3532 $w_cmit insert end "Author: $author_name $author_email $author_time\n"
3533 $w_cmit insert end "Committer: $committer_name $committer_email $committer_time\n"
3534 $w_cmit insert end "Original File: [escape_path $blame_data($w,line$lno,file)]\n"
3535 $w_cmit insert end "\n"
3536 $w_cmit insert end $msg
3538 $w_cmit conf -state disabled
3540 set blame_data($w,highlight_line) $lno
3541 set blame_data($w,highlight_commit) $cmit
3544 proc blame_copycommit {w i pos} {
3546 set lno [lindex [split [$i index $pos] .] 0]
3547 if {![catch {set commit $blame_data($w,line$lno,commit)}]} {
3556 ######################################################################
3561 #define mask_width 14
3562 #define mask_height 15
3563 static unsigned char mask_bits[] = {
3564 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3565 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3566 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
3569 image create bitmap file_plain -background white -foreground black -data {
3570 #define plain_width 14
3571 #define plain_height 15
3572 static unsigned char plain_bits[] = {
3573 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3574 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
3575 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3576 } -maskdata $filemask
3578 image create bitmap file_mod -background white -foreground blue -data {
3579 #define mod_width 14
3580 #define mod_height 15
3581 static unsigned char mod_bits[] = {
3582 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3583 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3584 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3585 } -maskdata $filemask
3587 image create bitmap file_fulltick -background white -foreground "#007000" -data {
3588 #define file_fulltick_width 14
3589 #define file_fulltick_height 15
3590 static unsigned char file_fulltick_bits[] = {
3591 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
3592 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
3593 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3594 } -maskdata $filemask
3596 image create bitmap file_parttick -background white -foreground "#005050" -data {
3597 #define parttick_width 14
3598 #define parttick_height 15
3599 static unsigned char parttick_bits[] = {
3600 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3601 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
3602 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3603 } -maskdata $filemask
3605 image create bitmap file_question -background white -foreground black -data {
3606 #define file_question_width 14
3607 #define file_question_height 15
3608 static unsigned char file_question_bits[] = {
3609 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
3610 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
3611 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3612 } -maskdata $filemask
3614 image create bitmap file_removed -background white -foreground red -data {
3615 #define file_removed_width 14
3616 #define file_removed_height 15
3617 static unsigned char file_removed_bits[] = {
3618 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3619 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
3620 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
3621 } -maskdata $filemask
3623 image create bitmap file_merge -background white -foreground blue -data {
3624 #define file_merge_width 14
3625 #define file_merge_height 15
3626 static unsigned char file_merge_bits[] = {
3627 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
3628 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3629 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3630 } -maskdata $filemask
3633 #define file_width 18
3634 #define file_height 18
3635 static unsigned char file_bits[] = {
3636 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00,
3637 0x0c, 0x03, 0x00, 0x04, 0xfe, 0x00, 0x06, 0x80, 0x00, 0xff, 0x9f, 0x00,
3638 0x03, 0x98, 0x00, 0x02, 0x90, 0x00, 0x06, 0xb0, 0x00, 0x04, 0xa0, 0x00,
3639 0x0c, 0xe0, 0x00, 0x08, 0xc0, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
3640 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3642 image create bitmap file_dir -background white -foreground blue \
3643 -data $file_dir_data -maskdata $file_dir_data
3646 set file_uplevel_data {
3648 #define up_height 15
3649 static unsigned char up_bits[] = {
3650 0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f,
3651 0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
3652 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
3654 image create bitmap file_uplevel -background white -foreground red \
3655 -data $file_uplevel_data -maskdata $file_uplevel_data
3656 unset file_uplevel_data
3658 set ui_index .vpane.files.index.list
3659 set ui_workdir .vpane.files.workdir.list
3661 set all_icons(_$ui_index) file_plain
3662 set all_icons(A$ui_index) file_fulltick
3663 set all_icons(M$ui_index) file_fulltick
3664 set all_icons(D$ui_index) file_removed
3665 set all_icons(U$ui_index) file_merge
3667 set all_icons(_$ui_workdir) file_plain
3668 set all_icons(M$ui_workdir) file_mod
3669 set all_icons(D$ui_workdir) file_question
3670 set all_icons(U$ui_workdir) file_merge
3671 set all_icons(O$ui_workdir) file_plain
3673 set max_status_desc 0
3677 {_M "Modified, not staged"}
3678 {M_ "Staged for commit"}
3679 {MM "Portions staged for commit"}
3680 {MD "Staged for commit, missing"}
3682 {_O "Untracked, not staged"}
3683 {A_ "Staged for commit"}
3684 {AM "Portions staged for commit"}
3685 {AD "Staged for commit, missing"}
3688 {D_ "Staged for removal"}
3689 {DO "Staged for removal, still present"}
3691 {U_ "Requires merge resolution"}
3692 {UU "Requires merge resolution"}
3693 {UM "Requires merge resolution"}
3694 {UD "Requires merge resolution"}
3696 if {$max_status_desc < [string length [lindex $i 1]]} {
3697 set max_status_desc [string length [lindex $i 1]]
3699 set all_descs([lindex $i 0]) [lindex $i 1]
3703 ######################################################################
3707 proc bind_button3 {w cmd} {
3708 bind $w <Any-Button-3> $cmd
3710 bind $w <Control-Button-1> $cmd
3714 proc scrollbar2many {list mode args} {
3715 foreach w $list {eval $w $mode $args}
3718 proc many2scrollbar {list mode sb top bottom} {
3719 $sb set $top $bottom
3720 foreach w $list {$w $mode moveto $top}
3723 proc incr_font_size {font {amt 1}} {
3724 set sz [font configure $font -size]
3726 font configure $font -size $sz
3727 font configure ${font}bold -size $sz
3730 proc hook_failed_popup {hook msg} {
3735 label $w.m.l1 -text "$hook hook failed:" \
3740 -background white -borderwidth 1 \
3742 -width 80 -height 10 \
3744 -yscrollcommand [list $w.m.sby set]
3746 -text {You must correct the above errors before committing.} \
3750 scrollbar $w.m.sby -command [list $w.m.t yview]
3751 pack $w.m.l1 -side top -fill x
3752 pack $w.m.l2 -side bottom -fill x
3753 pack $w.m.sby -side right -fill y
3754 pack $w.m.t -side left -fill both -expand 1
3755 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
3757 $w.m.t insert 1.0 $msg
3758 $w.m.t conf -state disabled
3760 button $w.ok -text OK \
3763 -command "destroy $w"
3764 pack $w.ok -side bottom -anchor e -pady 10 -padx 10
3766 bind $w <Visibility> "grab $w; focus $w"
3767 bind $w <Key-Return> "destroy $w"
3768 wm title $w "[appname] ([reponame]): error"
3772 set next_console_id 0
3774 proc new_console {short_title long_title} {
3775 global next_console_id console_data
3776 set w .console[incr next_console_id]
3777 set console_data($w) [list $short_title $long_title]
3778 return [console_init $w]
3781 proc console_init {w} {
3782 global console_cr console_data M1B
3784 set console_cr($w) 1.0
3787 label $w.m.l1 -text "[lindex $console_data($w) 1]:" \
3792 -background white -borderwidth 1 \
3794 -width 80 -height 10 \
3797 -yscrollcommand [list $w.m.sby set]
3798 label $w.m.s -text {Working... please wait...} \
3802 scrollbar $w.m.sby -command [list $w.m.t yview]
3803 pack $w.m.l1 -side top -fill x
3804 pack $w.m.s -side bottom -fill x
3805 pack $w.m.sby -side right -fill y
3806 pack $w.m.t -side left -fill both -expand 1
3807 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
3809 menu $w.ctxm -tearoff 0
3810 $w.ctxm add command -label "Copy" \
3812 -command "tk_textCopy $w.m.t"
3813 $w.ctxm add command -label "Select All" \
3815 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
3816 $w.ctxm add command -label "Copy All" \
3819 $w.m.t tag add sel 0.0 end
3821 $w.m.t tag remove sel 0.0 end
3824 button $w.ok -text {Close} \
3827 -command "destroy $w"
3828 pack $w.ok -side bottom -anchor e -pady 10 -padx 10
3830 bind_button3 $w.m.t "tk_popup $w.ctxm %X %Y"
3831 bind $w.m.t <$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
3832 bind $w.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
3833 bind $w <Visibility> "focus $w"
3834 wm title $w "[appname] ([reponame]): [lindex $console_data($w) 0]"
3838 proc console_exec {w cmd after} {
3839 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
3840 # But most users need that so we have to relogin. :-(
3843 set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"]
3846 # -- Tcl won't let us redirect both stdout and stderr to
3847 # the same pipe. So pass it through cat...
3849 set cmd [concat | $cmd |& cat]
3851 set fd_f [open $cmd r]
3852 fconfigure $fd_f -blocking 0 -translation binary
3853 fileevent $fd_f readable [list console_read $w $fd_f $after]
3856 proc console_read {w fd after} {
3861 if {![winfo exists $w]} {console_init $w}
3862 $w.m.t conf -state normal
3864 set n [string length $buf]
3866 set cr [string first "\r" $buf $c]
3867 set lf [string first "\n" $buf $c]
3868 if {$cr < 0} {set cr [expr {$n + 1}]}
3869 if {$lf < 0} {set lf [expr {$n + 1}]}
3872 $w.m.t insert end [string range $buf $c $lf]
3873 set console_cr($w) [$w.m.t index {end -1c}]
3877 $w.m.t delete $console_cr($w) end
3878 $w.m.t insert end "\n"
3879 $w.m.t insert end [string range $buf $c $cr]
3884 $w.m.t conf -state disabled
3888 fconfigure $fd -blocking 1
3890 if {[catch {close $fd}]} {
3895 uplevel #0 $after $w $ok
3898 fconfigure $fd -blocking 0
3901 proc console_chain {cmdlist w {ok 1}} {
3903 if {[llength $cmdlist] == 0} {
3908 set cmd [lindex $cmdlist 0]
3909 set cmdlist [lrange $cmdlist 1 end]
3911 if {[lindex $cmd 0] eq {console_exec}} {
3914 [list console_chain $cmdlist]
3916 uplevel #0 $cmd $cmdlist $w $ok
3923 proc console_done {args} {
3924 global console_cr console_data
3926 switch -- [llength $args] {
3928 set w [lindex $args 0]
3929 set ok [lindex $args 1]
3932 set w [lindex $args 1]
3933 set ok [lindex $args 2]
3936 error "wrong number of args: console_done ?ignored? w ok"
3941 if {[winfo exists $w]} {
3942 $w.m.s conf -background green -text {Success}
3943 $w.ok conf -state normal
3946 if {![winfo exists $w]} {
3949 $w.m.s conf -background red -text {Error: Command Failed}
3950 $w.ok conf -state normal
3953 array unset console_cr $w
3954 array unset console_data $w
3957 ######################################################################
3961 set starting_gitk_msg {Starting gitk... please wait...}
3963 proc do_gitk {revs} {
3964 global env ui_status_value starting_gitk_msg
3966 # -- On Windows gitk is severly broken, and right now it seems like
3967 # nobody cares about fixing it. The only known workaround is to
3968 # always delete ~/.gitk before starting the program.
3971 catch {file delete [file join $env(HOME) .gitk]}
3974 # -- Always start gitk through whatever we were loaded with. This
3975 # lets us bypass using shell process on Windows systems.
3977 set cmd [info nameofexecutable]
3978 lappend cmd [gitexec gitk]
3984 if {[catch {eval exec $cmd &} err]} {
3985 error_popup "Failed to start gitk:\n\n$err"
3987 set ui_status_value $starting_gitk_msg
3989 if {$ui_status_value eq $starting_gitk_msg} {
3990 set ui_status_value {Ready.}
3997 set fd [open "| git count-objects -v" r]
3998 while {[gets $fd line] > 0} {
3999 if {[regexp {^([^:]+): (\d+)$} $line _ name value]} {
4000 set stats($name) $value
4006 foreach p [glob -directory [gitdir objects pack] \
4009 incr packed_sz [file size $p]
4011 if {$packed_sz > 0} {
4012 set stats(size-pack) [expr {$packed_sz / 1024}]
4017 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
4019 label $w.header -text {Database Statistics} \
4021 pack $w.header -side top -fill x
4023 frame $w.buttons -border 1
4024 button $w.buttons.close -text Close \
4026 -command [list destroy $w]
4027 button $w.buttons.gc -text {Compress Database} \
4029 -command "destroy $w;do_gc"
4030 pack $w.buttons.close -side right
4031 pack $w.buttons.gc -side left
4032 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
4034 frame $w.stat -borderwidth 1 -relief solid
4036 {count {Number of loose objects}}
4037 {size {Disk space used by loose objects} { KiB}}
4038 {in-pack {Number of packed objects}}
4039 {packs {Number of packs}}
4040 {size-pack {Disk space used by packed objects} { KiB}}
4041 {prune-packable {Packed objects waiting for pruning}}
4042 {garbage {Garbage files}}
4044 set name [lindex $s 0]
4045 set label [lindex $s 1]
4046 if {[catch {set value $stats($name)}]} continue
4047 if {[llength $s] > 2} {
4048 set value "$value[lindex $s 2]"
4051 label $w.stat.l_$name -text "$label:" -anchor w -font font_ui
4052 label $w.stat.v_$name -text $value -anchor w -font font_ui
4053 grid $w.stat.l_$name $w.stat.v_$name -sticky we -padx {0 5}
4055 pack $w.stat -pady 10 -padx 10
4057 bind $w <Visibility> "grab $w; focus $w"
4058 bind $w <Key-Escape> [list destroy $w]
4059 bind $w <Key-Return> [list destroy $w]
4060 wm title $w "[appname] ([reponame]): Database Statistics"
4065 set w [new_console {gc} {Compressing the object database}]
4067 {console_exec {git pack-refs --prune}}
4068 {console_exec {git reflog expire --all}}
4069 {console_exec {git repack -a -d -l}}
4070 {console_exec {git rerere gc}}
4074 proc do_fsck_objects {} {
4075 set w [new_console {fsck-objects} \
4076 {Verifying the object database with fsck-objects}]
4077 set cmd [list git fsck-objects]
4080 lappend cmd --strict
4081 console_exec $w $cmd console_done
4087 global ui_comm is_quitting repo_config commit_type
4089 if {$is_quitting} return
4092 if {[winfo exists $ui_comm]} {
4093 # -- Stash our current commit buffer.
4095 set save [gitdir GITGUI_MSG]
4096 set msg [string trim [$ui_comm get 0.0 end]]
4097 regsub -all -line {[ \r\t]+$} $msg {} msg
4098 if {(![string match amend* $commit_type]
4099 || [$ui_comm edit modified])
4102 set fd [open $save w]
4103 puts -nonewline $fd $msg
4107 catch {file delete $save}
4110 # -- Stash our current window geometry into this repository.
4112 set cfg_geometry [list]
4113 lappend cfg_geometry [wm geometry .]
4114 lappend cfg_geometry [lindex [.vpane sash coord 0] 1]
4115 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 0]
4116 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
4119 if {$cfg_geometry ne $rc_geometry} {
4120 catch {exec git config gui.geometry $cfg_geometry}
4128 rescan {set ui_status_value {Ready.}}
4131 proc unstage_helper {txt paths} {
4132 global file_states current_diff_path
4134 if {![lock_index begin-update]} return
4138 foreach path $paths {
4139 switch -glob -- [lindex $file_states($path) 0] {
4143 lappend pathList $path
4144 if {$path eq $current_diff_path} {
4145 set after {reshow_diff;}
4150 if {$pathList eq {}} {
4156 [concat $after {set ui_status_value {Ready.}}]
4160 proc do_unstage_selection {} {
4161 global current_diff_path selected_paths
4163 if {[array size selected_paths] > 0} {
4165 {Unstaging selected files from commit} \
4166 [array names selected_paths]
4167 } elseif {$current_diff_path ne {}} {
4169 "Unstaging [short_path $current_diff_path] from commit" \
4170 [list $current_diff_path]
4174 proc add_helper {txt paths} {
4175 global file_states current_diff_path
4177 if {![lock_index begin-update]} return
4181 foreach path $paths {
4182 switch -glob -- [lindex $file_states($path) 0] {
4187 lappend pathList $path
4188 if {$path eq $current_diff_path} {
4189 set after {reshow_diff;}
4194 if {$pathList eq {}} {
4200 [concat $after {set ui_status_value {Ready to commit.}}]
4204 proc do_add_selection {} {
4205 global current_diff_path selected_paths
4207 if {[array size selected_paths] > 0} {
4209 {Adding selected files} \
4210 [array names selected_paths]
4211 } elseif {$current_diff_path ne {}} {
4213 "Adding [short_path $current_diff_path]" \
4214 [list $current_diff_path]
4218 proc do_add_all {} {
4222 foreach path [array names file_states] {
4223 switch -glob -- [lindex $file_states($path) 0] {
4226 ?D {lappend paths $path}
4229 add_helper {Adding all changed files} $paths
4232 proc revert_helper {txt paths} {
4233 global file_states current_diff_path
4235 if {![lock_index begin-update]} return
4239 foreach path $paths {
4240 switch -glob -- [lindex $file_states($path) 0] {
4244 lappend pathList $path
4245 if {$path eq $current_diff_path} {
4246 set after {reshow_diff;}
4252 set n [llength $pathList]
4256 } elseif {$n == 1} {
4257 set s "[short_path [lindex $pathList]]"
4259 set s "these $n files"
4262 set reply [tk_dialog \
4264 "[appname] ([reponame])" \
4265 "Revert changes in $s?
4267 Any unadded changes will be permanently lost by the revert." \
4277 [concat $after {set ui_status_value {Ready.}}]
4283 proc do_revert_selection {} {
4284 global current_diff_path selected_paths
4286 if {[array size selected_paths] > 0} {
4288 {Reverting selected files} \
4289 [array names selected_paths]
4290 } elseif {$current_diff_path ne {}} {
4292 "Reverting [short_path $current_diff_path]" \
4293 [list $current_diff_path]
4297 proc do_signoff {} {
4300 set me [committer_ident]
4301 if {$me eq {}} return
4303 set sob "Signed-off-by: $me"
4304 set last [$ui_comm get {end -1c linestart} {end -1c}]
4305 if {$last ne $sob} {
4306 $ui_comm edit separator
4308 && ![regexp {^[A-Z][A-Za-z]*-[A-Za-z-]+: *} $last]} {
4309 $ui_comm insert end "\n"
4311 $ui_comm insert end "\n$sob"
4312 $ui_comm edit separator
4317 proc do_select_commit_type {} {
4318 global commit_type selected_commit_type
4320 if {$selected_commit_type eq {new}
4321 && [string match amend* $commit_type]} {
4323 } elseif {$selected_commit_type eq {amend}
4324 && ![string match amend* $commit_type]} {
4327 # The amend request was rejected...
4329 if {![string match amend* $commit_type]} {
4330 set selected_commit_type new
4340 global appvers copyright
4341 global tcl_patchLevel tk_patchLevel
4345 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
4347 label $w.header -text "About [appname]" \
4349 pack $w.header -side top -fill x
4352 button $w.buttons.close -text {Close} \
4354 -command [list destroy $w]
4355 pack $w.buttons.close -side right
4356 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
4359 -text "[appname] - a commit creation tool for Git.
4367 pack $w.desc -side top -fill x -padx 5 -pady 5
4370 append v "[appname] version $appvers\n"
4371 append v "[exec git version]\n"
4373 if {$tcl_patchLevel eq $tk_patchLevel} {
4374 append v "Tcl/Tk version $tcl_patchLevel"
4376 append v "Tcl version $tcl_patchLevel"
4377 append v ", Tk version $tk_patchLevel"
4388 pack $w.vers -side top -fill x -padx 5 -pady 5
4390 menu $w.ctxm -tearoff 0
4391 $w.ctxm add command \
4396 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
4399 bind $w <Visibility> "grab $w; focus $w"
4400 bind $w <Key-Escape> "destroy $w"
4401 bind_button3 $w.vers "tk_popup $w.ctxm %X %Y; grab $w; focus $w"
4402 wm title $w "About [appname]"
4406 proc do_options {} {
4407 global repo_config global_config font_descs
4408 global repo_config_new global_config_new
4410 array unset repo_config_new
4411 array unset global_config_new
4412 foreach name [array names repo_config] {
4413 set repo_config_new($name) $repo_config($name)
4416 foreach name [array names repo_config] {
4418 gui.diffcontext {continue}
4420 set repo_config_new($name) $repo_config($name)
4422 foreach name [array names global_config] {
4423 set global_config_new($name) $global_config($name)
4426 set w .options_editor
4428 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
4430 label $w.header -text "[appname] Options" \
4432 pack $w.header -side top -fill x
4435 button $w.buttons.restore -text {Restore Defaults} \
4437 -command do_restore_defaults
4438 pack $w.buttons.restore -side left
4439 button $w.buttons.save -text Save \
4441 -command [list do_save_config $w]
4442 pack $w.buttons.save -side right
4443 button $w.buttons.cancel -text {Cancel} \
4445 -command [list destroy $w]
4446 pack $w.buttons.cancel -side right -padx 5
4447 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
4449 labelframe $w.repo -text "[reponame] Repository" \
4451 labelframe $w.global -text {Global (All Repositories)} \
4453 pack $w.repo -side left -fill both -expand 1 -pady 5 -padx 5
4454 pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
4458 {t user.name {User Name}}
4459 {t user.email {Email Address}}
4461 {b merge.summary {Summarize Merge Commits}}
4462 {i-1..5 merge.verbosity {Merge Verbosity}}
4464 {b gui.trustmtime {Trust File Modification Timestamps}}
4465 {i-1..99 gui.diffcontext {Number of Diff Context Lines}}
4466 {t gui.newbranchtemplate {New Branch Name Template}}
4468 set type [lindex $option 0]
4469 set name [lindex $option 1]
4470 set text [lindex $option 2]
4472 foreach f {repo global} {
4473 switch -glob -- $type {
4475 checkbutton $w.$f.$optid -text $text \
4476 -variable ${f}_config_new($name) \
4480 pack $w.$f.$optid -side top -anchor w
4483 regexp -- {-(\d+)\.\.(\d+)$} $type _junk min max
4485 label $w.$f.$optid.l -text "$text:" -font font_ui
4486 pack $w.$f.$optid.l -side left -anchor w -fill x
4487 spinbox $w.$f.$optid.v \
4488 -textvariable ${f}_config_new($name) \
4492 -width [expr {1 + [string length $max]}] \
4494 bind $w.$f.$optid.v <FocusIn> {%W selection range 0 end}
4495 pack $w.$f.$optid.v -side right -anchor e -padx 5
4496 pack $w.$f.$optid -side top -anchor w -fill x
4500 label $w.$f.$optid.l -text "$text:" -font font_ui
4501 entry $w.$f.$optid.v \
4505 -textvariable ${f}_config_new($name) \
4507 pack $w.$f.$optid.l -side left -anchor w
4508 pack $w.$f.$optid.v -side left -anchor w \
4511 pack $w.$f.$optid -side top -anchor w -fill x
4517 set all_fonts [lsort [font families]]
4518 foreach option $font_descs {
4519 set name [lindex $option 0]
4520 set font [lindex $option 1]
4521 set text [lindex $option 2]
4523 set global_config_new(gui.$font^^family) \
4524 [font configure $font -family]
4525 set global_config_new(gui.$font^^size) \
4526 [font configure $font -size]
4528 frame $w.global.$name
4529 label $w.global.$name.l -text "$text:" -font font_ui
4530 pack $w.global.$name.l -side left -anchor w -fill x
4531 eval tk_optionMenu $w.global.$name.family \
4532 global_config_new(gui.$font^^family) \
4534 spinbox $w.global.$name.size \
4535 -textvariable global_config_new(gui.$font^^size) \
4536 -from 2 -to 80 -increment 1 \
4539 bind $w.global.$name.size <FocusIn> {%W selection range 0 end}
4540 pack $w.global.$name.size -side right -anchor e
4541 pack $w.global.$name.family -side right -anchor e
4542 pack $w.global.$name -side top -anchor w -fill x
4545 bind $w <Visibility> "grab $w; focus $w"
4546 bind $w <Key-Escape> "destroy $w"
4547 wm title $w "[appname] ([reponame]): Options"
4551 proc do_restore_defaults {} {
4552 global font_descs default_config repo_config
4553 global repo_config_new global_config_new
4555 foreach name [array names default_config] {
4556 set repo_config_new($name) $default_config($name)
4557 set global_config_new($name) $default_config($name)
4560 foreach option $font_descs {
4561 set name [lindex $option 0]
4562 set repo_config(gui.$name) $default_config(gui.$name)
4566 foreach option $font_descs {
4567 set name [lindex $option 0]
4568 set font [lindex $option 1]
4569 set global_config_new(gui.$font^^family) \
4570 [font configure $font -family]
4571 set global_config_new(gui.$font^^size) \
4572 [font configure $font -size]
4576 proc do_save_config {w} {
4577 if {[catch {save_config} err]} {
4578 error_popup "Failed to completely save options:\n\n$err"
4584 proc do_windows_shortcut {} {
4587 set fn [tk_getSaveFile \
4589 -title "[appname] ([reponame]): Create Desktop Icon" \
4590 -initialfile "Git [reponame].bat"]
4594 puts $fd "@ECHO Entering [reponame]"
4595 puts $fd "@ECHO Starting git-gui... please wait..."
4596 puts $fd "@SET PATH=[file normalize [gitexec]];%PATH%"
4597 puts $fd "@SET GIT_DIR=[file normalize [gitdir]]"
4598 puts -nonewline $fd "@\"[info nameofexecutable]\""
4599 puts $fd " \"[file normalize $argv0]\""
4602 error_popup "Cannot write script:\n\n$err"
4607 proc do_cygwin_shortcut {} {
4611 set desktop [exec cygpath \
4619 set fn [tk_getSaveFile \
4621 -title "[appname] ([reponame]): Create Desktop Icon" \
4622 -initialdir $desktop \
4623 -initialfile "Git [reponame].bat"]
4627 set sh [exec cygpath \
4631 set me [exec cygpath \
4635 set gd [exec cygpath \
4639 set gw [exec cygpath \
4642 [file dirname [gitdir]]]
4643 regsub -all ' $me "'\\''" me
4644 regsub -all ' $gd "'\\''" gd
4645 puts $fd "@ECHO Entering $gw"
4646 puts $fd "@ECHO Starting git-gui... please wait..."
4647 puts -nonewline $fd "@\"$sh\" --login -c \""
4648 puts -nonewline $fd "GIT_DIR='$gd'"
4649 puts -nonewline $fd " '$me'"
4653 error_popup "Cannot write script:\n\n$err"
4658 proc do_macosx_app {} {
4661 set fn [tk_getSaveFile \
4663 -title "[appname] ([reponame]): Create Desktop Icon" \
4664 -initialdir [file join $env(HOME) Desktop] \
4665 -initialfile "Git [reponame].app"]
4668 set Contents [file join $fn Contents]
4669 set MacOS [file join $Contents MacOS]
4670 set exe [file join $MacOS git-gui]
4674 set fd [open [file join $Contents Info.plist] w]
4675 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
4676 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4677 <plist version="1.0">
4679 <key>CFBundleDevelopmentRegion</key>
4680 <string>English</string>
4681 <key>CFBundleExecutable</key>
4682 <string>git-gui</string>
4683 <key>CFBundleIdentifier</key>
4684 <string>org.spearce.git-gui</string>
4685 <key>CFBundleInfoDictionaryVersion</key>
4686 <string>6.0</string>
4687 <key>CFBundlePackageType</key>
4688 <string>APPL</string>
4689 <key>CFBundleSignature</key>
4690 <string>????</string>
4691 <key>CFBundleVersion</key>
4692 <string>1.0</string>
4693 <key>NSPrincipalClass</key>
4694 <string>NSApplication</string>
4699 set fd [open $exe w]
4700 set gd [file normalize [gitdir]]
4701 set ep [file normalize [gitexec]]
4702 regsub -all ' $gd "'\\''" gd
4703 regsub -all ' $ep "'\\''" ep
4704 puts $fd "#!/bin/sh"
4705 foreach name [array names env] {
4706 if {[string match GIT_* $name]} {
4707 regsub -all ' $env($name) "'\\''" v
4708 puts $fd "export $name='$v'"
4711 puts $fd "export PATH='$ep':\$PATH"
4712 puts $fd "export GIT_DIR='$gd'"
4713 puts $fd "exec [file normalize $argv0]"
4716 file attributes $exe -permissions u+x,g+x,o+x
4718 error_popup "Cannot write icon:\n\n$err"
4723 proc toggle_or_diff {w x y} {
4724 global file_states file_lists current_diff_path ui_index ui_workdir
4725 global last_clicked selected_paths
4727 set pos [split [$w index @$x,$y] .]
4728 set lno [lindex $pos 0]
4729 set col [lindex $pos 1]
4730 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4736 set last_clicked [list $w $lno]
4737 array unset selected_paths
4738 $ui_index tag remove in_sel 0.0 end
4739 $ui_workdir tag remove in_sel 0.0 end
4742 if {$current_diff_path eq $path} {
4743 set after {reshow_diff;}
4747 if {$w eq $ui_index} {
4749 "Unstaging [short_path $path] from commit" \
4751 [concat $after {set ui_status_value {Ready.}}]
4752 } elseif {$w eq $ui_workdir} {
4754 "Adding [short_path $path]" \
4756 [concat $after {set ui_status_value {Ready.}}]
4759 show_diff $path $w $lno
4763 proc add_one_to_selection {w x y} {
4764 global file_lists last_clicked selected_paths
4766 set lno [lindex [split [$w index @$x,$y] .] 0]
4767 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4773 if {$last_clicked ne {}
4774 && [lindex $last_clicked 0] ne $w} {
4775 array unset selected_paths
4776 [lindex $last_clicked 0] tag remove in_sel 0.0 end
4779 set last_clicked [list $w $lno]
4780 if {[catch {set in_sel $selected_paths($path)}]} {
4784 unset selected_paths($path)
4785 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
4787 set selected_paths($path) 1
4788 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
4792 proc add_range_to_selection {w x y} {
4793 global file_lists last_clicked selected_paths
4795 if {[lindex $last_clicked 0] ne $w} {
4796 toggle_or_diff $w $x $y
4800 set lno [lindex [split [$w index @$x,$y] .] 0]
4801 set lc [lindex $last_clicked 1]
4810 foreach path [lrange $file_lists($w) \
4811 [expr {$begin - 1}] \
4812 [expr {$end - 1}]] {
4813 set selected_paths($path) 1
4815 $w tag add in_sel $begin.0 [expr {$end + 1}].0
4818 ######################################################################
4822 set cursor_ptr arrow
4823 font create font_diff -family Courier -size 10
4827 eval font configure font_ui [font actual [.dummy cget -font]]
4831 font create font_uibold
4832 font create font_diffbold
4837 } elseif {[is_MacOSX]} {
4845 proc apply_config {} {
4846 global repo_config font_descs
4848 foreach option $font_descs {
4849 set name [lindex $option 0]
4850 set font [lindex $option 1]
4852 foreach {cn cv} $repo_config(gui.$name) {
4853 font configure $font $cn $cv
4856 error_popup "Invalid font specified in gui.$name:\n\n$err"
4858 foreach {cn cv} [font configure $font] {
4859 font configure ${font}bold $cn $cv
4861 font configure ${font}bold -weight bold
4865 set default_config(merge.summary) false
4866 set default_config(merge.verbosity) 2
4867 set default_config(user.name) {}
4868 set default_config(user.email) {}
4870 set default_config(gui.trustmtime) false
4871 set default_config(gui.diffcontext) 5
4872 set default_config(gui.newbranchtemplate) {}
4873 set default_config(gui.fontui) [font configure font_ui]
4874 set default_config(gui.fontdiff) [font configure font_diff]
4876 {fontui font_ui {Main Font}}
4877 {fontdiff font_diff {Diff/Console Font}}
4882 ######################################################################
4884 ## feature option selection
4886 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
4891 if {$subcommand eq {gui.sh}} {
4894 if {$subcommand eq {gui} && [llength $argv] > 0} {
4895 set subcommand [lindex $argv 0]
4896 set argv [lrange $argv 1 end]
4899 enable_option multicommit
4900 enable_option branch
4901 enable_option transport
4903 switch -- $subcommand {
4905 disable_option multicommit
4906 disable_option branch
4907 disable_option transport
4910 enable_option singlecommit
4912 disable_option multicommit
4913 disable_option branch
4914 disable_option transport
4918 ######################################################################
4926 menu .mbar -tearoff 0
4927 .mbar add cascade -label Repository -menu .mbar.repository
4928 .mbar add cascade -label Edit -menu .mbar.edit
4929 if {[is_enabled branch]} {
4930 .mbar add cascade -label Branch -menu .mbar.branch
4932 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
4933 .mbar add cascade -label Commit -menu .mbar.commit
4935 if {[is_enabled transport]} {
4936 .mbar add cascade -label Merge -menu .mbar.merge
4937 .mbar add cascade -label Fetch -menu .mbar.fetch
4938 .mbar add cascade -label Push -menu .mbar.push
4940 . configure -menu .mbar
4942 # -- Repository Menu
4944 menu .mbar.repository
4946 .mbar.repository add command \
4947 -label {Browse Current Branch} \
4948 -command {new_browser $current_branch} \
4950 trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Browse \$current_branch\" ;#"
4951 .mbar.repository add separator
4953 .mbar.repository add command \
4954 -label {Visualize Current Branch} \
4955 -command {do_gitk $current_branch} \
4957 trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#"
4958 .mbar.repository add command \
4959 -label {Visualize All Branches} \
4960 -command {do_gitk --all} \
4962 .mbar.repository add separator
4964 if {[is_enabled multicommit]} {
4965 .mbar.repository add command -label {Database Statistics} \
4969 .mbar.repository add command -label {Compress Database} \
4973 .mbar.repository add command -label {Verify Database} \
4974 -command do_fsck_objects \
4977 .mbar.repository add separator
4980 .mbar.repository add command \
4981 -label {Create Desktop Icon} \
4982 -command do_cygwin_shortcut \
4984 } elseif {[is_Windows]} {
4985 .mbar.repository add command \
4986 -label {Create Desktop Icon} \
4987 -command do_windows_shortcut \
4989 } elseif {[is_MacOSX]} {
4990 .mbar.repository add command \
4991 -label {Create Desktop Icon} \
4992 -command do_macosx_app \
4997 .mbar.repository add command -label Quit \
4999 -accelerator $M1T-Q \
5005 .mbar.edit add command -label Undo \
5006 -command {catch {[focus] edit undo}} \
5007 -accelerator $M1T-Z \
5009 .mbar.edit add command -label Redo \
5010 -command {catch {[focus] edit redo}} \
5011 -accelerator $M1T-Y \
5013 .mbar.edit add separator
5014 .mbar.edit add command -label Cut \
5015 -command {catch {tk_textCut [focus]}} \
5016 -accelerator $M1T-X \
5018 .mbar.edit add command -label Copy \
5019 -command {catch {tk_textCopy [focus]}} \
5020 -accelerator $M1T-C \
5022 .mbar.edit add command -label Paste \
5023 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
5024 -accelerator $M1T-V \
5026 .mbar.edit add command -label Delete \
5027 -command {catch {[focus] delete sel.first sel.last}} \
5030 .mbar.edit add separator
5031 .mbar.edit add command -label {Select All} \
5032 -command {catch {[focus] tag add sel 0.0 end}} \
5033 -accelerator $M1T-A \
5038 if {[is_enabled branch]} {
5041 .mbar.branch add command -label {Create...} \
5042 -command do_create_branch \
5043 -accelerator $M1T-N \
5045 lappend disable_on_lock [list .mbar.branch entryconf \
5046 [.mbar.branch index last] -state]
5048 .mbar.branch add command -label {Delete...} \
5049 -command do_delete_branch \
5051 lappend disable_on_lock [list .mbar.branch entryconf \
5052 [.mbar.branch index last] -state]
5057 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
5060 .mbar.commit add radiobutton \
5061 -label {New Commit} \
5062 -command do_select_commit_type \
5063 -variable selected_commit_type \
5066 lappend disable_on_lock \
5067 [list .mbar.commit entryconf [.mbar.commit index last] -state]
5069 .mbar.commit add radiobutton \
5070 -label {Amend Last Commit} \
5071 -command do_select_commit_type \
5072 -variable selected_commit_type \
5075 lappend disable_on_lock \
5076 [list .mbar.commit entryconf [.mbar.commit index last] -state]
5078 .mbar.commit add separator
5080 .mbar.commit add command -label Rescan \
5081 -command do_rescan \
5084 lappend disable_on_lock \
5085 [list .mbar.commit entryconf [.mbar.commit index last] -state]
5087 .mbar.commit add command -label {Add To Commit} \
5088 -command do_add_selection \
5090 lappend disable_on_lock \
5091 [list .mbar.commit entryconf [.mbar.commit index last] -state]
5093 .mbar.commit add command -label {Add Existing To Commit} \
5094 -command do_add_all \
5095 -accelerator $M1T-I \
5097 lappend disable_on_lock \
5098 [list .mbar.commit entryconf [.mbar.commit index last] -state]
5100 .mbar.commit add command -label {Unstage From Commit} \
5101 -command do_unstage_selection \
5103 lappend disable_on_lock \
5104 [list .mbar.commit entryconf [.mbar.commit index last] -state]
5106 .mbar.commit add command -label {Revert Changes} \
5107 -command do_revert_selection \
5109 lappend disable_on_lock \
5110 [list .mbar.commit entryconf [.mbar.commit index last] -state]
5112 .mbar.commit add separator
5114 .mbar.commit add command -label {Sign Off} \
5115 -command do_signoff \
5116 -accelerator $M1T-S \
5119 .mbar.commit add command -label Commit \
5120 -command do_commit \
5121 -accelerator $M1T-Return \
5123 lappend disable_on_lock \
5124 [list .mbar.commit entryconf [.mbar.commit index last] -state]
5128 # -- Apple Menu (Mac OS X only)
5130 .mbar add cascade -label Apple -menu .mbar.apple
5133 .mbar.apple add command -label "About [appname]" \
5136 .mbar.apple add command -label "[appname] Options..." \
5137 -command do_options \
5142 .mbar.edit add separator
5143 .mbar.edit add command -label {Options...} \
5144 -command do_options \
5149 if {[file exists /usr/local/miga/lib/gui-miga]
5150 && [file exists .pvcsrc]} {
5152 global ui_status_value
5153 if {![lock_index update]} return
5154 set cmd [list sh --login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
5155 set miga_fd [open "|$cmd" r]
5156 fconfigure $miga_fd -blocking 0
5157 fileevent $miga_fd readable [list miga_done $miga_fd]
5158 set ui_status_value {Running miga...}
5160 proc miga_done {fd} {
5165 rescan [list set ui_status_value {Ready.}]
5168 .mbar add cascade -label Tools -menu .mbar.tools
5170 .mbar.tools add command -label "Migrate" \
5173 lappend disable_on_lock \
5174 [list .mbar.tools entryconf [.mbar.tools index last] -state]
5180 .mbar add cascade -label Help -menu .mbar.help
5184 .mbar.help add command -label "About [appname]" \
5190 catch {set browser $repo_config(instaweb.browser)}
5191 set doc_path [file dirname [gitexec]]
5192 set doc_path [file join $doc_path Documentation index.html]
5195 set doc_path [exec cygpath --windows $doc_path]
5198 if {$browser eq {}} {
5201 } elseif {[is_Cygwin]} {
5202 set program_files [file dirname [exec cygpath --windir]]
5203 set program_files [file join $program_files {Program Files}]
5204 set firefox [file join $program_files {Mozilla Firefox} firefox.exe]
5205 set ie [file join $program_files {Internet Explorer} IEXPLORE.EXE]
5206 if {[file exists $firefox]} {
5207 set browser $firefox
5208 } elseif {[file exists $ie]} {
5211 unset program_files firefox ie
5215 if {[file isfile $doc_path]} {
5216 set doc_url "file:$doc_path"
5218 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
5221 if {$browser ne {}} {
5222 .mbar.help add command -label {Online Documentation} \
5223 -command [list exec $browser $doc_url &] \
5226 unset browser doc_path doc_url
5228 # -- Standard bindings
5230 bind . <Destroy> do_quit
5231 bind all <$M1B-Key-q> do_quit
5232 bind all <$M1B-Key-Q> do_quit
5233 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
5234 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
5236 # -- Not a normal commit type invocation? Do that instead!
5238 switch -- $subcommand {
5240 if {[llength $argv] != 2} {
5241 puts stderr "usage: $argv0 blame commit path"
5244 set current_branch [lindex $argv 0]
5245 show_blame $current_branch [lindex $argv 1]
5250 if {[llength $argv] != 0} {
5251 puts -nonewline stderr "usage: $argv0"
5252 if {$subcommand ne {gui} && [appname] ne "git-$subcommand"} {
5253 puts -nonewline stderr " $subcommand"
5258 # fall through to setup UI for commits
5261 puts stderr "usage: $argv0 \[{blame|citool}\]"
5272 -text {Current Branch:} \
5277 -textvariable current_branch \
5281 pack .branch.l1 -side left
5282 pack .branch.cb -side left -fill x
5283 pack .branch -side top -fill x
5285 if {[is_enabled branch]} {
5287 .mbar.merge add command -label {Local Merge...} \
5288 -command do_local_merge \
5290 lappend disable_on_lock \
5291 [list .mbar.merge entryconf [.mbar.merge index last] -state]
5292 .mbar.merge add command -label {Abort Merge...} \
5293 -command do_reset_hard \
5295 lappend disable_on_lock \
5296 [list .mbar.merge entryconf [.mbar.merge index last] -state]
5302 .mbar.push add command -label {Push...} \
5303 -command do_push_anywhere \
5307 # -- Main Window Layout
5309 panedwindow .vpane -orient vertical
5310 panedwindow .vpane.files -orient horizontal
5311 .vpane add .vpane.files -sticky nsew -height 100 -width 200
5312 pack .vpane -anchor n -side top -fill both -expand 1
5314 # -- Index File List
5316 frame .vpane.files.index -height 100 -width 200
5317 label .vpane.files.index.title -text {Changes To Be Committed} \
5320 text $ui_index -background white -borderwidth 0 \
5321 -width 20 -height 10 \
5324 -cursor $cursor_ptr \
5325 -xscrollcommand {.vpane.files.index.sx set} \
5326 -yscrollcommand {.vpane.files.index.sy set} \
5328 scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
5329 scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
5330 pack .vpane.files.index.title -side top -fill x
5331 pack .vpane.files.index.sx -side bottom -fill x
5332 pack .vpane.files.index.sy -side right -fill y
5333 pack $ui_index -side left -fill both -expand 1
5334 .vpane.files add .vpane.files.index -sticky nsew
5336 # -- Working Directory File List
5338 frame .vpane.files.workdir -height 100 -width 200
5339 label .vpane.files.workdir.title -text {Changed But Not Updated} \
5342 text $ui_workdir -background white -borderwidth 0 \
5343 -width 20 -height 10 \
5346 -cursor $cursor_ptr \
5347 -xscrollcommand {.vpane.files.workdir.sx set} \
5348 -yscrollcommand {.vpane.files.workdir.sy set} \
5350 scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
5351 scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
5352 pack .vpane.files.workdir.title -side top -fill x
5353 pack .vpane.files.workdir.sx -side bottom -fill x
5354 pack .vpane.files.workdir.sy -side right -fill y
5355 pack $ui_workdir -side left -fill both -expand 1
5356 .vpane.files add .vpane.files.workdir -sticky nsew
5358 foreach i [list $ui_index $ui_workdir] {
5359 $i tag conf in_diff -font font_uibold
5360 $i tag conf in_sel \
5361 -background [$i cget -foreground] \
5362 -foreground [$i cget -background]
5366 # -- Diff and Commit Area
5368 frame .vpane.lower -height 300 -width 400
5369 frame .vpane.lower.commarea
5370 frame .vpane.lower.diff -relief sunken -borderwidth 1
5371 pack .vpane.lower.commarea -side top -fill x
5372 pack .vpane.lower.diff -side bottom -fill both -expand 1
5373 .vpane add .vpane.lower -sticky nsew
5375 # -- Commit Area Buttons
5377 frame .vpane.lower.commarea.buttons
5378 label .vpane.lower.commarea.buttons.l -text {} \
5382 pack .vpane.lower.commarea.buttons.l -side top -fill x
5383 pack .vpane.lower.commarea.buttons -side left -fill y
5385 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
5386 -command do_rescan \
5388 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
5389 lappend disable_on_lock \
5390 {.vpane.lower.commarea.buttons.rescan conf -state}
5392 button .vpane.lower.commarea.buttons.incall -text {Add Existing} \
5393 -command do_add_all \
5395 pack .vpane.lower.commarea.buttons.incall -side top -fill x
5396 lappend disable_on_lock \
5397 {.vpane.lower.commarea.buttons.incall conf -state}
5399 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
5400 -command do_signoff \
5402 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
5404 button .vpane.lower.commarea.buttons.commit -text {Commit} \
5405 -command do_commit \
5407 pack .vpane.lower.commarea.buttons.commit -side top -fill x
5408 lappend disable_on_lock \
5409 {.vpane.lower.commarea.buttons.commit conf -state}
5411 # -- Commit Message Buffer
5413 frame .vpane.lower.commarea.buffer
5414 frame .vpane.lower.commarea.buffer.header
5415 set ui_comm .vpane.lower.commarea.buffer.t
5416 set ui_coml .vpane.lower.commarea.buffer.header.l
5417 radiobutton .vpane.lower.commarea.buffer.header.new \
5418 -text {New Commit} \
5419 -command do_select_commit_type \
5420 -variable selected_commit_type \
5423 lappend disable_on_lock \
5424 [list .vpane.lower.commarea.buffer.header.new conf -state]
5425 radiobutton .vpane.lower.commarea.buffer.header.amend \
5426 -text {Amend Last Commit} \
5427 -command do_select_commit_type \
5428 -variable selected_commit_type \
5431 lappend disable_on_lock \
5432 [list .vpane.lower.commarea.buffer.header.amend conf -state]
5437 proc trace_commit_type {varname args} {
5438 global ui_coml commit_type
5439 switch -glob -- $commit_type {
5440 initial {set txt {Initial Commit Message:}}
5441 amend {set txt {Amended Commit Message:}}
5442 amend-initial {set txt {Amended Initial Commit Message:}}
5443 amend-merge {set txt {Amended Merge Commit Message:}}
5444 merge {set txt {Merge Commit Message:}}
5445 * {set txt {Commit Message:}}
5447 $ui_coml conf -text $txt
5449 trace add variable commit_type write trace_commit_type
5450 pack $ui_coml -side left -fill x
5451 pack .vpane.lower.commarea.buffer.header.amend -side right
5452 pack .vpane.lower.commarea.buffer.header.new -side right
5454 text $ui_comm -background white -borderwidth 1 \
5457 -autoseparators true \
5459 -width 75 -height 9 -wrap none \
5461 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
5462 scrollbar .vpane.lower.commarea.buffer.sby \
5463 -command [list $ui_comm yview]
5464 pack .vpane.lower.commarea.buffer.header -side top -fill x
5465 pack .vpane.lower.commarea.buffer.sby -side right -fill y
5466 pack $ui_comm -side left -fill y
5467 pack .vpane.lower.commarea.buffer -side left -fill y
5469 # -- Commit Message Buffer Context Menu
5471 set ctxm .vpane.lower.commarea.buffer.ctxm
5472 menu $ctxm -tearoff 0
5476 -command {tk_textCut $ui_comm}
5480 -command {tk_textCopy $ui_comm}
5484 -command {tk_textPaste $ui_comm}
5488 -command {$ui_comm delete sel.first sel.last}
5491 -label {Select All} \
5493 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
5498 $ui_comm tag add sel 0.0 end
5499 tk_textCopy $ui_comm
5500 $ui_comm tag remove sel 0.0 end
5507 bind_button3 $ui_comm "tk_popup $ctxm %X %Y"
5511 set current_diff_path {}
5512 set current_diff_side {}
5513 set diff_actions [list]
5514 proc trace_current_diff_path {varname args} {
5515 global current_diff_path diff_actions file_states
5516 if {$current_diff_path eq {}} {
5522 set p $current_diff_path
5523 set s [mapdesc [lindex $file_states($p) 0] $p]
5525 set p [escape_path $p]
5529 .vpane.lower.diff.header.status configure -text $s
5530 .vpane.lower.diff.header.file configure -text $f
5531 .vpane.lower.diff.header.path configure -text $p
5532 foreach w $diff_actions {
5536 trace add variable current_diff_path write trace_current_diff_path
5538 frame .vpane.lower.diff.header -background orange
5539 label .vpane.lower.diff.header.status \
5540 -background orange \
5541 -width $max_status_desc \
5545 label .vpane.lower.diff.header.file \
5546 -background orange \
5550 label .vpane.lower.diff.header.path \
5551 -background orange \
5555 pack .vpane.lower.diff.header.status -side left
5556 pack .vpane.lower.diff.header.file -side left
5557 pack .vpane.lower.diff.header.path -fill x
5558 set ctxm .vpane.lower.diff.header.ctxm
5559 menu $ctxm -tearoff 0
5568 -- $current_diff_path
5570 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
5571 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
5575 frame .vpane.lower.diff.body
5576 set ui_diff .vpane.lower.diff.body.t
5577 text $ui_diff -background white -borderwidth 0 \
5578 -width 80 -height 15 -wrap none \
5580 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
5581 -yscrollcommand {.vpane.lower.diff.body.sby set} \
5583 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
5584 -command [list $ui_diff xview]
5585 scrollbar .vpane.lower.diff.body.sby -orient vertical \
5586 -command [list $ui_diff yview]
5587 pack .vpane.lower.diff.body.sbx -side bottom -fill x
5588 pack .vpane.lower.diff.body.sby -side right -fill y
5589 pack $ui_diff -side left -fill both -expand 1
5590 pack .vpane.lower.diff.header -side top -fill x
5591 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
5593 $ui_diff tag conf d_cr -elide true
5594 $ui_diff tag conf d_@ -foreground blue -font font_diffbold
5595 $ui_diff tag conf d_+ -foreground {#00a000}
5596 $ui_diff tag conf d_- -foreground red
5598 $ui_diff tag conf d_++ -foreground {#00a000}
5599 $ui_diff tag conf d_-- -foreground red
5600 $ui_diff tag conf d_+s \
5601 -foreground {#00a000} \
5602 -background {#e2effa}
5603 $ui_diff tag conf d_-s \
5605 -background {#e2effa}
5606 $ui_diff tag conf d_s+ \
5607 -foreground {#00a000} \
5609 $ui_diff tag conf d_s- \
5613 $ui_diff tag conf d<<<<<<< \
5614 -foreground orange \
5616 $ui_diff tag conf d======= \
5617 -foreground orange \
5619 $ui_diff tag conf d>>>>>>> \
5620 -foreground orange \
5623 $ui_diff tag raise sel
5625 # -- Diff Body Context Menu
5627 set ctxm .vpane.lower.diff.body.ctxm
5628 menu $ctxm -tearoff 0
5632 -command reshow_diff
5633 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
5637 -command {tk_textCopy $ui_diff}
5638 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
5640 -label {Select All} \
5642 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
5643 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
5648 $ui_diff tag add sel 0.0 end
5649 tk_textCopy $ui_diff
5650 $ui_diff tag remove sel 0.0 end
5652 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
5655 -label {Apply/Reverse Hunk} \
5657 -command {apply_hunk $cursorX $cursorY}
5658 set ui_diff_applyhunk [$ctxm index last]
5659 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
5662 -label {Decrease Font Size} \
5664 -command {incr_font_size font_diff -1}
5665 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
5667 -label {Increase Font Size} \
5669 -command {incr_font_size font_diff 1}
5670 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
5673 -label {Show Less Context} \
5675 -command {if {$repo_config(gui.diffcontext) >= 2} {
5676 incr repo_config(gui.diffcontext) -1
5679 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
5681 -label {Show More Context} \
5684 incr repo_config(gui.diffcontext)
5687 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
5689 $ctxm add command -label {Options...} \
5692 bind_button3 $ui_diff "
5695 if {\$ui_index eq \$current_diff_side} {
5696 $ctxm entryconf $ui_diff_applyhunk -label {Unstage Hunk From Commit}
5698 $ctxm entryconf $ui_diff_applyhunk -label {Stage Hunk For Commit}
5700 tk_popup $ctxm %X %Y
5702 unset ui_diff_applyhunk
5706 set ui_status_value {Initializing...}
5707 label .status -textvariable ui_status_value \
5713 pack .status -anchor w -side bottom -fill x
5718 set gm $repo_config(gui.geometry)
5719 wm geometry . [lindex $gm 0]
5720 .vpane sash place 0 \
5721 [lindex [.vpane sash coord 0] 0] \
5723 .vpane.files sash place 0 \
5725 [lindex [.vpane.files sash coord 0] 1]
5731 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
5732 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
5733 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
5734 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
5735 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
5736 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
5737 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
5738 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
5739 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
5740 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
5741 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
5743 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
5744 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
5745 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
5746 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
5747 bind $ui_diff <$M1B-Key-v> {break}
5748 bind $ui_diff <$M1B-Key-V> {break}
5749 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
5750 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
5751 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
5752 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
5753 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
5754 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
5755 bind $ui_diff <Button-1> {focus %W}
5757 if {[is_enabled branch]} {
5758 bind . <$M1B-Key-n> do_create_branch
5759 bind . <$M1B-Key-N> do_create_branch
5762 bind all <Key-F5> do_rescan
5763 bind all <$M1B-Key-r> do_rescan
5764 bind all <$M1B-Key-R> do_rescan
5765 bind . <$M1B-Key-s> do_signoff
5766 bind . <$M1B-Key-S> do_signoff
5767 bind . <$M1B-Key-i> do_add_all
5768 bind . <$M1B-Key-I> do_add_all
5769 bind . <$M1B-Key-Return> do_commit
5770 foreach i [list $ui_index $ui_workdir] {
5771 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
5772 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
5773 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
5777 set file_lists($ui_index) [list]
5778 set file_lists($ui_workdir) [list]
5782 set MERGE_HEAD [list]
5785 set current_branch {}
5786 set current_diff_path {}
5787 set selected_commit_type new
5789 wm title . "[appname] ([file normalize [file dirname [gitdir]]])"
5790 focus -force $ui_comm
5792 # -- Warn the user about environmental problems. Cygwin's Tcl
5793 # does *not* pass its env array onto any processes it spawns.
5794 # This means that git processes get none of our environment.
5799 set msg "Possible environment issues exist.
5801 The following environment variables are probably
5802 going to be ignored by any Git subprocess run
5806 foreach name [array names env] {
5807 switch -regexp -- $name {
5808 {^GIT_INDEX_FILE$} -
5809 {^GIT_OBJECT_DIRECTORY$} -
5810 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
5812 {^GIT_EXTERNAL_DIFF$} -
5816 {^GIT_CONFIG_LOCAL$} -
5817 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
5818 append msg " - $name\n"
5821 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
5822 append msg " - $name\n"
5824 set suggest_user $name
5828 if {$ignored_env > 0} {
5830 This is due to a known issue with the
5831 Tcl binary distributed by Cygwin."
5833 if {$suggest_user ne {}} {
5836 A good replacement for $suggest_user
5837 is placing values for the user.name and
5838 user.email settings into your personal
5844 unset ignored_env msg suggest_user name
5847 # -- Only initialize complex UI if we are going to stay running.
5849 if {[is_enabled transport]} {
5853 populate_branch_menu
5858 # -- Only suggest a gc run if we are going to stay running.
5860 if {[is_enabled multicommit]} {
5861 set object_limit 2000
5862 if {[is_Windows]} {set object_limit 200}
5863 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
5864 if {$objects_current >= $object_limit} {
5866 "This repository currently has $objects_current loose objects.
5868 To maintain optimal performance it is strongly
5869 recommended that you compress the database
5870 when more than $object_limit loose objects exist.
5872 Compress the database now?"] eq yes} {
5876 unset object_limit _junk objects_current
5879 lock_index begin-read