2 # Tcl ignores the next line -*- tcl -*- \
3 if test "z$*" = zversion \
4 ||
test "z$*" = z--version
; \
6 echo 'git-gui version @@GITGUI_VERSION@@'; \
11 set appvers
{@@GITGUI_VERSION@@
}
13 Copyright ©
2006, 2007 Shawn Pearce
, et. al.
15 This program is free software
; you can redistribute it and
/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation
; either version
2 of the License
, or
18 (at your option
) any later version.
20 This program is distributed
in the hope that it will be useful
,
21 but WITHOUT ANY WARRANTY
; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License
for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program
; if not
, write to the Free Software
27 Foundation
, Inc.
, 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
}
29 ######################################################################
31 ## Tcl/Tk sanity check
33 if {[catch
{package require Tcl
8.4} err
]
34 ||
[catch
{package require Tk
8.4} err
]
40 -title "git-gui: fatal error" \
45 ######################################################################
47 ## enable verbose loading?
49 if {![catch
{set _verbose
$env(GITGUI_VERBOSE
)}]} {
51 rename auto_load real__auto_load
52 proc auto_load
{name args
} {
53 puts stderr
"auto_load $name"
54 return [uplevel
1 real__auto_load
$name $args]
56 rename
source real__source
58 puts stderr
"source $name"
59 uplevel
1 real__source
$name
63 ######################################################################
65 ## configure our library
67 set oguilib
{@@GITGUI_LIBDIR@@
}
68 set oguirel
{@@GITGUI_RELATIVE@@
}
69 if {$oguirel eq
{1}} {
70 set oguilib
[file dirname [file dirname [file normalize
$argv0]]]
71 set oguilib
[file join $oguilib share git-gui lib
]
72 } elseif
{[string match @@
* $oguirel]} {
73 set oguilib
[file join [file dirname [file normalize
$argv0]] lib
]
76 set idx
[file join $oguilib tclIndex
]
77 if {[catch
{set fd
[open
$idx r
]} err
]} {
82 -title "git-gui: fatal error" \
86 if {[gets
$fd] eq
{# Autogenerated by git-gui Makefile}} {
88 while {[gets
$fd n
] >= 0} {
89 if {$n ne
{} && ![string match
#* $n]} {
101 if {[lsearch
-exact $loaded $p] >= 0} continue
102 source [file join $oguilib $p]
107 set auto_path
[concat
[list
$oguilib] $auto_path]
109 unset -nocomplain oguirel idx fd
111 ######################################################################
115 set _appname
[lindex
[file split $argv0] end
]
132 return [eval [list
file join $_gitdir] $args]
135 proc gitexec
{args
} {
137 if {$_gitexec eq
{}} {
138 if {[catch
{set _gitexec
[git
--exec-path]} err
]} {
139 error
"Git not installed?\n\n$err"
142 set _gitexec
[exec cygpath \
147 set _gitexec
[file normalize
$_gitexec]
153 return [eval [list
file join $_gitexec] $args]
162 global tcl_platform tk_library
163 if {[tk windowingsystem
] eq
{aqua
}} {
171 if {$tcl_platform(platform
) eq
{windows
}} {
178 global tcl_platform _iscygwin
179 if {$_iscygwin eq
{}} {
180 if {$tcl_platform(platform
) eq
{windows
}} {
181 if {[catch
{set p
[exec cygpath
--windir]} err
]} {
193 proc is_enabled
{option
} {
194 global enabled_options
195 if {[catch
{set on
$enabled_options($option)}]} {return 0}
199 proc enable_option
{option
} {
200 global enabled_options
201 set enabled_options
($option) 1
204 proc disable_option
{option
} {
205 global enabled_options
206 set enabled_options
($option) 0
209 ######################################################################
213 proc is_many_config
{name
} {
214 switch
-glob -- $name {
223 proc is_config_true
{name
} {
225 if {[catch
{set v
$repo_config($name)}]} {
227 } elseif
{$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes}} {
234 proc get_config
{name
} {
236 if {[catch
{set v
$repo_config($name)}]} {
243 proc load_config
{include_global
} {
244 global repo_config global_config default_config
246 array
unset global_config
247 if {$include_global} {
249 set fd_rc
[git_read config
--global --list]
250 while {[gets
$fd_rc line
] >= 0} {
251 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
252 if {[is_many_config
$name]} {
253 lappend global_config
($name) $value
255 set global_config
($name) $value
263 array
unset repo_config
265 set fd_rc
[git_read config
--list]
266 while {[gets
$fd_rc line
] >= 0} {
267 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
268 if {[is_many_config
$name]} {
269 lappend repo_config
($name) $value
271 set repo_config
($name) $value
278 foreach name
[array names default_config
] {
279 if {[catch
{set v
$global_config($name)}]} {
280 set global_config
($name) $default_config($name)
282 if {[catch
{set v
$repo_config($name)}]} {
283 set repo_config
($name) $default_config($name)
288 ######################################################################
292 proc _git_cmd
{name
} {
295 if {[catch
{set v
$_git_cmd_path($name)}]} {
299 --exec-path { return [list $
::_git
$name] }
302 set p
[gitexec git-
$name$
::_search_exe
]
303 if {[file exists
$p]} {
305 } elseif
{[is_Windows
] && [file exists
[gitexec git-
$name]]} {
306 # Try to determine what sort of magic will make
307 # git-$name go and do its thing, because native
308 # Tcl on Windows doesn't know it.
310 set p
[gitexec git-
$name]
317 #!*perl { set i perl }
318 #!*python { set i python }
319 default
{ error
"git-$name is not supported: $s" }
323 if {![info exists interp
]} {
324 set interp
[_which
$i]
327 error
"git-$name requires $i (not in PATH)"
329 set v
[list
$interp $p]
331 # Assume it is builtin to git somehow and we
332 # aren't actually able to see a file for it.
334 set v
[list $
::_git
$name]
336 set _git_cmd_path
($name) $v
342 global env _search_exe _search_path
344 if {$_search_path eq
{}} {
346 set _search_path
[split [exec cygpath \
352 } elseif
{[is_Windows
]} {
353 set _search_path
[split $env(PATH
) {;}]
356 set _search_path
[split $env(PATH
) :]
361 foreach p
$_search_path {
362 set p
[file join $p $what$_search_exe]
363 if {[file exists
$p]} {
364 return [file normalize
$p]
374 switch
-- [lindex
$args 0] {
388 set args
[lrange
$args 1 end
]
391 set cmdp
[_git_cmd
[lindex
$args 0]]
392 set args
[lrange
$args 1 end
]
394 return [eval $opt $cmdp $args]
397 proc git_read
{args
} {
401 switch
-- [lindex
$args 0] {
419 set args
[lrange
$args 1 end
]
422 set cmdp
[_git_cmd
[lindex
$args 0]]
423 set args
[lrange
$args 1 end
]
426 set fd
[open
[concat
$opt $cmdp $args] r
]
428 if { [lindex
$args end
] eq
{2>@
1}
429 && $err eq
{can not
find channel named
"1"}
431 # Older versions of Tcl 8.4 don't have this 2>@1 IO
432 # redirect operator. Fallback to |& cat for those.
433 # The command was not actually started, so its safe
434 # to try to start it a second time.
436 set fd
[open
[concat \
439 [lrange
$args 0 end-1
] \
449 proc git_write
{args
} {
453 switch
-- [lindex
$args 0] {
467 set args
[lrange
$args 1 end
]
470 set cmdp
[_git_cmd
[lindex
$args 0]]
471 set args
[lrange
$args 1 end
]
473 return [open
[concat
$opt $cmdp $args] w
]
476 proc load_current_branch
{} {
477 global current_branch is_detached
479 set fd
[open
[gitdir HEAD
] r
]
480 if {[gets
$fd ref
] < 1} {
485 set pfx
{ref
: refs
/heads
/}
486 set len
[string length
$pfx]
487 if {[string equal
-length $len $pfx $ref]} {
488 # We're on a branch. It might not exist. But
489 # HEAD looks good enough to be a branch.
491 set current_branch
[string range
$ref $len end
]
494 # Assume this is a detached head.
496 set current_branch HEAD
501 auto_load tk_optionMenu
502 rename tk_optionMenu real__tkOptionMenu
503 proc tk_optionMenu
{w varName args
} {
504 set m
[eval real__tkOptionMenu
$w $varName $args]
505 $m configure
-font font_ui
506 $w configure
-font font_ui
510 ######################################################################
514 set _git
[_which git
]
516 catch
{wm withdraw .
}
517 error_popup
"Cannot find git in PATH."
520 set _nice
[_which nice
]
522 ######################################################################
526 if {[catch
{set _git_version
[git
--version]} err
]} {
527 catch
{wm withdraw .
}
528 error_popup
"Cannot determine Git version:
532 [appname] requires Git 1.5.0 or later."
535 if {![regsub
{^git version
} $_git_version {} _git_version
]} {
536 catch
{wm withdraw .
}
537 error_popup
"Cannot parse Git version string:\n\n$_git_version"
540 regsub
{\.
[0-9]+\.g
[0-9a-f]+$
} $_git_version {} _git_version
541 regsub
{\.rc
[0-9]+$
} $_git_version {} _git_version
543 proc git-version
{args
} {
546 switch
[llength
$args] {
552 set op
[lindex
$args 0]
553 set vr
[lindex
$args 1]
554 set cm
[package vcompare
$_git_version $vr]
555 return [expr $cm $op 0]
559 set type [lindex
$args 0]
560 set name
[lindex
$args 1]
561 set parm
[lindex
$args 2]
562 set body
[lindex
$args 3]
564 if {($type ne
{proc
} && $type ne
{method
})} {
565 error
"Invalid arguments to git-version"
567 if {[llength
$body] < 2 ||
[lindex
$body end-1
] ne
{default
}} {
568 error
"Last arm of $type $name must be default"
571 foreach
{op vr cb
} [lrange
$body 0 end-2
] {
572 if {[git-version
$op $vr]} {
573 return [uplevel
[list
$type $name $parm $cb]]
577 return [uplevel
[list
$type $name $parm [lindex
$body end
]]]
581 error
"git-version >= x"
587 if {[git-version
< 1.5]} {
588 catch
{wm withdraw .
}
589 error_popup
"[appname] requires Git 1.5.0 or later.
591 You are using [git-version]:
597 ######################################################################
602 set _gitdir
$env(GIT_DIR
)
606 set _gitdir
[git rev-parse
--git-dir]
607 set _prefix
[git rev-parse
--show-prefix]
609 catch
{wm withdraw .
}
610 error_popup
"Cannot find the git directory:\n\n$err"
613 if {![file isdirectory
$_gitdir] && [is_Cygwin
]} {
614 catch
{set _gitdir
[exec cygpath
--unix $_gitdir]}
616 if {![file isdirectory
$_gitdir]} {
617 catch
{wm withdraw .
}
618 error_popup
"Git directory not found:\n\n$_gitdir"
621 if {[lindex
[file split $_gitdir] end
] ne
{.git
}} {
622 catch
{wm withdraw .
}
623 error_popup
"Cannot use funny .git directory:\n\n$_gitdir"
626 if {[catch
{cd [file dirname $_gitdir]} err
]} {
627 catch
{wm withdraw .
}
628 error_popup
"No working directory [file dirname $_gitdir]:\n\n$err"
631 set _reponame
[lindex
[file split \
632 [file normalize
[file dirname $_gitdir]]] \
635 ######################################################################
639 set current_diff_path
{}
640 set current_diff_side
{}
641 set diff_actions
[list
]
645 set MERGE_HEAD
[list
]
648 set current_branch
{}
650 set current_diff_path
{}
651 set selected_commit_type new
653 ######################################################################
661 set disable_on_lock
[list
]
662 set index_lock_type none
664 proc lock_index
{type} {
665 global index_lock_type disable_on_lock
667 if {$index_lock_type eq
{none
}} {
668 set index_lock_type
$type
669 foreach w
$disable_on_lock {
670 uplevel
#0 $w disabled
673 } elseif
{$index_lock_type eq
"begin-$type"} {
674 set index_lock_type
$type
680 proc unlock_index
{} {
681 global index_lock_type disable_on_lock
683 set index_lock_type none
684 foreach w
$disable_on_lock {
689 ######################################################################
693 proc repository_state
{ctvar hdvar mhvar
} {
694 global current_branch
695 upvar
$ctvar ct
$hdvar hd
$mhvar mh
700 if {[catch
{set hd
[git rev-parse
--verify HEAD
]}]} {
706 set merge_head
[gitdir MERGE_HEAD
]
707 if {[file exists
$merge_head]} {
709 set fd_mh
[open
$merge_head r
]
710 while {[gets
$fd_mh line
] >= 0} {
721 global PARENT empty_tree
723 set p
[lindex
$PARENT 0]
727 if {$empty_tree eq
{}} {
728 set empty_tree
[git mktree
<< {}]
733 proc rescan
{after
{honor_trustmtime
1}} {
734 global HEAD PARENT MERGE_HEAD commit_type
735 global ui_index ui_workdir ui_comm
736 global rescan_active file_states
739 if {$rescan_active > 0 ||
![lock_index
read]} return
741 repository_state newType newHEAD newMERGE_HEAD
742 if {[string match amend
* $commit_type]
743 && $newType eq
{normal
}
744 && $newHEAD eq
$HEAD} {
748 set MERGE_HEAD
$newMERGE_HEAD
749 set commit_type
$newType
752 array
unset file_states
754 if {![$ui_comm edit modified
]
755 ||
[string trim
[$ui_comm get
0.0 end
]] eq
{}} {
756 if {[string match amend
* $commit_type]} {
757 } elseif
{[load_message GITGUI_MSG
]} {
758 } elseif
{[load_message MERGE_MSG
]} {
759 } elseif
{[load_message SQUASH_MSG
]} {
762 $ui_comm edit modified false
765 if {$honor_trustmtime && $repo_config(gui.trustmtime
) eq
{true
}} {
766 rescan_stage2
{} $after
769 ui_status
{Refreshing
file status...
}
770 set fd_rf
[git_read update-index \
776 fconfigure
$fd_rf -blocking 0 -translation binary
777 fileevent
$fd_rf readable \
778 [list rescan_stage2
$fd_rf $after]
782 proc rescan_stage2
{fd after
} {
783 global rescan_active buf_rdi buf_rdf buf_rlo
787 if {![eof
$fd]} return
791 set ls_others
[list
--exclude-per-directory=.gitignore
]
792 set info_exclude
[gitdir info exclude
]
793 if {[file readable
$info_exclude]} {
794 lappend ls_others
"--exclude-from=$info_exclude"
802 ui_status
{Scanning
for modified files ...
}
803 set fd_di
[git_read diff-index
--cached -z [PARENT
]]
804 set fd_df
[git_read diff-files
-z]
805 set fd_lo
[eval git_read ls-files
--others -z $ls_others]
807 fconfigure
$fd_di -blocking 0 -translation binary
-encoding binary
808 fconfigure
$fd_df -blocking 0 -translation binary
-encoding binary
809 fconfigure
$fd_lo -blocking 0 -translation binary
-encoding binary
810 fileevent
$fd_di readable
[list read_diff_index
$fd_di $after]
811 fileevent
$fd_df readable
[list read_diff_files
$fd_df $after]
812 fileevent
$fd_lo readable
[list read_ls_others
$fd_lo $after]
815 proc load_message
{file} {
819 if {[file isfile
$f]} {
820 if {[catch
{set fd
[open
$f r
]}]} {
823 set content
[string trim
[read $fd]]
825 regsub
-all -line {[ \r\t]+$
} $content {} content
826 $ui_comm delete
0.0 end
827 $ui_comm insert end
$content
833 proc read_diff_index
{fd after
} {
836 append buf_rdi
[read $fd]
838 set n
[string length
$buf_rdi]
840 set z1
[string first
"\0" $buf_rdi $c]
843 set z2
[string first
"\0" $buf_rdi $z1]
847 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
848 set p
[string range
$buf_rdi $z1 [expr {$z2 - 1}]]
850 [encoding convertfrom
$p] \
852 [list
[lindex
$i 0] [lindex
$i 2]] \
858 set buf_rdi
[string range
$buf_rdi $c end
]
863 rescan_done
$fd buf_rdi
$after
866 proc read_diff_files
{fd after
} {
869 append buf_rdf
[read $fd]
871 set n
[string length
$buf_rdf]
873 set z1
[string first
"\0" $buf_rdf $c]
876 set z2
[string first
"\0" $buf_rdf $z1]
880 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
881 set p
[string range
$buf_rdf $z1 [expr {$z2 - 1}]]
883 [encoding convertfrom
$p] \
886 [list
[lindex
$i 0] [lindex
$i 2]]
891 set buf_rdf
[string range
$buf_rdf $c end
]
896 rescan_done
$fd buf_rdf
$after
899 proc read_ls_others
{fd after
} {
902 append buf_rlo
[read $fd]
903 set pck
[split $buf_rlo "\0"]
904 set buf_rlo
[lindex
$pck end
]
905 foreach p
[lrange
$pck 0 end-1
] {
906 merge_state
[encoding convertfrom
$p] ?O
908 rescan_done
$fd buf_rlo
$after
911 proc rescan_done
{fd buf after
} {
912 global rescan_active current_diff_path
913 global file_states repo_config
916 if {![eof
$fd]} return
919 if {[incr rescan_active
-1] > 0} return
924 if {$current_diff_path ne
{}} reshow_diff
928 proc prune_selection
{} {
929 global file_states selected_paths
931 foreach path
[array names selected_paths
] {
932 if {[catch
{set still_here
$file_states($path)}]} {
933 unset selected_paths
($path)
938 ######################################################################
942 proc mapicon
{w state path
} {
945 if {[catch
{set r
$all_icons($state$w)}]} {
946 puts
"error: no icon for $w state={$state} $path"
952 proc mapdesc
{state path
} {
955 if {[catch
{set r
$all_descs($state)}]} {
956 puts
"error: no desc for state={$state} $path"
962 proc ui_status
{msg
} {
963 $
::main_status show
$msg
966 proc ui_ready
{{test {}}} {
967 $
::main_status show
{Ready.
} $test
970 proc escape_path
{path
} {
971 regsub
-all {\\} $path "\\\\" path
972 regsub
-all "\n" $path "\\n" path
976 proc short_path
{path
} {
977 return [escape_path
[lindex
[file split $path] end
]]
981 set null_sha1
[string repeat
0 40]
983 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
984 global file_states next_icon_id null_sha1
986 set s0
[string index
$new_state 0]
987 set s1
[string index
$new_state 1]
989 if {[catch
{set info
$file_states($path)}]} {
991 set icon n
[incr next_icon_id
]
993 set state
[lindex
$info 0]
994 set icon
[lindex
$info 1]
995 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
996 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
999 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1000 elseif
{$s0 eq
{_
}} {set s0 _
}
1002 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1003 elseif
{$s1 eq
{_
}} {set s1 _
}
1005 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1006 set head_info
[list
0 $null_sha1]
1007 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1008 && $head_info eq
{}} {
1009 set head_info
$index_info
1012 set file_states
($path) [list
$s0$s1 $icon \
1013 $head_info $index_info \
1018 proc display_file_helper
{w path icon_name old_m new_m
} {
1021 if {$new_m eq
{_
}} {
1022 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1024 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1026 $w conf
-state normal
1027 $w delete
$lno.0 [expr {$lno + 1}].0
1028 $w conf
-state disabled
1030 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1031 lappend file_lists
($w) $path
1032 set file_lists
($w) [lsort
-unique $file_lists($w)]
1033 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1035 $w conf
-state normal
1036 $w image create
$lno.0 \
1037 -align center
-padx 5 -pady 1 \
1039 -image [mapicon
$w $new_m $path]
1040 $w insert
$lno.1 "[escape_path $path]\n"
1041 $w conf
-state disabled
1042 } elseif
{$old_m ne
$new_m} {
1043 $w conf
-state normal
1044 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1045 $w conf
-state disabled
1049 proc display_file
{path state
} {
1050 global file_states selected_paths
1051 global ui_index ui_workdir
1053 set old_m
[merge_state
$path $state]
1054 set s
$file_states($path)
1055 set new_m
[lindex
$s 0]
1056 set icon_name
[lindex
$s 1]
1058 set o
[string index
$old_m 0]
1059 set n
[string index
$new_m 0]
1066 display_file_helper
$ui_index $path $icon_name $o $n
1068 if {[string index
$old_m 0] eq
{U
}} {
1071 set o
[string index
$old_m 1]
1073 if {[string index
$new_m 0] eq
{U
}} {
1076 set n
[string index
$new_m 1]
1078 display_file_helper
$ui_workdir $path $icon_name $o $n
1080 if {$new_m eq
{__
}} {
1081 unset file_states
($path)
1082 catch
{unset selected_paths
($path)}
1086 proc display_all_files_helper
{w path icon_name m
} {
1089 lappend file_lists
($w) $path
1090 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1091 $w image create end \
1092 -align center
-padx 5 -pady 1 \
1094 -image [mapicon
$w $m $path]
1095 $w insert end
"[escape_path $path]\n"
1098 proc display_all_files
{} {
1099 global ui_index ui_workdir
1100 global file_states file_lists
1103 $ui_index conf
-state normal
1104 $ui_workdir conf
-state normal
1106 $ui_index delete
0.0 end
1107 $ui_workdir delete
0.0 end
1110 set file_lists
($ui_index) [list
]
1111 set file_lists
($ui_workdir) [list
]
1113 foreach path
[lsort
[array names file_states
]] {
1114 set s
$file_states($path)
1116 set icon_name
[lindex
$s 1]
1118 set s
[string index
$m 0]
1119 if {$s ne
{U
} && $s ne
{_
}} {
1120 display_all_files_helper
$ui_index $path \
1124 if {[string index
$m 0] eq
{U
}} {
1127 set s
[string index
$m 1]
1130 display_all_files_helper
$ui_workdir $path \
1135 $ui_index conf
-state disabled
1136 $ui_workdir conf
-state disabled
1139 ######################################################################
1144 #define mask_width 14
1145 #define mask_height 15
1146 static unsigned char mask_bits
[] = {
1147 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1148 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1149 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1152 image create bitmap file_plain
-background white
-foreground black
-data {
1153 #define plain_width 14
1154 #define plain_height 15
1155 static unsigned char plain_bits
[] = {
1156 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1157 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1158 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1159 } -maskdata $filemask
1161 image create bitmap file_mod
-background white
-foreground blue
-data {
1162 #define mod_width 14
1163 #define mod_height 15
1164 static unsigned char mod_bits
[] = {
1165 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1166 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1167 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1168 } -maskdata $filemask
1170 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
1171 #define file_fulltick_width 14
1172 #define file_fulltick_height 15
1173 static unsigned char file_fulltick_bits
[] = {
1174 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1175 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1176 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1177 } -maskdata $filemask
1179 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
1180 #define parttick_width 14
1181 #define parttick_height 15
1182 static unsigned char parttick_bits
[] = {
1183 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1184 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
1185 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1186 } -maskdata $filemask
1188 image create bitmap file_question
-background white
-foreground black
-data {
1189 #define file_question_width 14
1190 #define file_question_height 15
1191 static unsigned char file_question_bits
[] = {
1192 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1193 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1194 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1195 } -maskdata $filemask
1197 image create bitmap file_removed
-background white
-foreground red
-data {
1198 #define file_removed_width 14
1199 #define file_removed_height 15
1200 static unsigned char file_removed_bits
[] = {
1201 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1202 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1203 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1204 } -maskdata $filemask
1206 image create bitmap file_merge
-background white
-foreground blue
-data {
1207 #define file_merge_width 14
1208 #define file_merge_height 15
1209 static unsigned char file_merge_bits
[] = {
1210 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1211 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1212 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1213 } -maskdata $filemask
1216 #define file_width 18
1217 #define file_height 18
1218 static unsigned char file_bits
[] = {
1219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00,
1220 0x0c, 0x03, 0x00, 0x04, 0xfe, 0x00, 0x06, 0x80, 0x00, 0xff, 0x9f, 0x00,
1221 0x03, 0x98, 0x00, 0x02, 0x90, 0x00, 0x06, 0xb0, 0x00, 0x04, 0xa0, 0x00,
1222 0x0c, 0xe0, 0x00, 0x08, 0xc0, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
1223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1225 image create bitmap file_dir
-background white
-foreground blue \
1226 -data $file_dir_data -maskdata $file_dir_data
1229 set file_uplevel_data
{
1231 #define up_height 15
1232 static unsigned char up_bits
[] = {
1233 0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f,
1234 0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
1235 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
1237 image create bitmap file_uplevel
-background white
-foreground red \
1238 -data $file_uplevel_data -maskdata $file_uplevel_data
1239 unset file_uplevel_data
1241 set ui_index .vpane.files.index.list
1242 set ui_workdir .vpane.files.workdir.list
1244 set all_icons
(_
$ui_index) file_plain
1245 set all_icons
(A
$ui_index) file_fulltick
1246 set all_icons
(M
$ui_index) file_fulltick
1247 set all_icons
(D
$ui_index) file_removed
1248 set all_icons
(U
$ui_index) file_merge
1250 set all_icons
(_
$ui_workdir) file_plain
1251 set all_icons
(M
$ui_workdir) file_mod
1252 set all_icons
(D
$ui_workdir) file_question
1253 set all_icons
(U
$ui_workdir) file_merge
1254 set all_icons
(O
$ui_workdir) file_plain
1256 set max_status_desc
0
1260 {_M
"Modified, not staged"}
1261 {M_
"Staged for commit"}
1262 {MM
"Portions staged for commit"}
1263 {MD
"Staged for commit, missing"}
1265 {_O
"Untracked, not staged"}
1266 {A_
"Staged for commit"}
1267 {AM
"Portions staged for commit"}
1268 {AD
"Staged for commit, missing"}
1271 {D_
"Staged for removal"}
1272 {DO
"Staged for removal, still present"}
1274 {U_
"Requires merge resolution"}
1275 {UU
"Requires merge resolution"}
1276 {UM
"Requires merge resolution"}
1277 {UD
"Requires merge resolution"}
1279 if {$max_status_desc < [string length
[lindex
$i 1]]} {
1280 set max_status_desc
[string length
[lindex
$i 1]]
1282 set all_descs
([lindex
$i 0]) [lindex
$i 1]
1286 ######################################################################
1290 proc bind_button3
{w cmd
} {
1291 bind $w <Any-Button-3
> $cmd
1293 bind $w <Control-Button-1
> $cmd
1297 proc scrollbar2many
{list mode args
} {
1298 foreach w
$list {eval $w $mode $args}
1301 proc many2scrollbar
{list mode sb top bottom
} {
1302 $sb set $top $bottom
1303 foreach w
$list {$w $mode moveto
$top}
1306 proc incr_font_size
{font
{amt
1}} {
1307 set sz
[font configure
$font -size]
1309 font configure
$font -size $sz
1310 font configure
${font}bold
-size $sz
1311 font configure
${font}italic
-size $sz
1314 ######################################################################
1318 set starting_gitk_msg
{Starting gitk... please
wait...
}
1320 proc do_gitk
{revs
} {
1321 # -- Always start gitk through whatever we were loaded with. This
1322 # lets us bypass using shell process on Windows systems.
1324 set exe
[file join [file dirname $
::_git
] gitk
]
1325 set cmd
[list
[info nameofexecutable
] $exe]
1326 if {! [file exists
$exe]} {
1327 error_popup
"Unable to start gitk:\n\n$exe does not exist"
1329 eval exec $cmd $revs &
1330 ui_status $
::starting_gitk_msg
1332 ui_ready
$starting_gitk_msg
1340 global ui_comm is_quitting repo_config commit_type
1342 if {$is_quitting} return
1345 if {[winfo exists
$ui_comm]} {
1346 # -- Stash our current commit buffer.
1348 set save
[gitdir GITGUI_MSG
]
1349 set msg
[string trim
[$ui_comm get
0.0 end
]]
1350 regsub
-all -line {[ \r\t]+$
} $msg {} msg
1351 if {(![string match amend
* $commit_type]
1352 ||
[$ui_comm edit modified
])
1355 set fd
[open
$save w
]
1356 puts
-nonewline $fd $msg
1360 catch
{file delete
$save}
1363 # -- Stash our current window geometry into this repository.
1365 set cfg_geometry
[list
]
1366 lappend cfg_geometry
[wm geometry .
]
1367 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
1368 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
1369 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
1372 if {$cfg_geometry ne
$rc_geometry} {
1373 catch
{git config gui.geometry
$cfg_geometry}
1388 proc toggle_or_diff
{w x y
} {
1389 global file_states file_lists current_diff_path ui_index ui_workdir
1390 global last_clicked selected_paths
1392 set pos
[split [$w index @
$x,$y] .
]
1393 set lno
[lindex
$pos 0]
1394 set col [lindex
$pos 1]
1395 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
1401 set last_clicked
[list
$w $lno]
1402 array
unset selected_paths
1403 $ui_index tag remove in_sel
0.0 end
1404 $ui_workdir tag remove in_sel
0.0 end
1407 if {$current_diff_path eq
$path} {
1408 set after
{reshow_diff
;}
1412 if {$w eq
$ui_index} {
1414 "Unstaging [short_path $path] from commit" \
1416 [concat
$after [list ui_ready
]]
1417 } elseif
{$w eq
$ui_workdir} {
1419 "Adding [short_path $path]" \
1421 [concat
$after [list ui_ready
]]
1424 show_diff
$path $w $lno
1428 proc add_one_to_selection
{w x y
} {
1429 global file_lists last_clicked selected_paths
1431 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
1432 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
1438 if {$last_clicked ne
{}
1439 && [lindex
$last_clicked 0] ne
$w} {
1440 array
unset selected_paths
1441 [lindex
$last_clicked 0] tag remove in_sel
0.0 end
1444 set last_clicked
[list
$w $lno]
1445 if {[catch
{set in_sel
$selected_paths($path)}]} {
1449 unset selected_paths
($path)
1450 $w tag remove in_sel
$lno.0 [expr {$lno + 1}].0
1452 set selected_paths
($path) 1
1453 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
1457 proc add_range_to_selection
{w x y
} {
1458 global file_lists last_clicked selected_paths
1460 if {[lindex
$last_clicked 0] ne
$w} {
1461 toggle_or_diff
$w $x $y
1465 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
1466 set lc
[lindex
$last_clicked 1]
1475 foreach path
[lrange
$file_lists($w) \
1476 [expr {$begin - 1}] \
1477 [expr {$end - 1}]] {
1478 set selected_paths
($path) 1
1480 $w tag add in_sel
$begin.0 [expr {$end + 1}].0
1483 ######################################################################
1487 set cursor_ptr arrow
1488 font create font_diff
-family Courier
-size 10
1492 eval font configure font_ui
[font actual
[.dummy cget
-font]]
1496 font create font_uiitalic
1497 font create font_uibold
1498 font create font_diffbold
1499 font create font_diffitalic
1501 foreach class
{Button Checkbutton Entry Label
1502 Labelframe Listbox Menu Message
1503 Radiobutton Spinbox Text
} {
1504 option add
*$class.font font_ui
1508 if {[is_Windows
] ||
[is_MacOSX
]} {
1509 option add
*Menu.tearOff
0
1520 proc apply_config
{} {
1521 global repo_config font_descs
1523 foreach option
$font_descs {
1524 set name
[lindex
$option 0]
1525 set font
[lindex
$option 1]
1527 foreach
{cn cv
} $repo_config(gui.
$name) {
1528 font configure
$font $cn $cv
1531 error_popup
"Invalid font specified in gui.$name:\n\n$err"
1533 foreach
{cn cv
} [font configure
$font] {
1534 font configure
${font}bold
$cn $cv
1535 font configure
${font}italic
$cn $cv
1537 font configure
${font}bold
-weight bold
1538 font configure
${font}italic
-slant italic
1542 set default_config
(merge.diffstat
) true
1543 set default_config
(merge.summary
) false
1544 set default_config
(merge.verbosity
) 2
1545 set default_config
(user.name
) {}
1546 set default_config
(user.email
) {}
1548 set default_config
(gui.matchtrackingbranch
) false
1549 set default_config
(gui.pruneduringfetch
) false
1550 set default_config
(gui.trustmtime
) false
1551 set default_config
(gui.diffcontext
) 5
1552 set default_config
(gui.newbranchtemplate
) {}
1553 set default_config
(gui.fontui
) [font configure font_ui
]
1554 set default_config
(gui.fontdiff
) [font configure font_diff
]
1556 {fontui font_ui
{Main Font
}}
1557 {fontdiff font_diff
{Diff
/Console Font
}}
1562 ######################################################################
1564 ## feature option selection
1566 if {[regexp
{^git-
(.
+)$
} [appname
] _junk subcommand
]} {
1571 if {$subcommand eq
{gui.sh
}} {
1574 if {$subcommand eq
{gui
} && [llength
$argv] > 0} {
1575 set subcommand
[lindex
$argv 0]
1576 set argv
[lrange
$argv 1 end
]
1579 enable_option multicommit
1580 enable_option branch
1581 enable_option transport
1583 switch
-- $subcommand {
1586 disable_option multicommit
1587 disable_option branch
1588 disable_option transport
1591 enable_option singlecommit
1593 disable_option multicommit
1594 disable_option branch
1595 disable_option transport
1599 ######################################################################
1607 menu .mbar
-tearoff 0
1608 .mbar add cascade
-label Repository
-menu .mbar.repository
1609 .mbar add cascade
-label Edit
-menu .mbar.edit
1610 if {[is_enabled branch
]} {
1611 .mbar add cascade
-label Branch
-menu .mbar.branch
1613 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
1614 .mbar add cascade
-label Commit
-menu .mbar.commit
1616 if {[is_enabled transport
]} {
1617 .mbar add cascade
-label Merge
-menu .mbar.merge
1618 .mbar add cascade
-label Fetch
-menu .mbar.fetch
1619 .mbar add cascade
-label Push
-menu .mbar.push
1621 . configure
-menu .mbar
1623 # -- Repository Menu
1625 menu .mbar.repository
1627 .mbar.repository add
command \
1628 -label {Browse Current Branch
} \
1629 -command {browser
::new
$current_branch}
1630 trace add variable current_branch
write ".mbar.repository entryconf [.mbar.repository index last] -label \"Browse \$current_branch\" ;#"
1631 .mbar.repository add separator
1633 .mbar.repository add
command \
1634 -label {Visualize Current Branch
} \
1635 -command {do_gitk
$current_branch}
1636 trace add variable current_branch
write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#"
1637 .mbar.repository add
command \
1638 -label {Visualize All Branches
} \
1639 -command {do_gitk
--all}
1640 .mbar.repository add separator
1642 if {[is_enabled multicommit
]} {
1643 .mbar.repository add
command -label {Database Statistics
} \
1646 .mbar.repository add
command -label {Compress Database
} \
1649 .mbar.repository add
command -label {Verify Database
} \
1650 -command do_fsck_objects
1652 .mbar.repository add separator
1655 .mbar.repository add
command \
1656 -label {Create Desktop Icon
} \
1657 -command do_cygwin_shortcut
1658 } elseif
{[is_Windows
]} {
1659 .mbar.repository add
command \
1660 -label {Create Desktop Icon
} \
1661 -command do_windows_shortcut
1662 } elseif
{[is_MacOSX
]} {
1663 .mbar.repository add
command \
1664 -label {Create Desktop Icon
} \
1665 -command do_macosx_app
1669 .mbar.repository add
command -label Quit \
1676 .mbar.edit add
command -label Undo \
1677 -command {catch
{[focus
] edit undo
}} \
1679 .mbar.edit add
command -label Redo \
1680 -command {catch
{[focus
] edit redo
}} \
1682 .mbar.edit add separator
1683 .mbar.edit add
command -label Cut \
1684 -command {catch
{tk_textCut
[focus
]}} \
1686 .mbar.edit add
command -label Copy \
1687 -command {catch
{tk_textCopy
[focus
]}} \
1689 .mbar.edit add
command -label Paste \
1690 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
1692 .mbar.edit add
command -label Delete \
1693 -command {catch
{[focus
] delete sel.first sel.last
}} \
1695 .mbar.edit add separator
1696 .mbar.edit add
command -label {Select All
} \
1697 -command {catch
{[focus
] tag add sel
0.0 end
}} \
1702 if {[is_enabled branch
]} {
1705 .mbar.branch add
command -label {Create...
} \
1706 -command branch_create
::dialog \
1708 lappend disable_on_lock
[list .mbar.branch entryconf \
1709 [.mbar.branch index last
] -state]
1711 .mbar.branch add
command -label {Checkout...
} \
1712 -command branch_checkout
::dialog \
1714 lappend disable_on_lock
[list .mbar.branch entryconf \
1715 [.mbar.branch index last
] -state]
1717 .mbar.branch add
command -label {Rename...
} \
1718 -command branch_rename
::dialog
1719 lappend disable_on_lock
[list .mbar.branch entryconf \
1720 [.mbar.branch index last
] -state]
1722 .mbar.branch add
command -label {Delete...
} \
1723 -command branch_delete
::dialog
1724 lappend disable_on_lock
[list .mbar.branch entryconf \
1725 [.mbar.branch index last
] -state]
1727 .mbar.branch add
command -label {Reset...
} \
1728 -command merge
::reset_hard
1729 lappend disable_on_lock
[list .mbar.branch entryconf \
1730 [.mbar.branch index last
] -state]
1735 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
1738 .mbar.commit add radiobutton \
1739 -label {New Commit
} \
1740 -command do_select_commit_type \
1741 -variable selected_commit_type \
1743 lappend disable_on_lock \
1744 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1746 .mbar.commit add radiobutton \
1747 -label {Amend Last Commit
} \
1748 -command do_select_commit_type \
1749 -variable selected_commit_type \
1751 lappend disable_on_lock \
1752 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1754 .mbar.commit add separator
1756 .mbar.commit add
command -label Rescan \
1757 -command do_rescan \
1759 lappend disable_on_lock \
1760 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1762 .mbar.commit add
command -label {Add To Commit
} \
1763 -command do_add_selection
1764 lappend disable_on_lock \
1765 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1767 .mbar.commit add
command -label {Add Existing To Commit
} \
1768 -command do_add_all \
1770 lappend disable_on_lock \
1771 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1773 .mbar.commit add
command -label {Unstage From Commit
} \
1774 -command do_unstage_selection
1775 lappend disable_on_lock \
1776 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1778 .mbar.commit add
command -label {Revert Changes
} \
1779 -command do_revert_selection
1780 lappend disable_on_lock \
1781 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1783 .mbar.commit add separator
1785 .mbar.commit add
command -label {Sign Off
} \
1786 -command do_signoff \
1789 .mbar.commit add
command -label Commit \
1790 -command do_commit \
1791 -accelerator $M1T-Return
1792 lappend disable_on_lock \
1793 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
1798 if {[is_enabled branch
]} {
1800 .mbar.merge add
command -label {Local Merge...
} \
1801 -command merge
::dialog
1802 lappend disable_on_lock \
1803 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
1804 .mbar.merge add
command -label {Abort Merge...
} \
1805 -command merge
::reset_hard
1806 lappend disable_on_lock \
1807 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
1813 if {[is_enabled transport
]} {
1817 .mbar.push add
command -label {Push...
} \
1818 -command do_push_anywhere \
1820 .mbar.push add
command -label {Delete...
} \
1821 -command remote_branch_delete
::dialog
1825 # -- Apple Menu (Mac OS X only)
1827 .mbar add cascade
-label Apple
-menu .mbar.apple
1830 .mbar.apple add
command -label "About [appname]" \
1832 .mbar.apple add
command -label "Options..." \
1837 .mbar.edit add separator
1838 .mbar.edit add
command -label {Options...
} \
1843 if {[is_Cygwin
] && [file exists
/usr
/local
/miga
/lib
/gui-miga
]} {
1845 if {![lock_index update
]} return
1846 set cmd
[list sh
--login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
1847 set miga_fd
[open
"|$cmd" r
]
1848 fconfigure
$miga_fd -blocking 0
1849 fileevent
$miga_fd readable
[list miga_done
$miga_fd]
1850 ui_status
{Running miga...
}
1852 proc miga_done
{fd
} {
1860 .mbar add cascade
-label Tools
-menu .mbar.tools
1862 .mbar.tools add
command -label "Migrate" \
1864 lappend disable_on_lock \
1865 [list .mbar.tools entryconf
[.mbar.tools index last
] -state]
1871 .mbar add cascade
-label Help
-menu .mbar.
help
1875 .mbar.
help add
command -label "About [appname]" \
1880 catch
{set browser
$repo_config(instaweb.browser
)}
1881 set doc_path
[file dirname [gitexec
]]
1882 set doc_path
[file join $doc_path Documentation index.html
]
1885 set doc_path
[exec cygpath
--mixed $doc_path]
1888 if {$browser eq
{}} {
1891 } elseif
{[is_Cygwin
]} {
1892 set program_files
[file dirname [exec cygpath
--windir]]
1893 set program_files
[file join $program_files {Program Files
}]
1894 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
1895 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
1896 if {[file exists
$firefox]} {
1897 set browser
$firefox
1898 } elseif
{[file exists
$ie]} {
1901 unset program_files firefox ie
1905 if {[file isfile
$doc_path]} {
1906 set doc_url
"file:$doc_path"
1908 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
1911 if {$browser ne
{}} {
1912 .mbar.
help add
command -label {Online Documentation
} \
1913 -command [list
exec $browser $doc_url &]
1915 unset browser doc_path doc_url
1917 # -- Standard bindings
1919 wm protocol . WM_DELETE_WINDOW do_quit
1920 bind all
<$M1B-Key-q> do_quit
1921 bind all
<$M1B-Key-Q> do_quit
1922 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
1923 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
1925 set subcommand_args
{}
1927 puts stderr
"usage: $::argv0 $::subcommand $::subcommand_args"
1931 # -- Not a normal commit type invocation? Do that instead!
1933 switch
-- $subcommand {
1935 set subcommand_args
{rev?
}
1936 switch
[llength
$argv] {
1937 0 { load_current_branch
}
1939 set current_branch
[lindex
$argv 0]
1940 if {[regexp
{^
[0-9a-f]{1,39}$
} $current_branch]} {
1942 set current_branch \
1943 [git rev-parse
--verify $current_branch]
1952 browser
::new
$current_branch
1956 set subcommand_args
{rev? path?
}
1961 if {$is_path ||
[file exists
$_prefix$a]} {
1962 if {$path ne
{}} usage
1965 } elseif
{$a eq
{--}} {
1967 if {$head ne
{}} usage
1972 } elseif
{$head eq
{}} {
1973 if {$head ne
{}} usage
1984 if {[regexp
{^
[0-9a-f]{1,39}$
} $head]} {
1986 set head [git rev-parse
--verify $head]
1992 set current_branch
$head
1995 if {$path eq
{}} usage
1996 blame
::new
$head $path
2001 if {[llength
$argv] != 0} {
2002 puts
-nonewline stderr
"usage: $argv0"
2003 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
2004 puts
-nonewline stderr
" $subcommand"
2009 # fall through to setup UI for commits
2012 puts stderr
"usage: $argv0 \[{blame|browser|citool}\]"
2023 -text {Current Branch
:} \
2027 -textvariable current_branch \
2030 pack .branch.l1
-side left
2031 pack .branch.cb
-side left
-fill x
2032 pack .branch
-side top
-fill x
2034 # -- Main Window Layout
2036 panedwindow .vpane
-orient vertical
2037 panedwindow .vpane.files
-orient horizontal
2038 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
2039 pack .vpane
-anchor n
-side top
-fill both
-expand 1
2041 # -- Index File List
2043 frame .vpane.files.index
-height 100 -width 200
2044 label .vpane.files.index.title
-text {Staged Changes
(Will Be Committed
)} \
2045 -background lightgreen
2046 text
$ui_index -background white
-borderwidth 0 \
2047 -width 20 -height 10 \
2049 -cursor $cursor_ptr \
2050 -xscrollcommand {.vpane.files.index.sx
set} \
2051 -yscrollcommand {.vpane.files.index.sy
set} \
2053 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
2054 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
2055 pack .vpane.files.index.title
-side top
-fill x
2056 pack .vpane.files.index.sx
-side bottom
-fill x
2057 pack .vpane.files.index.sy
-side right
-fill y
2058 pack
$ui_index -side left
-fill both
-expand 1
2059 .vpane.files add .vpane.files.index
-sticky nsew
2061 # -- Working Directory File List
2063 frame .vpane.files.workdir
-height 100 -width 200
2064 label .vpane.files.workdir.title
-text {Unstaged Changes
(Will Not Be Committed
)} \
2065 -background lightsalmon
2066 text
$ui_workdir -background white
-borderwidth 0 \
2067 -width 20 -height 10 \
2069 -cursor $cursor_ptr \
2070 -xscrollcommand {.vpane.files.workdir.sx
set} \
2071 -yscrollcommand {.vpane.files.workdir.sy
set} \
2073 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
2074 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
2075 pack .vpane.files.workdir.title
-side top
-fill x
2076 pack .vpane.files.workdir.sx
-side bottom
-fill x
2077 pack .vpane.files.workdir.sy
-side right
-fill y
2078 pack
$ui_workdir -side left
-fill both
-expand 1
2079 .vpane.files add .vpane.files.workdir
-sticky nsew
2081 foreach i
[list
$ui_index $ui_workdir] {
2082 $i tag conf in_diff
-background lightgray
2083 $i tag conf in_sel
-background lightgray
2087 # -- Diff and Commit Area
2089 frame .vpane.lower
-height 300 -width 400
2090 frame .vpane.lower.commarea
2091 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
2092 pack .vpane.lower.commarea
-side top
-fill x
2093 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
2094 .vpane add .vpane.lower
-sticky nsew
2096 # -- Commit Area Buttons
2098 frame .vpane.lower.commarea.buttons
2099 label .vpane.lower.commarea.buttons.l
-text {} \
2102 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
2103 pack .vpane.lower.commarea.buttons
-side left
-fill y
2105 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
2107 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
2108 lappend disable_on_lock \
2109 {.vpane.lower.commarea.buttons.rescan conf
-state}
2111 button .vpane.lower.commarea.buttons.incall
-text {Add Existing
} \
2113 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
2114 lappend disable_on_lock \
2115 {.vpane.lower.commarea.buttons.incall conf
-state}
2117 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
2119 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
2121 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
2123 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
2124 lappend disable_on_lock \
2125 {.vpane.lower.commarea.buttons.commit conf
-state}
2127 button .vpane.lower.commarea.buttons.push
-text {Push
} \
2128 -command do_push_anywhere
2129 pack .vpane.lower.commarea.buttons.push
-side top
-fill x
2131 # -- Commit Message Buffer
2133 frame .vpane.lower.commarea.buffer
2134 frame .vpane.lower.commarea.buffer.header
2135 set ui_comm .vpane.lower.commarea.buffer.t
2136 set ui_coml .vpane.lower.commarea.buffer.header.l
2137 radiobutton .vpane.lower.commarea.buffer.header.new \
2138 -text {New Commit
} \
2139 -command do_select_commit_type \
2140 -variable selected_commit_type \
2142 lappend disable_on_lock \
2143 [list .vpane.lower.commarea.buffer.header.new conf
-state]
2144 radiobutton .vpane.lower.commarea.buffer.header.amend \
2145 -text {Amend Last Commit
} \
2146 -command do_select_commit_type \
2147 -variable selected_commit_type \
2149 lappend disable_on_lock \
2150 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
2154 proc trace_commit_type
{varname args
} {
2155 global ui_coml commit_type
2156 switch
-glob -- $commit_type {
2157 initial
{set txt
{Initial Commit Message
:}}
2158 amend
{set txt
{Amended Commit Message
:}}
2159 amend-initial
{set txt
{Amended Initial Commit Message
:}}
2160 amend-merge
{set txt
{Amended Merge Commit Message
:}}
2161 merge
{set txt
{Merge Commit Message
:}}
2162 * {set txt
{Commit Message
:}}
2164 $ui_coml conf
-text $txt
2166 trace add variable commit_type
write trace_commit_type
2167 pack
$ui_coml -side left
-fill x
2168 pack .vpane.lower.commarea.buffer.header.amend
-side right
2169 pack .vpane.lower.commarea.buffer.header.new
-side right
2171 text
$ui_comm -background white
-borderwidth 1 \
2174 -autoseparators true \
2176 -width 75 -height 9 -wrap none \
2178 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
2179 scrollbar .vpane.lower.commarea.buffer.sby \
2180 -command [list
$ui_comm yview
]
2181 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
2182 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
2183 pack
$ui_comm -side left
-fill y
2184 pack .vpane.lower.commarea.buffer
-side left
-fill y
2186 # -- Commit Message Buffer Context Menu
2188 set ctxm .vpane.lower.commarea.buffer.ctxm
2189 menu
$ctxm -tearoff 0
2192 -command {tk_textCut
$ui_comm}
2195 -command {tk_textCopy
$ui_comm}
2198 -command {tk_textPaste
$ui_comm}
2201 -command {$ui_comm delete sel.first sel.last
}
2204 -label {Select All
} \
2205 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
2209 $ui_comm tag add sel
0.0 end
2210 tk_textCopy
$ui_comm
2211 $ui_comm tag remove sel
0.0 end
2217 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
2221 proc trace_current_diff_path
{varname args
} {
2222 global current_diff_path diff_actions file_states
2223 if {$current_diff_path eq
{}} {
2229 set p
$current_diff_path
2230 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
2232 set p
[escape_path
$p]
2236 .vpane.lower.
diff.header.status configure
-text $s
2237 .vpane.lower.
diff.header.
file configure
-text $f
2238 .vpane.lower.
diff.header.path configure
-text $p
2239 foreach w
$diff_actions {
2243 trace add variable current_diff_path
write trace_current_diff_path
2245 frame .vpane.lower.
diff.header
-background gold
2246 label .vpane.lower.
diff.header.status \
2248 -width $max_status_desc \
2251 label .vpane.lower.
diff.header.
file \
2255 label .vpane.lower.
diff.header.path \
2259 pack .vpane.lower.
diff.header.status
-side left
2260 pack .vpane.lower.
diff.header.
file -side left
2261 pack .vpane.lower.
diff.header.path
-fill x
2262 set ctxm .vpane.lower.
diff.header.ctxm
2263 menu
$ctxm -tearoff 0
2271 -- $current_diff_path
2273 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2274 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
2278 frame .vpane.lower.
diff.body
2279 set ui_diff .vpane.lower.
diff.body.t
2280 text
$ui_diff -background white
-borderwidth 0 \
2281 -width 80 -height 15 -wrap none \
2283 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
2284 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
2286 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
2287 -command [list
$ui_diff xview
]
2288 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
2289 -command [list
$ui_diff yview
]
2290 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
2291 pack .vpane.lower.
diff.body.sby
-side right
-fill y
2292 pack
$ui_diff -side left
-fill both
-expand 1
2293 pack .vpane.lower.
diff.header
-side top
-fill x
2294 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
2296 $ui_diff tag conf d_cr
-elide true
2297 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
2298 $ui_diff tag conf d_
+ -foreground {#00a000}
2299 $ui_diff tag conf d_-
-foreground red
2301 $ui_diff tag conf d_
++ -foreground {#00a000}
2302 $ui_diff tag conf d_--
-foreground red
2303 $ui_diff tag conf d_
+s \
2304 -foreground {#00a000} \
2305 -background {#e2effa}
2306 $ui_diff tag conf d_-s \
2308 -background {#e2effa}
2309 $ui_diff tag conf d_s
+ \
2310 -foreground {#00a000} \
2312 $ui_diff tag conf d_s- \
2316 $ui_diff tag conf d
<<<<<<< \
2317 -foreground orange \
2319 $ui_diff tag conf d
======= \
2320 -foreground orange \
2322 $ui_diff tag conf d
>>>>>>> \
2323 -foreground orange \
2326 $ui_diff tag raise sel
2328 # -- Diff Body Context Menu
2330 set ctxm .vpane.lower.
diff.body.ctxm
2331 menu
$ctxm -tearoff 0
2334 -command reshow_diff
2335 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2338 -command {tk_textCopy
$ui_diff}
2339 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2341 -label {Select All
} \
2342 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
2343 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2347 $ui_diff tag add sel
0.0 end
2348 tk_textCopy
$ui_diff
2349 $ui_diff tag remove sel
0.0 end
2351 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2354 -label {Apply
/Reverse Hunk
} \
2355 -command {apply_hunk
$cursorX $cursorY}
2356 set ui_diff_applyhunk
[$ctxm index last
]
2357 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
2360 -label {Decrease Font Size
} \
2361 -command {incr_font_size font_diff
-1}
2362 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2364 -label {Increase Font Size
} \
2365 -command {incr_font_size font_diff
1}
2366 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2369 -label {Show Less Context
} \
2370 -command {if {$repo_config(gui.diffcontext
) >= 1} {
2371 incr repo_config
(gui.diffcontext
) -1
2374 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2376 -label {Show More Context
} \
2377 -command {if {$repo_config(gui.diffcontext
) < 99} {
2378 incr repo_config
(gui.diffcontext
)
2381 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2383 $ctxm add
command -label {Options...
} \
2385 bind_button3
$ui_diff "
2388 if {\$ui_index eq \$current_diff_side} {
2389 $ctxm entryconf $ui_diff_applyhunk -label {Unstage Hunk From Commit}
2391 $ctxm entryconf $ui_diff_applyhunk -label {Stage Hunk For Commit}
2393 tk_popup $ctxm %X %Y
2395 unset ui_diff_applyhunk
2399 set main_status
[::status_bar
::new .status
]
2400 pack .status
-anchor w
-side bottom
-fill x
2401 $main_status show
{Initializing...
}
2406 set gm
$repo_config(gui.geometry
)
2407 wm geometry .
[lindex
$gm 0]
2408 .vpane sash place
0 \
2409 [lindex
[.vpane sash coord
0] 0] \
2411 .vpane.files sash place
0 \
2413 [lindex
[.vpane.files sash coord
0] 1]
2419 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
2420 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
2421 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
2422 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
2423 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
2424 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
2425 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
2426 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
2427 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
2428 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2429 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2431 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
2432 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
2433 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
2434 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
2435 bind $ui_diff <$M1B-Key-v> {break}
2436 bind $ui_diff <$M1B-Key-V> {break}
2437 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2438 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2439 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
2440 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
2441 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
2442 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
2443 bind $ui_diff <Key-k
> {catch
{%W yview scroll
-1 units
};break}
2444 bind $ui_diff <Key-j
> {catch
{%W yview scroll
1 units
};break}
2445 bind $ui_diff <Key-h
> {catch
{%W xview scroll
-1 units
};break}
2446 bind $ui_diff <Key-l
> {catch
{%W xview scroll
1 units
};break}
2447 bind $ui_diff <Control-Key-b
> {catch
{%W yview scroll
-1 pages
};break}
2448 bind $ui_diff <Control-Key-f
> {catch
{%W yview scroll
1 pages
};break}
2449 bind $ui_diff <Button-1
> {focus
%W
}
2451 if {[is_enabled branch
]} {
2452 bind .
<$M1B-Key-n> branch_create
::dialog
2453 bind .
<$M1B-Key-N> branch_create
::dialog
2454 bind .
<$M1B-Key-o> branch_checkout
::dialog
2455 bind .
<$M1B-Key-O> branch_checkout
::dialog
2457 if {[is_enabled transport
]} {
2458 bind .
<$M1B-Key-p> do_push_anywhere
2459 bind .
<$M1B-Key-P> do_push_anywhere
2462 bind .
<Key-F5
> do_rescan
2463 bind .
<$M1B-Key-r> do_rescan
2464 bind .
<$M1B-Key-R> do_rescan
2465 bind .
<$M1B-Key-s> do_signoff
2466 bind .
<$M1B-Key-S> do_signoff
2467 bind .
<$M1B-Key-i> do_add_all
2468 bind .
<$M1B-Key-I> do_add_all
2469 bind .
<$M1B-Key-Return> do_commit
2470 foreach i
[list
$ui_index $ui_workdir] {
2471 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
2472 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
2473 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
2477 set file_lists
($ui_index) [list
]
2478 set file_lists
($ui_workdir) [list
]
2480 wm title .
"[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"
2481 focus
-force $ui_comm
2483 # -- Warn the user about environmental problems. Cygwin's Tcl
2484 # does *not* pass its env array onto any processes it spawns.
2485 # This means that git processes get none of our environment.
2490 set msg
"Possible environment issues exist.
2492 The following environment variables are probably
2493 going to be ignored by any Git subprocess run
2497 foreach name
[array names env
] {
2498 switch
-regexp -- $name {
2499 {^GIT_INDEX_FILE$
} -
2500 {^GIT_OBJECT_DIRECTORY$
} -
2501 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
2503 {^GIT_EXTERNAL_DIFF$
} -
2507 {^GIT_CONFIG_LOCAL$
} -
2508 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
2509 append msg
" - $name\n"
2512 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
2513 append msg
" - $name\n"
2515 set suggest_user
$name
2519 if {$ignored_env > 0} {
2521 This is due to a known issue with the
2522 Tcl binary distributed by Cygwin."
2524 if {$suggest_user ne
{}} {
2527 A good replacement for $suggest_user
2528 is placing values for the user.name and
2529 user.email settings into your personal
2535 unset ignored_env msg suggest_user name
2538 # -- Only initialize complex UI if we are going to stay running.
2540 if {[is_enabled transport
]} {
2547 # -- Only suggest a gc run if we are going to stay running.
2549 if {[is_enabled multicommit
]} {
2550 set object_limit
2000
2551 if {[is_Windows
]} {set object_limit
200}
2552 regexp
{^
([0-9]+) objects
,} [git count-objects
] _junk objects_current
2553 if {$objects_current >= $object_limit} {
2555 "This repository currently has $objects_current loose objects.
2557 To maintain optimal performance it is strongly recommended that you compress the database when more than $object_limit loose objects exist.
2559 Compress the database now?"] eq
yes} {
2563 unset object_limit _junk objects_current
2566 lock_index begin-read