2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright (C) 2006 Shawn Pearce, Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
10 set appname [lindex [file split $argv0] end]
13 ######################################################################
17 proc is_many_config {name} {
18 switch -glob -- $name {
27 proc load_config {include_global} {
28 global repo_config global_config default_config
30 array unset global_config
31 if {$include_global} {
33 set fd_rc [open "| git repo-config --global --list" r]
34 while {[gets $fd_rc line] >= 0} {
35 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
36 if {[is_many_config $name]} {
37 lappend global_config($name) $value
39 set global_config($name) $value
47 array unset repo_config
49 set fd_rc [open "| git repo-config --list" r]
50 while {[gets $fd_rc line] >= 0} {
51 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
52 if {[is_many_config $name]} {
53 lappend repo_config($name) $value
55 set repo_config($name) $value
62 foreach name [array names default_config] {
63 if {[catch {set v $global_config($name)}]} {
64 set global_config($name) $default_config($name)
66 if {[catch {set v $repo_config($name)}]} {
67 set repo_config($name) $default_config($name)
73 global default_config font_descs
74 global repo_config global_config
75 global repo_config_new global_config_new
77 foreach option $font_descs {
78 set name [lindex $option 0]
79 set font [lindex $option 1]
80 font configure $font \
81 -family $global_config_new(gui.$font^^family) \
82 -size $global_config_new(gui.$font^^size)
83 font configure ${font}bold \
84 -family $global_config_new(gui.$font^^family) \
85 -size $global_config_new(gui.$font^^size)
86 set global_config_new(gui.$name) [font configure $font]
87 unset global_config_new(gui.$font^^family)
88 unset global_config_new(gui.$font^^size)
91 foreach name [array names default_config] {
92 set value $global_config_new($name)
93 if {$value ne $global_config($name)} {
94 if {$value eq $default_config($name)} {
95 catch {exec git repo-config --global --unset $name}
97 regsub -all "\[{}\]" $value {"} value
98 exec git repo-config --global $name $value
100 set global_config($name) $value
101 if {$value eq $repo_config($name)} {
102 catch {exec git repo-config --unset $name}
103 set repo_config($name) $value
108 foreach name [array names default_config] {
109 set value $repo_config_new($name)
110 if {$value ne $repo_config($name)} {
111 if {$value eq $global_config($name)} {
112 catch {exec git repo-config --unset $name}
114 regsub -all "\[{}\]" $value {"} value
115 exec git repo-config $name $value
117 set repo_config($name) $value
122 proc error_popup {msg} {
123 global gitdir appname
128 append title [lindex \
129 [file split [file normalize [file dirname $gitdir]]] \
137 -title "$title: error" \
141 proc info_popup {msg} {
142 global gitdir appname
147 append title [lindex \
148 [file split [file normalize [file dirname $gitdir]]] \
160 ######################################################################
164 if { [catch {set cdup [exec git rev-parse --show-cdup]} err]
165 || [catch {set gitdir [exec git rev-parse --git-dir]} err]} {
166 catch {wm withdraw .}
167 error_popup "Cannot find the git directory:\n\n$err"
176 if {$appname eq {git-citool}} {
180 ######################################################################
187 set disable_on_lock [list]
188 set index_lock_type none
194 proc lock_index {type} {
195 global index_lock_type disable_on_lock
197 if {$index_lock_type eq {none}} {
198 set index_lock_type $type
199 foreach w $disable_on_lock {
200 uplevel #0 $w disabled
203 } elseif {$index_lock_type eq {begin-update} && $type eq {update}} {
204 set index_lock_type $type
210 proc unlock_index {} {
211 global index_lock_type disable_on_lock
213 set index_lock_type none
214 foreach w $disable_on_lock {
219 ######################################################################
223 proc repository_state {hdvar ctvar} {
225 upvar $hdvar hd $ctvar ct
227 if {[catch {set hd [exec git rev-parse --verify HEAD]}]} {
229 } elseif {[file exists [file join $gitdir MERGE_HEAD]]} {
236 proc update_status {{final Ready.}} {
237 global HEAD PARENT commit_type
238 global ui_index ui_other ui_status_value ui_comm
239 global status_active file_states
242 if {$status_active || ![lock_index read]} return
244 repository_state new_HEAD new_type
245 if {$commit_type eq {amend}
246 && $new_type eq {normal}
247 && $new_HEAD eq $HEAD} {
251 set commit_type $new_type
254 array unset file_states
256 if {![$ui_comm edit modified]
257 || [string trim [$ui_comm get 0.0 end]] eq {}} {
258 if {[load_message GITGUI_MSG]} {
259 } elseif {[load_message MERGE_MSG]} {
260 } elseif {[load_message SQUASH_MSG]} {
262 $ui_comm edit modified false
266 if {$repo_config(gui.trustmtime) eq {true}} {
267 update_status_stage2 {} $final
270 set ui_status_value {Refreshing file status...}
271 set cmd [list git update-index]
273 lappend cmd --unmerged
274 lappend cmd --ignore-missing
275 lappend cmd --refresh
276 set fd_rf [open "| $cmd" r]
277 fconfigure $fd_rf -blocking 0 -translation binary
278 fileevent $fd_rf readable \
279 [list update_status_stage2 $fd_rf $final]
283 proc update_status_stage2 {fd final} {
284 global gitdir PARENT commit_type
285 global ui_index ui_other ui_status_value ui_comm
287 global buf_rdi buf_rdf buf_rlo
291 if {![eof $fd]} return
295 set ls_others [list | git ls-files --others -z \
296 --exclude-per-directory=.gitignore]
297 set info_exclude [file join $gitdir info exclude]
298 if {[file readable $info_exclude]} {
299 lappend ls_others "--exclude-from=$info_exclude"
307 set ui_status_value {Scanning for modified files ...}
308 set fd_di [open "| git diff-index --cached -z $PARENT" r]
309 set fd_df [open "| git diff-files -z" r]
310 set fd_lo [open $ls_others r]
312 fconfigure $fd_di -blocking 0 -translation binary
313 fconfigure $fd_df -blocking 0 -translation binary
314 fconfigure $fd_lo -blocking 0 -translation binary
315 fileevent $fd_di readable [list read_diff_index $fd_di $final]
316 fileevent $fd_df readable [list read_diff_files $fd_df $final]
317 fileevent $fd_lo readable [list read_ls_others $fd_lo $final]
320 proc load_message {file} {
321 global gitdir ui_comm
323 set f [file join $gitdir $file]
324 if {[file isfile $f]} {
325 if {[catch {set fd [open $f r]}]} {
328 set content [string trim [read $fd]]
330 $ui_comm delete 0.0 end
331 $ui_comm insert end $content
337 proc read_diff_index {fd final} {
340 append buf_rdi [read $fd]
342 set n [string length $buf_rdi]
344 set z1 [string first "\0" $buf_rdi $c]
347 set z2 [string first "\0" $buf_rdi $z1]
353 [string range $buf_rdi $z1 $z2] \
354 [string index $buf_rdi [expr $z1 - 2]]_
358 set buf_rdi [string range $buf_rdi $c end]
363 status_eof $fd buf_rdi $final
366 proc read_diff_files {fd final} {
369 append buf_rdf [read $fd]
371 set n [string length $buf_rdf]
373 set z1 [string first "\0" $buf_rdf $c]
376 set z2 [string first "\0" $buf_rdf $z1]
382 [string range $buf_rdf $z1 $z2] \
383 _[string index $buf_rdf [expr $z1 - 2]]
387 set buf_rdf [string range $buf_rdf $c end]
392 status_eof $fd buf_rdf $final
395 proc read_ls_others {fd final} {
398 append buf_rlo [read $fd]
399 set pck [split $buf_rlo "\0"]
400 set buf_rlo [lindex $pck end]
401 foreach p [lrange $pck 0 end-1] {
404 status_eof $fd buf_rlo $final
407 proc status_eof {fd buf final} {
408 global status_active ui_status_value
415 if {[incr status_active -1] == 0} {
419 set ui_status_value $final
424 ######################################################################
429 global ui_diff ui_fname_value ui_fstatus_value ui_index ui_other
431 $ui_diff conf -state normal
432 $ui_diff delete 0.0 end
433 $ui_diff conf -state disabled
435 set ui_fname_value {}
436 set ui_fstatus_value {}
438 $ui_index tag remove in_diff 0.0 end
439 $ui_other tag remove in_diff 0.0 end
442 proc reshow_diff {} {
443 global ui_fname_value ui_status_value file_states
445 if {$ui_fname_value eq {}
446 || [catch {set s $file_states($ui_fname_value)}]} {
449 show_diff $ui_fname_value
453 proc handle_empty_diff {} {
454 global ui_fname_value file_states file_lists
456 set path $ui_fname_value
457 set s $file_states($path)
458 if {[lindex $s 0] ne {_M}} return
460 info_popup "No differences detected.
462 [short_path $path] has no changes.
464 The modification date of this file was updated by another
465 application and you currently have the Trust File Modification
466 Timestamps option enabled, so Git did not automatically detect
467 that there are no content differences in this file.
469 This file will now be removed from the modified files list, to
470 prevent possible confusion.
472 if {[catch {exec git update-index -- $path} err]} {
473 error_popup "Failed to refresh index:\n\n$err"
477 set old_w [mapcol [lindex $file_states($path) 0] $path]
478 set lno [lsearch -sorted $file_lists($old_w) $path]
480 set file_lists($old_w) \
481 [lreplace $file_lists($old_w) $lno $lno]
483 $old_w conf -state normal
484 $old_w delete $lno.0 [expr $lno + 1].0
485 $old_w conf -state disabled
489 proc show_diff {path {w {}} {lno {}}} {
490 global file_states file_lists
491 global PARENT diff_3way diff_active repo_config
492 global ui_diff ui_fname_value ui_fstatus_value ui_status_value
494 if {$diff_active || ![lock_index read]} return
497 if {$w eq {} || $lno == {}} {
498 foreach w [array names file_lists] {
499 set lno [lsearch -sorted $file_lists($w) $path]
506 if {$w ne {} && $lno >= 1} {
507 $w tag add in_diff $lno.0 [expr $lno + 1].0
510 set s $file_states($path)
514 set ui_fname_value [escape_path $path]
515 set ui_fstatus_value [mapdesc $m $path]
516 set ui_status_value "Loading diff of [escape_path $path]..."
518 set cmd [list | git diff-index]
519 lappend cmd --no-color
520 if {$repo_config(gui.diffcontext) > 0} {
521 lappend cmd "-U$repo_config(gui.diffcontext)"
531 set fd [open $path r]
532 set content [read $fd]
537 set ui_status_value "Unable to display [escape_path $path]"
538 error_popup "Error loading file:\n\n$err"
541 $ui_diff conf -state normal
542 $ui_diff insert end $content
543 $ui_diff conf -state disabled
546 set ui_status_value {Ready.}
555 if {[catch {set fd [open $cmd r]} err]} {
558 set ui_status_value "Unable to display [escape_path $path]"
559 error_popup "Error loading diff:\n\n$err"
563 fconfigure $fd -blocking 0 -translation auto
564 fileevent $fd readable [list read_diff $fd]
567 proc read_diff {fd} {
568 global ui_diff ui_status_value diff_3way diff_active
571 while {[gets $fd line] >= 0} {
572 if {[string match {diff --git *} $line]} continue
573 if {[string match {diff --combined *} $line]} continue
574 if {[string match {--- *} $line]} continue
575 if {[string match {+++ *} $line]} continue
576 if {[string match index* $line]} {
577 if {[string first , $line] >= 0} {
582 $ui_diff conf -state normal
584 set x [string index $line 0]
589 default {set tags {}}
592 set x [string range $line 0 1]
594 default {set tags {}}
596 "++" {set tags dp; set x " +"}
597 " +" {set tags {di bold}; set x "++"}
598 "+ " {set tags dni; set x "-+"}
599 "--" {set tags dm; set x " -"}
600 " -" {set tags {dm bold}; set x "--"}
601 "- " {set tags di; set x "+-"}
602 default {set tags {}}
604 set line [string replace $line 0 1 $x]
606 $ui_diff insert end $line $tags
607 $ui_diff insert end "\n"
608 $ui_diff conf -state disabled
615 set ui_status_value {Ready.}
617 if {$repo_config(gui.trustmtime) eq {true}
618 && [$ui_diff index end] eq {2.0}} {
624 ######################################################################
628 proc load_last_commit {} {
629 global HEAD PARENT commit_type ui_comm
631 if {$commit_type eq {amend}} return
632 if {$commit_type ne {normal}} {
633 error_popup "Can't amend a $commit_type commit."
641 set fd [open "| git cat-file commit $HEAD" r]
642 while {[gets $fd line] > 0} {
643 if {[string match {parent *} $line]} {
644 set parent [string range $line 7 end]
648 set msg [string trim [read $fd]]
651 error_popup "Error loading commit data for amend:\n\n$err"
655 if {$parent_count == 0} {
656 set commit_type amend
660 } elseif {$parent_count == 1} {
661 set commit_type amend
663 $ui_comm delete 0.0 end
664 $ui_comm insert end $msg
665 $ui_comm edit modified false
669 error_popup {You can't amend a merge commit.}
674 proc commit_tree {} {
675 global tcl_platform HEAD gitdir commit_type file_states
677 global ui_status_value ui_comm
679 if {![lock_index update]} return
681 # -- Our in memory state should match the repository.
683 repository_state curHEAD cur_type
684 if {$commit_type eq {amend}
685 && $cur_type eq {normal}
686 && $curHEAD eq $HEAD} {
687 } elseif {$commit_type ne $cur_type || $HEAD ne $curHEAD} {
688 error_popup {Last scanned state does not match repository state.
690 Its highly likely that another Git program modified the
691 repository since our last scan. A rescan is required
699 # -- At least one file should differ in the index.
702 foreach path [array names file_states] {
703 set s $file_states($path)
704 switch -glob -- [lindex $s 0] {
708 M? {set files_ready 1; break}
710 error_popup "Unmerged files cannot be committed.
712 File [short_path $path] has merge conflicts.
713 You must resolve them and include the file before committing.
719 error_popup "Unknown file state [lindex $s 0] detected.
721 File [short_path $path] cannot be committed by this program.
727 error_popup {No included files to commit.
729 You must include at least 1 file before you can commit.
735 # -- A message is required.
737 set msg [string trim [$ui_comm get 1.0 end]]
739 error_popup {Please supply a commit message.
741 A good commit message has the following format:
743 - First line: Describe in one sentance what you did.
745 - Remaining lines: Describe why this change is good.
751 # -- Ask the pre-commit hook for the go-ahead.
753 set pchook [file join $gitdir hooks pre-commit]
754 if {$tcl_platform(platform) eq {windows} && [file isfile $pchook]} {
755 set pchook [list sh -c [concat \
756 "if test -x \"$pchook\";" \
757 "then exec \"$pchook\" 2>&1;" \
759 } elseif {[file executable $pchook]} {
760 set pchook [list $pchook |& cat]
765 set ui_status_value {Calling pre-commit hook...}
767 set fd_ph [open "| $pchook" r]
768 fconfigure $fd_ph -blocking 0 -translation binary
769 fileevent $fd_ph readable \
770 [list commit_stage1 $fd_ph $curHEAD $msg]
772 commit_stage2 $curHEAD $msg
776 proc commit_stage1 {fd_ph curHEAD msg} {
777 global pch_error ui_status_value
779 append pch_error [read $fd_ph]
780 fconfigure $fd_ph -blocking 1
782 if {[catch {close $fd_ph}]} {
783 set ui_status_value {Commit declined by pre-commit hook.}
784 hook_failed_popup pre-commit $pch_error
787 commit_stage2 $curHEAD $msg
791 fconfigure $fd_ph -blocking 0
795 proc commit_stage2 {curHEAD msg} {
796 global ui_status_value
798 # -- Write the tree in the background.
800 set ui_status_value {Committing changes...}
801 set fd_wt [open "| git write-tree" r]
802 fileevent $fd_wt readable [list commit_stage3 $fd_wt $curHEAD $msg]
805 proc commit_stage3 {fd_wt curHEAD msg} {
806 global single_commit gitdir HEAD PARENT commit_type tcl_platform
807 global ui_status_value ui_comm
811 if {$tree_id eq {} || [catch {close $fd_wt} err]} {
812 error_popup "write-tree failed:\n\n$err"
813 set ui_status_value {Commit failed.}
818 # -- Create the commit.
820 set cmd [list git commit-tree $tree_id]
822 lappend cmd -p $PARENT
824 if {$commit_type eq {merge}} {
826 set fd_mh [open [file join $gitdir MERGE_HEAD] r]
827 while {[gets $fd_mh merge_head] >= 0} {
828 lappend cmd -p $merge_head
832 error_popup "Loading MERGE_HEAD failed:\n\n$err"
833 set ui_status_value {Commit failed.}
839 # git commit-tree writes to stderr during initial commit.
840 lappend cmd 2>/dev/null
843 if {[catch {set cmt_id [eval exec $cmd]} err]} {
844 error_popup "commit-tree failed:\n\n$err"
845 set ui_status_value {Commit failed.}
850 # -- Update the HEAD ref.
853 if {$commit_type ne {normal}} {
854 append reflogm " ($commit_type)"
856 set i [string first "\n" $msg]
858 append reflogm {: } [string range $msg 0 [expr $i - 1]]
860 append reflogm {: } $msg
862 set cmd [list git update-ref -m $reflogm HEAD $cmt_id $curHEAD]
863 if {[catch {eval exec $cmd} err]} {
864 error_popup "update-ref failed:\n\n$err"
865 set ui_status_value {Commit failed.}
870 # -- Cleanup after ourselves.
872 catch {file delete [file join $gitdir MERGE_HEAD]}
873 catch {file delete [file join $gitdir MERGE_MSG]}
874 catch {file delete [file join $gitdir SQUASH_MSG]}
875 catch {file delete [file join $gitdir GITGUI_MSG]}
877 # -- Let rerere do its thing.
879 if {[file isdirectory [file join $gitdir rr-cache]]} {
880 catch {exec git rerere}
883 # -- Run the post-commit hook.
885 set pchook [file join $gitdir hooks post-commit]
886 if {$tcl_platform(platform) eq {windows} && [file isfile $pchook]} {
887 set pchook [list sh -c [concat \
888 "if test -x \"$pchook\";" \
889 "then exec \"$pchook\";" \
891 } elseif {![file executable $pchook]} {
895 catch {exec $pchook &}
898 $ui_comm delete 0.0 end
899 $ui_comm edit modified false
902 if {$single_commit} do_quit
904 # -- Update status without invoking any git commands.
906 set commit_type normal
910 foreach path [array names file_states] {
911 set s $file_states($path)
916 D? {set m _[string index $m 1]}
920 unset file_states($path)
922 lset file_states($path) 0 $m
929 set ui_status_value \
930 "Changes committed as [string range $cmt_id 0 7]."
933 ######################################################################
937 proc fetch_from {remote} {
938 set w [new_console "fetch $remote" \
939 "Fetching new changes from $remote"]
940 set cmd [list git fetch]
945 proc pull_remote {remote branch} {
946 global HEAD commit_type file_states repo_config
948 if {![lock_index update]} return
950 # -- Our in memory state should match the repository.
952 repository_state curHEAD cur_type
953 if {$commit_type ne $cur_type || $HEAD ne $curHEAD} {
954 error_popup {Last scanned state does not match repository state.
956 Its highly likely that another Git program modified the
957 repository since our last scan. A rescan is required
958 before a pull can be started.
965 # -- No differences should exist before a pull.
967 if {[array size file_states] != 0} {
968 error_popup {Uncommitted but modified files are present.
970 You should not perform a pull with unmodified files in your working
971 directory as Git would be unable to recover from an incorrect merge.
973 Commit or throw away all changes before starting a pull operation.
979 set w [new_console "pull $remote $branch" \
980 "Pulling new changes from branch $branch in $remote"]
981 set cmd [list git pull]
982 if {$repo_config(gui.pullsummary) eq {false}} {
983 lappend cmd --no-summary
987 console_exec $w $cmd [list post_pull_remote $remote $branch]
990 proc post_pull_remote {remote branch success} {
991 global HEAD PARENT commit_type
992 global ui_status_value
996 repository_state HEAD commit_type
998 set $ui_status_value {Ready.}
1001 "Conflicts detected while pulling $branch from $remote."
1005 proc push_to {remote} {
1006 set w [new_console "push $remote" \
1007 "Pushing changes to $remote"]
1008 set cmd [list git push]
1010 console_exec $w $cmd
1013 ######################################################################
1017 proc mapcol {state path} {
1018 global all_cols ui_other
1020 if {[catch {set r $all_cols($state)}]} {
1021 puts "error: no column for state={$state} $path"
1027 proc mapicon {state path} {
1030 if {[catch {set r $all_icons($state)}]} {
1031 puts "error: no icon for state={$state} $path"
1037 proc mapdesc {state path} {
1040 if {[catch {set r $all_descs($state)}]} {
1041 puts "error: no desc for state={$state} $path"
1047 proc escape_path {path} {
1048 regsub -all "\n" $path "\\n" path
1052 proc short_path {path} {
1053 return [escape_path [lindex [file split $path] end]]
1058 proc merge_state {path new_state} {
1059 global file_states next_icon_id
1061 set s0 [string index $new_state 0]
1062 set s1 [string index $new_state 1]
1064 if {[catch {set info $file_states($path)}]} {
1066 set icon n[incr next_icon_id]
1068 set state [lindex $info 0]
1069 set icon [lindex $info 1]
1073 set s0 [string index $state 0]
1074 } elseif {$s0 eq {*}} {
1079 set s1 [string index $state 1]
1080 } elseif {$s1 eq {*}} {
1084 set file_states($path) [list $s0$s1 $icon]
1088 proc display_file {path state} {
1089 global file_states file_lists status_active
1091 set old_m [merge_state $path $state]
1092 if {$status_active} return
1094 set s $file_states($path)
1095 set new_m [lindex $s 0]
1096 set new_w [mapcol $new_m $path]
1097 set old_w [mapcol $old_m $path]
1098 set new_icon [mapicon $new_m $path]
1100 if {$new_w ne $old_w} {
1101 set lno [lsearch -sorted $file_lists($old_w) $path]
1104 $old_w conf -state normal
1105 $old_w delete $lno.0 [expr $lno + 1].0
1106 $old_w conf -state disabled
1109 lappend file_lists($new_w) $path
1110 set file_lists($new_w) [lsort $file_lists($new_w)]
1111 set lno [lsearch -sorted $file_lists($new_w) $path]
1113 $new_w conf -state normal
1114 $new_w image create $lno.0 \
1115 -align center -padx 5 -pady 1 \
1116 -name [lindex $s 1] \
1118 $new_w insert $lno.1 "[escape_path $path]\n"
1119 $new_w conf -state disabled
1120 } elseif {$new_icon ne [mapicon $old_m $path]} {
1121 $new_w conf -state normal
1122 $new_w image conf [lindex $s 1] -image $new_icon
1123 $new_w conf -state disabled
1127 proc display_all_files {} {
1128 global ui_index ui_other file_states file_lists
1130 $ui_index conf -state normal
1131 $ui_other conf -state normal
1133 $ui_index delete 0.0 end
1134 $ui_other delete 0.0 end
1136 set file_lists($ui_index) [list]
1137 set file_lists($ui_other) [list]
1139 foreach path [lsort [array names file_states]] {
1140 set s $file_states($path)
1142 set w [mapcol $m $path]
1143 lappend file_lists($w) $path
1144 $w image create end \
1145 -align center -padx 5 -pady 1 \
1146 -name [lindex $s 1] \
1147 -image [mapicon $m $path]
1148 $w insert end "[escape_path $path]\n"
1151 $ui_index conf -state disabled
1152 $ui_other conf -state disabled
1155 proc update_index {pathList} {
1156 global update_index_cp update_index_rsd ui_status_value
1158 if {![lock_index update]} return
1160 set update_index_cp 0
1161 set update_index_rsd 0
1162 set pathList [lsort $pathList]
1163 set totalCnt [llength $pathList]
1164 set batch [expr {int($totalCnt * .01) + 1}]
1165 if {$batch > 25} {set batch 25}
1167 set ui_status_value "Including files ... 0/$totalCnt 0%"
1168 set ui_status_value [format \
1169 "Including files ... %i/%i files (%.2f%%)" \
1173 set fd [open "| git update-index --add --remove -z --stdin" w]
1174 fconfigure $fd -blocking 0 -translation binary
1175 fileevent $fd writable [list \
1176 write_update_index \
1184 proc write_update_index {fd pathList totalCnt batch} {
1185 global update_index_cp update_index_rsd ui_status_value
1186 global file_states ui_fname_value
1188 if {$update_index_cp >= $totalCnt} {
1191 if {$update_index_rsd} {
1194 set ui_status_value {Ready.}
1199 for {set i $batch} \
1200 {$update_index_cp < $totalCnt && $i > 0} \
1202 set path [lindex $pathList $update_index_cp]
1203 incr update_index_cp
1205 switch -- [lindex $file_states($path) 0] {
1215 puts -nonewline $fd $path
1216 puts -nonewline $fd "\0"
1217 display_file $path $new
1218 if {$ui_fname_value eq $path} {
1219 set update_index_rsd 1
1223 set ui_status_value [format \
1224 "Including files ... %i/%i files (%.2f%%)" \
1227 [expr {100.0 * $update_index_cp / $totalCnt}]]
1230 ######################################################################
1232 ## remote management
1234 proc load_all_remotes {} {
1235 global gitdir all_remotes repo_config
1237 set all_remotes [list]
1238 set rm_dir [file join $gitdir remotes]
1239 if {[file isdirectory $rm_dir]} {
1240 set all_remotes [concat $all_remotes [glob \
1244 -directory $rm_dir *]]
1247 foreach line [array names repo_config remote.*.url] {
1248 if {[regexp ^remote\.(.*)\.url\$ $line line name]} {
1249 lappend all_remotes $name
1253 set all_remotes [lsort -unique $all_remotes]
1256 proc populate_remote_menu {m pfx op} {
1259 foreach remote $all_remotes {
1260 $m add command -label "$pfx $remote..." \
1261 -command [list $op $remote] \
1266 proc populate_pull_menu {m} {
1267 global gitdir repo_config all_remotes disable_on_lock
1269 foreach remote $all_remotes {
1271 if {[array get repo_config remote.$remote.url] ne {}} {
1272 if {[array get repo_config remote.$remote.fetch] ne {}} {
1273 regexp {^([^:]+):} \
1274 [lindex $repo_config(remote.$remote.fetch) 0] \
1279 set fd [open [file join $gitdir remotes $remote] r]
1280 while {[gets $fd line] >= 0} {
1281 if {[regexp {^Pull:[ \t]*([^:]+):} $line line rb]} {
1290 regsub ^refs/heads/ $rb {} rb_short
1291 if {$rb_short ne {}} {
1293 -label "Branch $rb_short from $remote..." \
1294 -command [list pull_remote $remote $rb] \
1296 lappend disable_on_lock \
1297 [list $m entryconf [$m index last] -state]
1302 ######################################################################
1307 #define mask_width 14
1308 #define mask_height 15
1309 static unsigned char mask_bits[] = {
1310 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1311 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1312 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1315 image create bitmap file_plain -background white -foreground black -data {
1316 #define plain_width 14
1317 #define plain_height 15
1318 static unsigned char plain_bits[] = {
1319 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1320 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1321 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1322 } -maskdata $filemask
1324 image create bitmap file_mod -background white -foreground blue -data {
1325 #define mod_width 14
1326 #define mod_height 15
1327 static unsigned char mod_bits[] = {
1328 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1329 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1330 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1331 } -maskdata $filemask
1333 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1334 #define file_fulltick_width 14
1335 #define file_fulltick_height 15
1336 static unsigned char file_fulltick_bits[] = {
1337 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1338 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1339 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1340 } -maskdata $filemask
1342 image create bitmap file_parttick -background white -foreground "#005050" -data {
1343 #define parttick_width 14
1344 #define parttick_height 15
1345 static unsigned char parttick_bits[] = {
1346 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1347 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
1348 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1349 } -maskdata $filemask
1351 image create bitmap file_question -background white -foreground black -data {
1352 #define file_question_width 14
1353 #define file_question_height 15
1354 static unsigned char file_question_bits[] = {
1355 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1356 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1357 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1358 } -maskdata $filemask
1360 image create bitmap file_removed -background white -foreground red -data {
1361 #define file_removed_width 14
1362 #define file_removed_height 15
1363 static unsigned char file_removed_bits[] = {
1364 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1365 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1366 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1367 } -maskdata $filemask
1369 image create bitmap file_merge -background white -foreground blue -data {
1370 #define file_merge_width 14
1371 #define file_merge_height 15
1372 static unsigned char file_merge_bits[] = {
1373 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1374 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1375 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1376 } -maskdata $filemask
1378 set ui_index .vpane.files.index.list
1379 set ui_other .vpane.files.other.list
1380 set max_status_desc 0
1382 {__ i plain "Unmodified"}
1383 {_M i mod "Modified"}
1384 {M_ i fulltick "Checked in"}
1385 {MM i parttick "Partially included"}
1387 {_O o plain "Untracked"}
1388 {A_ o fulltick "Added"}
1389 {AM o parttick "Partially added"}
1390 {AD o question "Added (but now gone)"}
1392 {_D i question "Missing"}
1393 {D_ i removed "Removed"}
1394 {DD i removed "Removed"}
1395 {DO i removed "Removed (still exists)"}
1397 {UM i merge "Merge conflicts"}
1398 {U_ i merge "Merge conflicts"}
1400 if {$max_status_desc < [string length [lindex $i 3]]} {
1401 set max_status_desc [string length [lindex $i 3]]
1403 if {[lindex $i 1] eq {i}} {
1404 set all_cols([lindex $i 0]) $ui_index
1406 set all_cols([lindex $i 0]) $ui_other
1408 set all_icons([lindex $i 0]) file_[lindex $i 2]
1409 set all_descs([lindex $i 0]) [lindex $i 3]
1413 ######################################################################
1418 global tcl_platform tk_library
1419 if {$tcl_platform(platform) eq {unix}
1420 && $tcl_platform(os) eq {Darwin}
1421 && [string match /Library/Frameworks/* $tk_library]} {
1427 proc bind_button3 {w cmd} {
1428 bind $w <Any-Button-3> $cmd
1430 bind $w <Control-Button-1> $cmd
1434 proc incr_font_size {font {amt 1}} {
1435 set sz [font configure $font -size]
1437 font configure $font -size $sz
1438 font configure ${font}bold -size $sz
1441 proc hook_failed_popup {hook msg} {
1442 global gitdir appname
1448 label $w.m.l1 -text "$hook hook failed:" \
1453 -background white -borderwidth 1 \
1455 -width 80 -height 10 \
1457 -yscrollcommand [list $w.m.sby set]
1459 -text {You must correct the above errors before committing.} \
1463 scrollbar $w.m.sby -command [list $w.m.t yview]
1464 pack $w.m.l1 -side top -fill x
1465 pack $w.m.l2 -side bottom -fill x
1466 pack $w.m.sby -side right -fill y
1467 pack $w.m.t -side left -fill both -expand 1
1468 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
1470 $w.m.t insert 1.0 $msg
1471 $w.m.t conf -state disabled
1473 button $w.ok -text OK \
1476 -command "destroy $w"
1477 pack $w.ok -side bottom
1479 bind $w <Visibility> "grab $w; focus $w"
1480 bind $w <Key-Return> "destroy $w"
1481 wm title $w "$appname ([lindex [file split \
1482 [file normalize [file dirname $gitdir]]] \
1487 set next_console_id 0
1489 proc new_console {short_title long_title} {
1490 global next_console_id console_data
1491 set w .console[incr next_console_id]
1492 set console_data($w) [list $short_title $long_title]
1493 return [console_init $w]
1496 proc console_init {w} {
1497 global console_cr console_data
1498 global gitdir appname M1B
1500 set console_cr($w) 1.0
1503 label $w.m.l1 -text "[lindex $console_data($w) 1]:" \
1508 -background white -borderwidth 1 \
1510 -width 80 -height 10 \
1513 -yscrollcommand [list $w.m.sby set]
1514 label $w.m.s -anchor w \
1517 scrollbar $w.m.sby -command [list $w.m.t yview]
1518 pack $w.m.l1 -side top -fill x
1519 pack $w.m.s -side bottom -fill x
1520 pack $w.m.sby -side right -fill y
1521 pack $w.m.t -side left -fill both -expand 1
1522 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
1524 menu $w.ctxm -tearoff 0
1525 $w.ctxm add command -label "Copy" \
1527 -command "tk_textCopy $w.m.t"
1528 $w.ctxm add command -label "Select All" \
1530 -command "$w.m.t tag add sel 0.0 end"
1531 $w.ctxm add command -label "Copy All" \
1534 $w.m.t tag add sel 0.0 end
1536 $w.m.t tag remove sel 0.0 end
1539 button $w.ok -text {Running...} \
1543 -command "destroy $w"
1544 pack $w.ok -side bottom
1546 bind_button3 $w.m.t "tk_popup $w.ctxm %X %Y"
1547 bind $w.m.t <$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
1548 bind $w.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
1549 bind $w <Visibility> "focus $w"
1550 wm title $w "$appname ([lindex [file split \
1551 [file normalize [file dirname $gitdir]]] \
1552 end]): [lindex $console_data($w) 0]"
1556 proc console_exec {w cmd {after {}}} {
1559 # -- Windows tosses the enviroment when we exec our child.
1560 # But most users need that so we have to relogin. :-(
1562 if {$tcl_platform(platform) eq {windows}} {
1563 set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"]
1566 # -- Tcl won't let us redirect both stdout and stderr to
1567 # the same pipe. So pass it through cat...
1569 set cmd [concat | $cmd |& cat]
1571 set fd_f [open $cmd r]
1572 fconfigure $fd_f -blocking 0 -translation binary
1573 fileevent $fd_f readable [list console_read $w $fd_f $after]
1576 proc console_read {w fd after} {
1577 global console_cr console_data
1581 if {![winfo exists $w]} {console_init $w}
1582 $w.m.t conf -state normal
1584 set n [string length $buf]
1586 set cr [string first "\r" $buf $c]
1587 set lf [string first "\n" $buf $c]
1588 if {$cr < 0} {set cr [expr $n + 1]}
1589 if {$lf < 0} {set lf [expr $n + 1]}
1592 $w.m.t insert end [string range $buf $c $lf]
1593 set console_cr($w) [$w.m.t index {end -1c}]
1597 $w.m.t delete $console_cr($w) end
1598 $w.m.t insert end "\n"
1599 $w.m.t insert end [string range $buf $c $cr]
1604 $w.m.t conf -state disabled
1608 fconfigure $fd -blocking 1
1610 if {[catch {close $fd}]} {
1611 if {![winfo exists $w]} {console_init $w}
1612 $w.m.s conf -background red -text {Error: Command Failed}
1613 $w.ok conf -text Close
1614 $w.ok conf -state normal
1616 } elseif {[winfo exists $w]} {
1617 $w.m.s conf -background green -text {Success}
1618 $w.ok conf -text Close
1619 $w.ok conf -state normal
1622 array unset console_cr $w
1623 array unset console_data $w
1625 uplevel #0 $after $ok
1629 fconfigure $fd -blocking 0
1632 ######################################################################
1636 set starting_gitk_msg {Please wait... Starting gitk...}
1639 global tcl_platform ui_status_value starting_gitk_msg
1641 set ui_status_value $starting_gitk_msg
1643 if {$ui_status_value eq $starting_gitk_msg} {
1644 set ui_status_value {Ready.}
1648 if {$tcl_platform(platform) eq {windows}} {
1656 set w [new_console "repack" "Repacking the object database"]
1657 set cmd [list git repack]
1660 console_exec $w $cmd
1666 global gitdir ui_comm is_quitting repo_config
1668 if {$is_quitting} return
1671 # -- Stash our current commit buffer.
1673 set save [file join $gitdir GITGUI_MSG]
1674 set msg [string trim [$ui_comm get 0.0 end]]
1675 if {[$ui_comm edit modified] && $msg ne {}} {
1677 set fd [open $save w]
1678 puts $fd [string trim [$ui_comm get 0.0 end]]
1681 } elseif {$msg eq {} && [file exists $save]} {
1685 # -- Stash our current window geometry into this repository.
1687 set cfg_geometry [list]
1688 lappend cfg_geometry [wm geometry .]
1689 lappend cfg_geometry [lindex [.vpane sash coord 0] 1]
1690 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 0]
1691 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
1694 if {$cfg_geometry ne $rc_geometry} {
1695 catch {exec git repo-config gui.geometry $cfg_geometry}
1705 proc do_include_all {} {
1708 if {![lock_index begin-update]} return
1711 foreach path [array names file_states] {
1712 set s $file_states($path)
1718 _D {lappend pathList $path}
1721 if {$pathList eq {}} {
1724 update_index $pathList
1728 set GIT_COMMITTER_IDENT {}
1730 proc do_signoff {} {
1731 global ui_comm GIT_COMMITTER_IDENT
1733 if {$GIT_COMMITTER_IDENT eq {}} {
1734 if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
1735 error_popup "Unable to obtain your identity:\n\n$err"
1738 if {![regexp {^(.*) [0-9]+ [-+0-9]+$} \
1739 $me me GIT_COMMITTER_IDENT]} {
1740 error_popup "Invalid GIT_COMMITTER_IDENT:\n\n$me"
1745 set sob "Signed-off-by: $GIT_COMMITTER_IDENT"
1746 set last [$ui_comm get {end -1c linestart} {end -1c}]
1747 if {$last ne $sob} {
1748 $ui_comm edit separator
1750 && ![regexp {^[A-Z][A-Za-z]*-[A-Za-z-]+: *} $last]} {
1751 $ui_comm insert end "\n"
1753 $ui_comm insert end "\n$sob"
1754 $ui_comm edit separator
1759 proc do_amend_last {} {
1767 proc do_options {} {
1768 global appname gitdir font_descs
1769 global repo_config global_config
1770 global repo_config_new global_config_new
1772 array unset repo_config_new
1773 array unset global_config_new
1774 foreach name [array names repo_config] {
1775 set repo_config_new($name) $repo_config($name)
1778 foreach name [array names repo_config] {
1780 gui.diffcontext {continue}
1782 set repo_config_new($name) $repo_config($name)
1784 foreach name [array names global_config] {
1785 set global_config_new($name) $global_config($name)
1787 set reponame [lindex [file split \
1788 [file normalize [file dirname $gitdir]]] \
1791 set w .options_editor
1793 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
1795 label $w.header -text "$appname Options" \
1797 pack $w.header -side top -fill x
1800 button $w.buttons.restore -text {Restore Defaults} \
1802 -command do_restore_defaults
1803 pack $w.buttons.restore -side left
1804 button $w.buttons.save -text Save \
1806 -command [list do_save_config $w]
1807 pack $w.buttons.save -side right
1808 button $w.buttons.cancel -text {Cancel} \
1810 -command [list destroy $w]
1811 pack $w.buttons.cancel -side right
1812 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
1814 labelframe $w.repo -text "$reponame Repository" \
1816 -relief raised -borderwidth 2
1817 labelframe $w.global -text {Global (All Repositories)} \
1819 -relief raised -borderwidth 2
1820 pack $w.repo -side left -fill both -expand 1 -pady 5 -padx 5
1821 pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
1824 {b pullsummary {Show Pull Summary}}
1825 {b trustmtime {Trust File Modification Timestamps}}
1826 {i diffcontext {Number of Diff Context Lines}}
1828 set type [lindex $option 0]
1829 set name [lindex $option 1]
1830 set text [lindex $option 2]
1831 foreach f {repo global} {
1834 checkbutton $w.$f.$name -text $text \
1835 -variable ${f}_config_new(gui.$name) \
1839 pack $w.$f.$name -side top -anchor w
1843 label $w.$f.$name.l -text "$text:" -font font_ui
1844 pack $w.$f.$name.l -side left -anchor w -fill x
1845 spinbox $w.$f.$name.v \
1846 -textvariable ${f}_config_new(gui.$name) \
1847 -from 1 -to 99 -increment 1 \
1850 pack $w.$f.$name.v -side right -anchor e
1851 pack $w.$f.$name -side top -anchor w -fill x
1857 set all_fonts [lsort [font families]]
1858 foreach option $font_descs {
1859 set name [lindex $option 0]
1860 set font [lindex $option 1]
1861 set text [lindex $option 2]
1863 set global_config_new(gui.$font^^family) \
1864 [font configure $font -family]
1865 set global_config_new(gui.$font^^size) \
1866 [font configure $font -size]
1868 frame $w.global.$name
1869 label $w.global.$name.l -text "$text:" -font font_ui
1870 pack $w.global.$name.l -side left -anchor w -fill x
1871 eval tk_optionMenu $w.global.$name.family \
1872 global_config_new(gui.$font^^family) \
1874 spinbox $w.global.$name.size \
1875 -textvariable global_config_new(gui.$font^^size) \
1876 -from 2 -to 80 -increment 1 \
1879 pack $w.global.$name.size -side right -anchor e
1880 pack $w.global.$name.family -side right -anchor e
1881 pack $w.global.$name -side top -anchor w -fill x
1884 bind $w <Visibility> "grab $w; focus $w"
1885 bind $w <Key-Escape> "destroy $w"
1886 wm title $w "$appname ($reponame): Options"
1890 proc do_restore_defaults {} {
1891 global font_descs default_config repo_config
1892 global repo_config_new global_config_new
1894 foreach name [array names default_config] {
1895 set repo_config_new($name) $default_config($name)
1896 set global_config_new($name) $default_config($name)
1899 foreach option $font_descs {
1900 set name [lindex $option 0]
1901 set repo_config(gui.$name) $default_config(gui.$name)
1905 foreach option $font_descs {
1906 set name [lindex $option 0]
1907 set font [lindex $option 1]
1908 set global_config_new(gui.$font^^family) \
1909 [font configure $font -family]
1910 set global_config_new(gui.$font^^size) \
1911 [font configure $font -size]
1915 proc do_save_config {w} {
1916 if {[catch {save_config} err]} {
1917 error_popup "Failed to completely save options:\n\n$err"
1923 # shift == 1: left click
1925 proc click {w x y shift wx wy} {
1926 global ui_index ui_other file_lists
1928 set pos [split [$w index @$x,$y] .]
1929 set lno [lindex $pos 0]
1930 set col [lindex $pos 1]
1931 set path [lindex $file_lists($w) [expr $lno - 1]]
1932 if {$path eq {}} return
1934 if {$col > 0 && $shift == 1} {
1935 show_diff $path $w $lno
1939 proc unclick {w x y} {
1942 set pos [split [$w index @$x,$y] .]
1943 set lno [lindex $pos 0]
1944 set col [lindex $pos 1]
1945 set path [lindex $file_lists($w) [expr $lno - 1]]
1946 if {$path eq {}} return
1949 update_index [list $path]
1953 ######################################################################
1957 set cursor_ptr arrow
1958 font create font_diff -family Courier -size 10
1962 eval font configure font_ui [font actual [.dummy cget -font]]
1966 font create font_uibold
1967 font create font_diffbold
1971 if {$tcl_platform(platform) eq {windows}} {
1974 } elseif {[is_MacOSX]} {
1979 proc apply_config {} {
1980 global repo_config font_descs
1982 foreach option $font_descs {
1983 set name [lindex $option 0]
1984 set font [lindex $option 1]
1986 foreach {cn cv} $repo_config(gui.$name) {
1987 font configure $font $cn $cv
1990 error_popup "Invalid font specified in gui.$name:\n\n$err"
1992 foreach {cn cv} [font configure $font] {
1993 font configure ${font}bold $cn $cv
1995 font configure ${font}bold -weight bold
1999 set default_config(gui.trustmtime) false
2000 set default_config(gui.pullsummary) true
2001 set default_config(gui.diffcontext) 5
2002 set default_config(gui.fontui) [font configure font_ui]
2003 set default_config(gui.fontdiff) [font configure font_diff]
2005 {fontui font_ui {Main Font}}
2006 {fontdiff font_diff {Diff/Console Font}}
2011 ######################################################################
2016 menu .mbar -tearoff 0
2017 .mbar add cascade -label Project -menu .mbar.project
2018 .mbar add cascade -label Edit -menu .mbar.edit
2019 .mbar add cascade -label Commit -menu .mbar.commit
2020 if {!$single_commit} {
2021 .mbar add cascade -label Fetch -menu .mbar.fetch
2022 .mbar add cascade -label Pull -menu .mbar.pull
2023 .mbar add cascade -label Push -menu .mbar.push
2025 . configure -menu .mbar
2029 .mbar.project add command -label Visualize \
2032 if {!$single_commit} {
2033 .mbar.project add command -label {Repack Database} \
2034 -command do_repack \
2037 .mbar.project add command -label Quit \
2039 -accelerator $M1T-Q \
2045 .mbar.edit add command -label Undo \
2046 -command {catch {[focus] edit undo}} \
2047 -accelerator $M1T-Z \
2049 .mbar.edit add command -label Redo \
2050 -command {catch {[focus] edit redo}} \
2051 -accelerator $M1T-Y \
2053 .mbar.edit add separator
2054 .mbar.edit add command -label Cut \
2055 -command {catch {tk_textCut [focus]}} \
2056 -accelerator $M1T-X \
2058 .mbar.edit add command -label Copy \
2059 -command {catch {tk_textCopy [focus]}} \
2060 -accelerator $M1T-C \
2062 .mbar.edit add command -label Paste \
2063 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2064 -accelerator $M1T-V \
2066 .mbar.edit add command -label Delete \
2067 -command {catch {[focus] delete sel.first sel.last}} \
2070 .mbar.edit add separator
2071 .mbar.edit add command -label {Select All} \
2072 -command {catch {[focus] tag add sel 0.0 end}} \
2073 -accelerator $M1T-A \
2075 .mbar.edit add separator
2076 .mbar.edit add command -label {Options...} \
2077 -command do_options \
2082 .mbar.commit add command -label Rescan \
2083 -command do_rescan \
2086 lappend disable_on_lock \
2087 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2088 .mbar.commit add command -label {Amend Last Commit} \
2089 -command do_amend_last \
2091 lappend disable_on_lock \
2092 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2093 .mbar.commit add command -label {Include All Files} \
2094 -command do_include_all \
2095 -accelerator $M1T-I \
2097 lappend disable_on_lock \
2098 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2099 .mbar.commit add command -label {Sign Off} \
2100 -command do_signoff \
2101 -accelerator $M1T-S \
2103 .mbar.commit add command -label Commit \
2104 -command do_commit \
2105 -accelerator $M1T-Return \
2107 lappend disable_on_lock \
2108 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2110 if {!$single_commit} {
2121 # -- Main Window Layout
2122 panedwindow .vpane -orient vertical
2123 panedwindow .vpane.files -orient horizontal
2124 .vpane add .vpane.files -sticky nsew -height 100 -width 400
2125 pack .vpane -anchor n -side top -fill both -expand 1
2127 # -- Index File List
2128 frame .vpane.files.index -height 100 -width 400
2129 label .vpane.files.index.title -text {Modified Files} \
2132 text $ui_index -background white -borderwidth 0 \
2133 -width 40 -height 10 \
2135 -cursor $cursor_ptr \
2136 -yscrollcommand {.vpane.files.index.sb set} \
2138 scrollbar .vpane.files.index.sb -command [list $ui_index yview]
2139 pack .vpane.files.index.title -side top -fill x
2140 pack .vpane.files.index.sb -side right -fill y
2141 pack $ui_index -side left -fill both -expand 1
2142 .vpane.files add .vpane.files.index -sticky nsew
2144 # -- Other (Add) File List
2145 frame .vpane.files.other -height 100 -width 100
2146 label .vpane.files.other.title -text {Untracked Files} \
2149 text $ui_other -background white -borderwidth 0 \
2150 -width 40 -height 10 \
2152 -cursor $cursor_ptr \
2153 -yscrollcommand {.vpane.files.other.sb set} \
2155 scrollbar .vpane.files.other.sb -command [list $ui_other yview]
2156 pack .vpane.files.other.title -side top -fill x
2157 pack .vpane.files.other.sb -side right -fill y
2158 pack $ui_other -side left -fill both -expand 1
2159 .vpane.files add .vpane.files.other -sticky nsew
2161 $ui_index tag conf in_diff -font font_uibold
2162 $ui_other tag conf in_diff -font font_uibold
2164 # -- Diff and Commit Area
2165 frame .vpane.lower -height 300 -width 400
2166 frame .vpane.lower.commarea
2167 frame .vpane.lower.diff -relief sunken -borderwidth 1
2168 pack .vpane.lower.commarea -side top -fill x
2169 pack .vpane.lower.diff -side bottom -fill both -expand 1
2170 .vpane add .vpane.lower -stick nsew
2172 # -- Commit Area Buttons
2173 frame .vpane.lower.commarea.buttons
2174 label .vpane.lower.commarea.buttons.l -text {} \
2178 pack .vpane.lower.commarea.buttons.l -side top -fill x
2179 pack .vpane.lower.commarea.buttons -side left -fill y
2181 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
2182 -command do_rescan \
2184 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
2185 lappend disable_on_lock \
2186 {.vpane.lower.commarea.buttons.rescan conf -state}
2188 button .vpane.lower.commarea.buttons.amend -text {Amend Last} \
2189 -command do_amend_last \
2191 pack .vpane.lower.commarea.buttons.amend -side top -fill x
2192 lappend disable_on_lock \
2193 {.vpane.lower.commarea.buttons.amend conf -state}
2195 button .vpane.lower.commarea.buttons.incall -text {Include All} \
2196 -command do_include_all \
2198 pack .vpane.lower.commarea.buttons.incall -side top -fill x
2199 lappend disable_on_lock \
2200 {.vpane.lower.commarea.buttons.incall conf -state}
2202 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
2203 -command do_signoff \
2205 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
2207 button .vpane.lower.commarea.buttons.commit -text {Commit} \
2208 -command do_commit \
2210 pack .vpane.lower.commarea.buttons.commit -side top -fill x
2211 lappend disable_on_lock \
2212 {.vpane.lower.commarea.buttons.commit conf -state}
2214 # -- Commit Message Buffer
2215 frame .vpane.lower.commarea.buffer
2216 set ui_comm .vpane.lower.commarea.buffer.t
2217 set ui_coml .vpane.lower.commarea.buffer.l
2218 label $ui_coml -text {Commit Message:} \
2222 trace add variable commit_type write {uplevel #0 {
2223 switch -glob $commit_type \
2224 initial {$ui_coml conf -text {Initial Commit Message:}} \
2225 amend {$ui_coml conf -text {Amended Commit Message:}} \
2226 merge {$ui_coml conf -text {Merge Commit Message:}} \
2227 * {$ui_coml conf -text {Commit Message:}}
2229 text $ui_comm -background white -borderwidth 1 \
2232 -autoseparators true \
2234 -width 75 -height 9 -wrap none \
2236 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
2237 scrollbar .vpane.lower.commarea.buffer.sby \
2238 -command [list $ui_comm yview]
2239 pack $ui_coml -side top -fill x
2240 pack .vpane.lower.commarea.buffer.sby -side right -fill y
2241 pack $ui_comm -side left -fill y
2242 pack .vpane.lower.commarea.buffer -side left -fill y
2244 # -- Commit Message Buffer Context Menu
2246 menu $ui_comm.ctxm -tearoff 0
2247 $ui_comm.ctxm add command -label "Cut" \
2249 -command "tk_textCut $ui_comm"
2250 $ui_comm.ctxm add command -label "Copy" \
2252 -command "tk_textCopy $ui_comm"
2253 $ui_comm.ctxm add command -label "Paste" \
2255 -command "tk_textPaste $ui_comm"
2256 $ui_comm.ctxm add command -label "Delete" \
2258 -command "$ui_comm delete sel.first sel.last"
2259 $ui_comm.ctxm add separator
2260 $ui_comm.ctxm add command -label "Select All" \
2262 -command "$ui_comm tag add sel 0.0 end"
2263 $ui_comm.ctxm add command -label "Copy All" \
2266 $ui_comm tag add sel 0.0 end
2267 tk_textCopy $ui_comm
2268 $ui_comm tag remove sel 0.0 end
2270 $ui_comm.ctxm add separator
2271 $ui_comm.ctxm add command -label "Sign Off" \
2274 bind_button3 $ui_comm "tk_popup $ui_comm.ctxm %X %Y"
2277 set ui_fname_value {}
2278 set ui_fstatus_value {}
2279 frame .vpane.lower.diff.header -background orange
2280 label .vpane.lower.diff.header.l1 -text {File:} \
2281 -background orange \
2283 label .vpane.lower.diff.header.l2 -textvariable ui_fname_value \
2284 -background orange \
2288 label .vpane.lower.diff.header.l3 -text {Status:} \
2289 -background orange \
2291 label .vpane.lower.diff.header.l4 -textvariable ui_fstatus_value \
2292 -background orange \
2293 -width $max_status_desc \
2297 pack .vpane.lower.diff.header.l1 -side left
2298 pack .vpane.lower.diff.header.l2 -side left -fill x
2299 pack .vpane.lower.diff.header.l4 -side right
2300 pack .vpane.lower.diff.header.l3 -side right
2303 frame .vpane.lower.diff.body
2304 set ui_diff .vpane.lower.diff.body.t
2305 text $ui_diff -background white -borderwidth 0 \
2306 -width 80 -height 15 -wrap none \
2308 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
2309 -yscrollcommand {.vpane.lower.diff.body.sby set} \
2311 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
2312 -command [list $ui_diff xview]
2313 scrollbar .vpane.lower.diff.body.sby -orient vertical \
2314 -command [list $ui_diff yview]
2315 pack .vpane.lower.diff.body.sbx -side bottom -fill x
2316 pack .vpane.lower.diff.body.sby -side right -fill y
2317 pack $ui_diff -side left -fill both -expand 1
2318 pack .vpane.lower.diff.header -side top -fill x
2319 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
2321 $ui_diff tag conf dm -foreground red
2322 $ui_diff tag conf dp -foreground blue
2323 $ui_diff tag conf di -foreground {#00a000}
2324 $ui_diff tag conf dni -foreground {#a000a0}
2325 $ui_diff tag conf da -font font_diffbold
2326 $ui_diff tag conf bold -font font_diffbold
2328 # -- Diff Body Context Menu
2330 menu $ui_diff.ctxm -tearoff 0
2331 $ui_diff.ctxm add command -label "Copy" \
2333 -command "tk_textCopy $ui_diff"
2334 $ui_diff.ctxm add command -label "Select All" \
2336 -command "$ui_diff tag add sel 0.0 end"
2337 $ui_diff.ctxm add command -label "Copy All" \
2340 $ui_diff tag add sel 0.0 end
2341 tk_textCopy $ui_diff
2342 $ui_diff tag remove sel 0.0 end
2344 $ui_diff.ctxm add separator
2345 $ui_diff.ctxm add command -label "Decrease Font Size" \
2347 -command {incr_font_size font_diff -1}
2348 $ui_diff.ctxm add command -label "Increase Font Size" \
2350 -command {incr_font_size font_diff 1}
2351 $ui_diff.ctxm add separator
2352 $ui_diff.ctxm add command -label "Show Less Context" \
2354 -command {if {$ui_fname_value ne {}
2355 && $repo_config(gui.diffcontext) >= 2} {
2356 incr repo_config(gui.diffcontext) -1
2359 $ui_diff.ctxm add command -label "Show More Context" \
2361 -command {if {$ui_fname_value ne {}} {
2362 incr repo_config(gui.diffcontext)
2365 $ui_diff.ctxm add separator
2366 $ui_diff.ctxm add command -label {Options...} \
2369 bind_button3 $ui_diff "tk_popup $ui_diff.ctxm %X %Y"
2372 set ui_status_value {Initializing...}
2373 label .status -textvariable ui_status_value \
2379 pack .status -anchor w -side bottom -fill x
2383 set gm $repo_config(gui.geometry)
2384 wm geometry . [lindex $gm 0]
2385 .vpane sash place 0 \
2386 [lindex [.vpane sash coord 0] 0] \
2388 .vpane.files sash place 0 \
2390 [lindex [.vpane.files sash coord 0] 1]
2395 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
2396 bind $ui_comm <$M1B-Key-i> {do_include_all;break}
2397 bind $ui_comm <$M1B-Key-I> {do_include_all;break}
2398 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
2399 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
2400 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
2401 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
2402 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
2403 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
2404 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
2405 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
2407 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
2408 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
2409 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
2410 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
2411 bind $ui_diff <$M1B-Key-v> {break}
2412 bind $ui_diff <$M1B-Key-V> {break}
2413 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
2414 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
2415 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
2416 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
2417 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
2418 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
2420 bind . <Destroy> do_quit
2421 bind all <Key-F5> do_rescan
2422 bind all <$M1B-Key-r> do_rescan
2423 bind all <$M1B-Key-R> do_rescan
2424 bind . <$M1B-Key-s> do_signoff
2425 bind . <$M1B-Key-S> do_signoff
2426 bind . <$M1B-Key-i> do_include_all
2427 bind . <$M1B-Key-I> do_include_all
2428 bind . <$M1B-Key-Return> do_commit
2429 bind all <$M1B-Key-q> do_quit
2430 bind all <$M1B-Key-Q> do_quit
2431 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2432 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2433 foreach i [list $ui_index $ui_other] {
2434 bind $i <Button-1> {click %W %x %y 1 %X %Y; break}
2435 bind $i <ButtonRelease-1> {unclick %W %x %y; break}
2436 bind_button3 $i {click %W %x %y 3 %X %Y; break}
2440 set file_lists($ui_index) [list]
2441 set file_lists($ui_other) [list]
2443 wm title . "$appname ([file normalize [file dirname $gitdir]])"
2444 focus -force $ui_comm
2445 if {!$single_commit} {
2447 populate_remote_menu .mbar.fetch From fetch_from
2448 populate_remote_menu .mbar.push To push_to
2449 populate_pull_menu .mbar.pull
2451 after 1 update_status