2 # Tcl ignores the next line -*- tcl -*- \
5 set appvers
{@@GITGUI_VERSION@@
}
7 Copyright ©
2006, 2007 Shawn Pearce
, et. al.
9 This program is free software
; you can redistribute it and
/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation
; either version
2 of the License
, or
12 (at your option
) any later version.
14 This program is distributed
in the hope that it will be useful
,
15 but WITHOUT ANY WARRANTY
; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License
for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program
; if not
, write to the Free Software
21 Foundation
, Inc.
, 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
}
23 ######################################################################
27 set _appname
[lindex
[file split $argv0] end
]
43 return [eval [concat
[list
file join $_gitdir] $args]]
48 if {$_gitexec eq
{}} {
49 if {[catch
{set _gitexec
[git
--exec-path]} err
]} {
50 error
"Git not installed?\n\n$err"
56 return [eval [concat
[list
file join $_gitexec] $args]]
65 global tcl_platform tk_library
66 if {[tk windowingsystem
] eq
{aqua
}} {
74 if {$tcl_platform(platform
) eq
{windows
}} {
81 global tcl_platform _iscygwin
82 if {$_iscygwin eq
{}} {
83 if {$tcl_platform(platform
) eq
{windows
}} {
84 if {[catch
{set p
[exec cygpath
--windir]} err
]} {
96 proc is_enabled
{option
} {
97 global enabled_options
98 if {[catch
{set on
$enabled_options($option)}]} {return 0}
102 proc enable_option
{option
} {
103 global enabled_options
104 set enabled_options
($option) 1
107 proc disable_option
{option
} {
108 global enabled_options
109 set enabled_options
($option) 0
112 ######################################################################
116 proc is_many_config
{name
} {
117 switch
-glob -- $name {
126 proc is_config_true
{name
} {
128 if {[catch
{set v
$repo_config($name)}]} {
130 } elseif
{$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes}} {
137 proc load_config
{include_global
} {
138 global repo_config global_config default_config
140 array
unset global_config
141 if {$include_global} {
143 set fd_rc
[open
"| git config --global --list" r
]
144 while {[gets
$fd_rc line
] >= 0} {
145 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
146 if {[is_many_config
$name]} {
147 lappend global_config
($name) $value
149 set global_config
($name) $value
157 array
unset repo_config
159 set fd_rc
[open
"| git config --list" r
]
160 while {[gets
$fd_rc line
] >= 0} {
161 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
162 if {[is_many_config
$name]} {
163 lappend repo_config
($name) $value
165 set repo_config
($name) $value
172 foreach name
[array names default_config
] {
173 if {[catch
{set v
$global_config($name)}]} {
174 set global_config
($name) $default_config($name)
176 if {[catch
{set v
$repo_config($name)}]} {
177 set repo_config
($name) $default_config($name)
182 proc save_config
{} {
183 global default_config font_descs
184 global repo_config global_config
185 global repo_config_new global_config_new
187 foreach option
$font_descs {
188 set name
[lindex
$option 0]
189 set font
[lindex
$option 1]
190 font configure
$font \
191 -family $global_config_new(gui.
$font^^family
) \
192 -size $global_config_new(gui.
$font^^size
)
193 font configure
${font}bold \
194 -family $global_config_new(gui.
$font^^family
) \
195 -size $global_config_new(gui.
$font^^size
)
196 set global_config_new
(gui.
$name) [font configure
$font]
197 unset global_config_new
(gui.
$font^^family
)
198 unset global_config_new
(gui.
$font^^size
)
201 foreach name
[array names default_config
] {
202 set value
$global_config_new($name)
203 if {$value ne
$global_config($name)} {
204 if {$value eq
$default_config($name)} {
205 catch
{git config
--global --unset $name}
207 regsub
-all "\[{}\]" $value {"} value
208 git config --global $name $value
210 set global_config($name) $value
211 if {$value eq $repo_config($name)} {
212 catch {git config --unset $name}
213 set repo_config($name) $value
218 foreach name [array names default_config] {
219 set value $repo_config_new($name)
220 if {$value ne $repo_config($name)} {
221 if {$value eq $global_config($name)} {
222 catch {git config --unset $name}
224 regsub -all "\
[{}\
]" $value {"} value
225 git config
$name $value
227 set repo_config
($name) $value
232 ######################################################################
237 return [eval exec git
$args]
240 proc error_popup
{msg
} {
242 if {[reponame
] ne
{}} {
243 append title
" ([reponame])"
245 set cmd
[list tk_messageBox \
248 -title "$title: error" \
250 if {[winfo ismapped .
]} {
251 lappend cmd
-parent .
256 proc warn_popup
{msg
} {
258 if {[reponame
] ne
{}} {
259 append title
" ([reponame])"
261 set cmd
[list tk_messageBox \
264 -title "$title: warning" \
266 if {[winfo ismapped .
]} {
267 lappend cmd
-parent .
272 proc info_popup
{msg
{parent .
}} {
274 if {[reponame
] ne
{}} {
275 append title
" ([reponame])"
285 proc ask_popup
{msg
} {
287 if {[reponame
] ne
{}} {
288 append title
" ([reponame])"
290 return [tk_messageBox \
298 auto_load tk_optionMenu
299 rename tk_optionMenu real__tkOptionMenu
300 proc tk_optionMenu
{w varName args
} {
301 set m
[eval real__tkOptionMenu
$w $varName $args]
302 $m configure
-font font_ui
303 $w configure
-font font_ui
307 ######################################################################
311 if {{--version} eq
$argv ||
{version
} eq
$argv} {
312 puts
"git-gui version $appvers"
319 if {[catch
{set v
[git
--version]} err
]} {
320 catch
{wm withdraw .
}
321 error_popup
"Cannot determine Git version:
325 [appname] requires Git $req_maj.$req_min or later."
328 if {[regexp
{^git version
(\d
+)\.
(\d
+)} $v _junk act_maj act_min
]} {
329 if {$act_maj < $req_maj
330 ||
($act_maj == $req_maj && $act_min < $req_min)} {
331 catch
{wm withdraw .
}
332 error_popup
"[appname] requires Git $req_maj.$req_min or later.
338 catch
{wm withdraw .
}
339 error_popup
"Cannot parse Git version string:\n\n$v"
342 unset -nocomplain v _junk act_maj act_min req_maj req_min
344 ######################################################################
348 if { [catch
{set _gitdir
$env(GIT_DIR
)}]
349 && [catch
{set _gitdir
[git rev-parse
--git-dir]} err
]} {
350 catch
{wm withdraw .
}
351 error_popup
"Cannot find the git directory:\n\n$err"
354 if {![file isdirectory
$_gitdir] && [is_Cygwin
]} {
355 catch
{set _gitdir
[exec cygpath
--unix $_gitdir]}
357 if {![file isdirectory
$_gitdir]} {
358 catch
{wm withdraw .
}
359 error_popup
"Git directory not found:\n\n$_gitdir"
362 if {[lindex
[file split $_gitdir] end
] ne
{.git
}} {
363 catch
{wm withdraw .
}
364 error_popup
"Cannot use funny .git directory:\n\n$_gitdir"
367 if {[catch
{cd [file dirname $_gitdir]} err
]} {
368 catch
{wm withdraw .
}
369 error_popup
"No working directory [file dirname $_gitdir]:\n\n$err"
372 set _reponame
[lindex
[file split \
373 [file normalize
[file dirname $_gitdir]]] \
376 ######################################################################
380 set current_diff_path
{}
381 set current_diff_side
{}
382 set diff_actions
[list
]
383 set ui_status_value
{Initializing...
}
387 set MERGE_HEAD
[list
]
390 set current_branch
{}
391 set current_diff_path
{}
392 set selected_commit_type new
394 ######################################################################
402 set disable_on_lock
[list
]
403 set index_lock_type none
405 proc lock_index
{type} {
406 global index_lock_type disable_on_lock
408 if {$index_lock_type eq
{none
}} {
409 set index_lock_type
$type
410 foreach w
$disable_on_lock {
411 uplevel
#0 $w disabled
414 } elseif
{$index_lock_type eq
"begin-$type"} {
415 set index_lock_type
$type
421 proc unlock_index
{} {
422 global index_lock_type disable_on_lock
424 set index_lock_type none
425 foreach w
$disable_on_lock {
430 ######################################################################
434 proc repository_state
{ctvar hdvar mhvar
} {
435 global current_branch
436 upvar
$ctvar ct
$hdvar hd
$mhvar mh
440 if {[catch
{set current_branch
[git symbolic-ref HEAD
]}]} {
441 set current_branch
{}
443 regsub ^refs
/((heads|tags|remotes
)/)? \
449 if {[catch
{set hd
[git rev-parse
--verify HEAD
]}]} {
455 set merge_head
[gitdir MERGE_HEAD
]
456 if {[file exists
$merge_head]} {
458 set fd_mh
[open
$merge_head r
]
459 while {[gets
$fd_mh line
] >= 0} {
470 global PARENT empty_tree
472 set p
[lindex
$PARENT 0]
476 if {$empty_tree eq
{}} {
477 set empty_tree
[git mktree
<< {}]
482 proc rescan
{after
{honor_trustmtime
1}} {
483 global HEAD PARENT MERGE_HEAD commit_type
484 global ui_index ui_workdir ui_status_value ui_comm
485 global rescan_active file_states
488 if {$rescan_active > 0 ||
![lock_index
read]} return
490 repository_state newType newHEAD newMERGE_HEAD
491 if {[string match amend
* $commit_type]
492 && $newType eq
{normal
}
493 && $newHEAD eq
$HEAD} {
497 set MERGE_HEAD
$newMERGE_HEAD
498 set commit_type
$newType
501 array
unset file_states
503 if {![$ui_comm edit modified
]
504 ||
[string trim
[$ui_comm get
0.0 end
]] eq
{}} {
505 if {[load_message GITGUI_MSG
]} {
506 } elseif
{[load_message MERGE_MSG
]} {
507 } elseif
{[load_message SQUASH_MSG
]} {
510 $ui_comm edit modified false
513 if {[is_enabled branch
]} {
518 if {$honor_trustmtime && $repo_config(gui.trustmtime
) eq
{true
}} {
519 rescan_stage2
{} $after
522 set ui_status_value
{Refreshing
file status...
}
523 set cmd
[list git update-index
]
525 lappend cmd
--unmerged
526 lappend cmd
--ignore-missing
527 lappend cmd
--refresh
528 set fd_rf
[open
"| $cmd" r
]
529 fconfigure
$fd_rf -blocking 0 -translation binary
530 fileevent
$fd_rf readable \
531 [list rescan_stage2
$fd_rf $after]
535 proc rescan_stage2
{fd after
} {
536 global ui_status_value
537 global rescan_active buf_rdi buf_rdf buf_rlo
541 if {![eof
$fd]} return
545 set ls_others
[list | git ls-files
--others -z \
546 --exclude-per-directory=.gitignore
]
547 set info_exclude
[gitdir info exclude
]
548 if {[file readable
$info_exclude]} {
549 lappend ls_others
"--exclude-from=$info_exclude"
557 set ui_status_value
{Scanning
for modified files ...
}
558 set fd_di
[open
"| git diff-index --cached -z [PARENT]" r
]
559 set fd_df
[open
"| git diff-files -z" r
]
560 set fd_lo
[open
$ls_others r
]
562 fconfigure
$fd_di -blocking 0 -translation binary
-encoding binary
563 fconfigure
$fd_df -blocking 0 -translation binary
-encoding binary
564 fconfigure
$fd_lo -blocking 0 -translation binary
-encoding binary
565 fileevent
$fd_di readable
[list read_diff_index
$fd_di $after]
566 fileevent
$fd_df readable
[list read_diff_files
$fd_df $after]
567 fileevent
$fd_lo readable
[list read_ls_others
$fd_lo $after]
570 proc load_message
{file} {
574 if {[file isfile
$f]} {
575 if {[catch
{set fd
[open
$f r
]}]} {
578 set content
[string trim
[read $fd]]
580 regsub
-all -line {[ \r\t]+$
} $content {} content
581 $ui_comm delete
0.0 end
582 $ui_comm insert end
$content
588 proc read_diff_index
{fd after
} {
591 append buf_rdi
[read $fd]
593 set n
[string length
$buf_rdi]
595 set z1
[string first
"\0" $buf_rdi $c]
598 set z2
[string first
"\0" $buf_rdi $z1]
602 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
603 set p
[string range
$buf_rdi $z1 [expr {$z2 - 1}]]
605 [encoding convertfrom
$p] \
607 [list
[lindex
$i 0] [lindex
$i 2]] \
613 set buf_rdi
[string range
$buf_rdi $c end
]
618 rescan_done
$fd buf_rdi
$after
621 proc read_diff_files
{fd after
} {
624 append buf_rdf
[read $fd]
626 set n
[string length
$buf_rdf]
628 set z1
[string first
"\0" $buf_rdf $c]
631 set z2
[string first
"\0" $buf_rdf $z1]
635 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
636 set p
[string range
$buf_rdf $z1 [expr {$z2 - 1}]]
638 [encoding convertfrom
$p] \
641 [list
[lindex
$i 0] [lindex
$i 2]]
646 set buf_rdf
[string range
$buf_rdf $c end
]
651 rescan_done
$fd buf_rdf
$after
654 proc read_ls_others
{fd after
} {
657 append buf_rlo
[read $fd]
658 set pck
[split $buf_rlo "\0"]
659 set buf_rlo
[lindex
$pck end
]
660 foreach p
[lrange
$pck 0 end-1
] {
661 merge_state
[encoding convertfrom
$p] ?O
663 rescan_done
$fd buf_rlo
$after
666 proc rescan_done
{fd buf after
} {
668 global file_states repo_config
671 if {![eof
$fd]} return
674 if {[incr rescan_active
-1] > 0} return
683 proc prune_selection
{} {
684 global file_states selected_paths
686 foreach path
[array names selected_paths
] {
687 if {[catch
{set still_here
$file_states($path)}]} {
688 unset selected_paths
($path)
693 ######################################################################
698 global ui_diff current_diff_path current_diff_header
699 global ui_index ui_workdir
701 $ui_diff conf
-state normal
702 $ui_diff delete
0.0 end
703 $ui_diff conf
-state disabled
705 set current_diff_path
{}
706 set current_diff_header
{}
708 $ui_index tag remove in_diff
0.0 end
709 $ui_workdir tag remove in_diff
0.0 end
712 proc reshow_diff
{} {
713 global ui_status_value file_states file_lists
714 global current_diff_path current_diff_side
716 set p
$current_diff_path
718 # No diff is being shown.
719 } elseif
{$current_diff_side eq
{}
720 ||
[catch
{set s
$file_states($p)}]
721 ||
[lsearch
-sorted -exact $file_lists($current_diff_side) $p] == -1} {
724 show_diff
$p $current_diff_side
728 proc handle_empty_diff
{} {
729 global current_diff_path file_states file_lists
731 set path
$current_diff_path
732 set s
$file_states($path)
733 if {[lindex
$s 0] ne
{_M
}} return
735 info_popup
"No differences detected.
737 [short_path $path] has no changes.
739 The modification date of this file was updated by another application, but the content within the file was not changed.
741 A rescan will be automatically started to find other files which may have the same state."
744 display_file
$path __
745 rescan
{set ui_status_value
{Ready.
}} 0
748 proc show_diff
{path w
{lno
{}}} {
749 global file_states file_lists
750 global is_3way_diff diff_active repo_config
751 global ui_diff ui_status_value ui_index ui_workdir
752 global current_diff_path current_diff_side current_diff_header
754 if {$diff_active ||
![lock_index
read]} return
758 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
764 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
767 set s
$file_states($path)
771 set current_diff_path
$path
772 set current_diff_side
$w
773 set current_diff_header
{}
774 set ui_status_value
"Loading diff of [escape_path $path]..."
776 # - Git won't give us the diff, there's nothing to compare to!
779 set max_sz
[expr {128 * 1024}]
781 set fd
[open
$path r
]
782 set content
[read $fd $max_sz]
784 set sz
[file size
$path]
788 set ui_status_value
"Unable to display [escape_path $path]"
789 error_popup
"Error loading file:\n\n$err"
792 $ui_diff conf
-state normal
793 if {![catch
{set type [exec file $path]}]} {
794 set n
[string length
$path]
795 if {[string equal
-length $n $path $type]} {
796 set type [string range
$type $n end
]
797 regsub
{^
:?\s
*} $type {} type
799 $ui_diff insert end
"* $type\n" d_@
801 if {[string first
"\0" $content] != -1} {
802 $ui_diff insert end \
803 "* Binary file (not showing content)." \
807 $ui_diff insert end \
808 "* Untracked file is $sz bytes.
809 * Showing only first $max_sz bytes.
812 $ui_diff insert end
$content
814 $ui_diff insert end
"
815 * Untracked file clipped here by [appname].
816 * To see the entire file, use an external editor.
820 $ui_diff conf
-state disabled
823 set ui_status_value
{Ready.
}
828 if {$w eq
$ui_index} {
829 lappend cmd diff-index
831 } elseif
{$w eq
$ui_workdir} {
832 if {[string index
$m 0] eq
{U
}} {
835 lappend cmd diff-files
840 lappend cmd
--no-color
841 if {$repo_config(gui.diffcontext
) > 0} {
842 lappend cmd
"-U$repo_config(gui.diffcontext)"
844 if {$w eq
$ui_index} {
850 if {[catch
{set fd
[open
$cmd r
]} err
]} {
853 set ui_status_value
"Unable to display [escape_path $path]"
854 error_popup
"Error loading diff:\n\n$err"
862 fileevent
$fd readable
[list read_diff
$fd]
865 proc read_diff
{fd
} {
866 global ui_diff ui_status_value diff_active
867 global is_3way_diff current_diff_header
869 $ui_diff conf
-state normal
870 while {[gets
$fd line
] >= 0} {
871 # -- Cleanup uninteresting diff header lines.
873 if { [string match
{diff --git *} $line]
874 ||
[string match
{diff --cc *} $line]
875 ||
[string match
{diff --combined *} $line]
876 ||
[string match
{--- *} $line]
877 ||
[string match
{+++ *} $line]} {
878 append current_diff_header
$line "\n"
881 if {[string match
{index
*} $line]} continue
882 if {$line eq
{deleted
file mode
120000}} {
883 set line
"deleted symlink"
886 # -- Automatically detect if this is a 3 way diff.
888 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
890 if {[string match
{mode
*} $line]
891 ||
[string match
{new
file *} $line]
892 ||
[string match
{deleted
file *} $line]
893 ||
[string match
{Binary files
* and
* differ
} $line]
894 ||
$line eq
{\ No newline
at end of
file}
895 ||
[regexp
{^\
* Unmerged path
} $line]} {
897 } elseif
{$is_3way_diff} {
898 set op
[string range
$line 0 1]
908 if {[regexp
{^\
+\
+([<>]{7} |
={7})} $line _g op
]} {
909 set line
[string replace
$line 0 1 { }]
916 puts
"error: Unhandled 3 way diff marker: {$op}"
921 set op
[string index
$line 0]
927 if {[regexp
{^\
+([<>]{7} |
={7})} $line _g op
]} {
928 set line
[string replace
$line 0 0 { }]
935 puts
"error: Unhandled 2 way diff marker: {$op}"
940 $ui_diff insert end
$line $tags
941 if {[string index
$line end
] eq
"\r"} {
942 $ui_diff tag add d_cr
{end
- 2c
}
944 $ui_diff insert end
"\n" $tags
946 $ui_diff conf
-state disabled
952 set ui_status_value
{Ready.
}
954 if {[$ui_diff index end
] eq
{2.0}} {
960 proc apply_hunk
{x y
} {
961 global current_diff_path current_diff_header current_diff_side
962 global ui_diff ui_index file_states
964 if {$current_diff_path eq
{} ||
$current_diff_header eq
{}} return
965 if {![lock_index apply_hunk
]} return
967 set apply_cmd
{git apply
--cached --whitespace=nowarn
}
968 set mi
[lindex
$file_states($current_diff_path) 0]
969 if {$current_diff_side eq
$ui_index} {
971 lappend apply_cmd
--reverse
972 if {[string index
$mi 0] ne
{M
}} {
978 if {[string index
$mi 1] ne
{M
}} {
984 set s_lno
[lindex
[split [$ui_diff index @
$x,$y] .
] 0]
985 set s_lno
[$ui_diff search
-backwards -regexp ^@@
$s_lno.0 0.0]
991 set e_lno
[$ui_diff search
-forwards -regexp ^@@
"$s_lno + 1 lines" end
]
997 set p
[open
"| $apply_cmd" w
]
998 fconfigure
$p -translation binary
-encoding binary
999 puts
-nonewline $p $current_diff_header
1000 puts
-nonewline $p [$ui_diff get
$s_lno $e_lno]
1002 error_popup
"Failed to $mode selected hunk.\n\n$err"
1007 $ui_diff conf
-state normal
1008 $ui_diff delete
$s_lno $e_lno
1009 $ui_diff conf
-state disabled
1011 if {[$ui_diff get
1.0 end
] eq
"\n"} {
1017 if {$current_diff_side eq
$ui_index} {
1019 } elseif
{[string index
$mi 0] eq
{_
}} {
1025 display_file
$current_diff_path $mi
1031 ######################################################################
1035 proc load_last_commit
{} {
1036 global HEAD PARENT MERGE_HEAD commit_type ui_comm
1039 if {[llength
$PARENT] == 0} {
1040 error_popup
{There is nothing to amend.
1042 You are about to create the initial commit. There is no commit before this to amend.
1047 repository_state curType curHEAD curMERGE_HEAD
1048 if {$curType eq
{merge
}} {
1049 error_popup
{Cannot amend
while merging.
1051 You are currently
in the middle of a merge that has not been fully completed. You cannot amend the prior commit unless you first abort the current merge activity.
1059 set fd
[open
"| git cat-file commit $curHEAD" r
]
1060 fconfigure
$fd -encoding binary
-translation lf
1061 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1064 while {[gets
$fd line
] > 0} {
1065 if {[string match
{parent
*} $line]} {
1066 lappend parents
[string range
$line 7 end
]
1067 } elseif
{[string match
{encoding
*} $line]} {
1068 set enc
[string tolower
[string range
$line 9 end
]]
1071 set msg
[encoding convertfrom
$enc [read $fd]]
1072 set msg
[string trim
$msg]
1075 error_popup
"Error loading commit data for amend:\n\n$err"
1081 set MERGE_HEAD
[list
]
1082 switch
-- [llength
$parents] {
1083 0 {set commit_type amend-initial
}
1084 1 {set commit_type amend
}
1085 default
{set commit_type amend-merge
}
1088 $ui_comm delete
0.0 end
1089 $ui_comm insert end
$msg
1091 $ui_comm edit modified false
1092 rescan
{set ui_status_value
{Ready.
}}
1095 proc create_new_commit
{} {
1096 global commit_type ui_comm
1098 set commit_type normal
1099 $ui_comm delete
0.0 end
1101 $ui_comm edit modified false
1102 rescan
{set ui_status_value
{Ready.
}}
1105 set GIT_COMMITTER_IDENT
{}
1107 proc committer_ident
{} {
1108 global GIT_COMMITTER_IDENT
1110 if {$GIT_COMMITTER_IDENT eq
{}} {
1111 if {[catch
{set me
[git var GIT_COMMITTER_IDENT
]} err
]} {
1112 error_popup
"Unable to obtain your identity:\n\n$err"
1115 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
1116 $me me GIT_COMMITTER_IDENT
]} {
1117 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
1122 return $GIT_COMMITTER_IDENT
1125 proc commit_tree
{} {
1126 global HEAD commit_type file_states ui_comm repo_config
1127 global ui_status_value pch_error
1129 if {[committer_ident
] eq
{}} return
1130 if {![lock_index update
]} return
1132 # -- Our in memory state should match the repository.
1134 repository_state curType curHEAD curMERGE_HEAD
1135 if {[string match amend
* $commit_type]
1136 && $curType eq
{normal
}
1137 && $curHEAD eq
$HEAD} {
1138 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1139 info_popup
{Last scanned state does not match repository state.
1141 Another Git program has modified this repository since the last scan. A rescan must be performed before another commit can be created.
1143 The rescan will be automatically started now.
1146 rescan
{set ui_status_value
{Ready.
}}
1150 # -- At least one file should differ in the index.
1153 foreach path
[array names file_states
] {
1154 switch
-glob -- [lindex
$file_states($path) 0] {
1158 M?
{set files_ready
1}
1160 error_popup
"Unmerged files cannot be committed.
1162 File [short_path $path] has merge conflicts. You must resolve them and add the file before committing.
1168 error_popup
"Unknown file state [lindex $s 0] detected.
1170 File [short_path $path] cannot be committed by this program.
1175 if {!$files_ready && ![string match
*merge
$curType]} {
1176 info_popup
{No changes to commit.
1178 You must add
at least
1 file before you can commit.
1184 # -- A message is required.
1186 set msg
[string trim
[$ui_comm get
1.0 end
]]
1187 regsub
-all -line {[ \t\r]+$
} $msg {} msg
1189 error_popup
{Please supply a commit message.
1191 A good commit message has the following format
:
1193 - First line
: Describe
in one sentance what you did.
1194 - Second line
: Blank
1195 - Remaining lines
: Describe why this change is good.
1201 # -- Run the pre-commit hook.
1203 set pchook
[gitdir hooks pre-commit
]
1205 # On Cygwin [file executable] might lie so we need to ask
1206 # the shell if the hook is executable. Yes that's annoying.
1208 if {[is_Cygwin
] && [file isfile
$pchook]} {
1209 set pchook
[list sh
-c [concat \
1210 "if test -x \"$pchook\";" \
1211 "then exec \"$pchook\" 2>&1;" \
1213 } elseif
{[file executable
$pchook]} {
1214 set pchook
[list
$pchook |
& cat]
1216 commit_writetree
$curHEAD $msg
1220 set ui_status_value
{Calling pre-commit hook...
}
1222 set fd_ph
[open
"| $pchook" r
]
1223 fconfigure
$fd_ph -blocking 0 -translation binary
1224 fileevent
$fd_ph readable \
1225 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
1228 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
1229 global pch_error ui_status_value
1231 append pch_error
[read $fd_ph]
1232 fconfigure
$fd_ph -blocking 1
1234 if {[catch
{close
$fd_ph}]} {
1235 set ui_status_value
{Commit declined by pre-commit hook.
}
1236 hook_failed_popup pre-commit
$pch_error
1239 commit_writetree
$curHEAD $msg
1244 fconfigure
$fd_ph -blocking 0
1247 proc commit_writetree
{curHEAD msg
} {
1248 global ui_status_value
1250 set ui_status_value
{Committing changes...
}
1251 set fd_wt
[open
"| git write-tree" r
]
1252 fileevent
$fd_wt readable \
1253 [list commit_committree
$fd_wt $curHEAD $msg]
1256 proc commit_committree
{fd_wt curHEAD msg
} {
1257 global HEAD PARENT MERGE_HEAD commit_type
1258 global all_heads current_branch
1259 global ui_status_value ui_comm selected_commit_type
1260 global file_states selected_paths rescan_active
1264 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1265 error_popup
"write-tree failed:\n\n$err"
1266 set ui_status_value
{Commit failed.
}
1271 # -- Verify this wasn't an empty change.
1273 if {$commit_type eq
{normal
}} {
1274 set old_tree
[git rev-parse
"$PARENT^{tree}"]
1275 if {$tree_id eq
$old_tree} {
1276 info_popup
{No changes to commit.
1278 No files were modified by this commit and it was not a merge commit.
1280 A rescan will be automatically started now.
1283 rescan
{set ui_status_value
{No changes to commit.
}}
1288 # -- Build the message.
1290 set msg_p
[gitdir COMMIT_EDITMSG
]
1291 set msg_wt
[open
$msg_p w
]
1292 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1295 fconfigure
$msg_wt -encoding binary
-translation binary
1296 puts
-nonewline $msg_wt [encoding convertto
$enc $msg]
1299 # -- Create the commit.
1301 set cmd
[list git commit-tree
$tree_id]
1302 foreach p
[concat
$PARENT $MERGE_HEAD] {
1306 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1307 error_popup
"commit-tree failed:\n\n$err"
1308 set ui_status_value
{Commit failed.
}
1313 # -- Update the HEAD ref.
1316 if {$commit_type ne
{normal
}} {
1317 append reflogm
" ($commit_type)"
1319 set i
[string first
"\n" $msg]
1321 set subject
[string range
$msg 0 [expr {$i - 1}]]
1325 append reflogm
{: } $subject
1326 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1327 if {[catch
{eval exec $cmd} err
]} {
1328 error_popup
"update-ref failed:\n\n$err"
1329 set ui_status_value
{Commit failed.
}
1334 # -- Cleanup after ourselves.
1336 catch
{file delete
$msg_p}
1337 catch
{file delete
[gitdir MERGE_HEAD
]}
1338 catch
{file delete
[gitdir MERGE_MSG
]}
1339 catch
{file delete
[gitdir SQUASH_MSG
]}
1340 catch
{file delete
[gitdir GITGUI_MSG
]}
1342 # -- Let rerere do its thing.
1344 if {[file isdirectory
[gitdir rr-cache
]]} {
1348 # -- Run the post-commit hook.
1350 set pchook
[gitdir hooks post-commit
]
1351 if {[is_Cygwin
] && [file isfile
$pchook]} {
1352 set pchook
[list sh
-c [concat \
1353 "if test -x \"$pchook\";" \
1354 "then exec \"$pchook\";" \
1356 } elseif
{![file executable
$pchook]} {
1359 if {$pchook ne
{}} {
1360 catch
{exec $pchook &}
1363 $ui_comm delete
0.0 end
1365 $ui_comm edit modified false
1367 if {[is_enabled singlecommit
]} do_quit
1369 # -- Make sure our current branch exists.
1371 if {$commit_type eq
{initial
}} {
1372 lappend all_heads
$current_branch
1373 set all_heads
[lsort
-unique $all_heads]
1374 populate_branch_menu
1377 # -- Update in memory status
1379 set selected_commit_type new
1380 set commit_type normal
1383 set MERGE_HEAD
[list
]
1385 foreach path
[array names file_states
] {
1386 set s
$file_states($path)
1388 switch
-glob -- $m {
1396 unset file_states
($path)
1397 catch
{unset selected_paths
($path)}
1400 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1406 set file_states
($path) [list \
1407 _
[string index
$m 1] \
1418 set ui_status_value \
1419 "Created commit [string range $cmt_id 0 7]: $subject"
1422 ######################################################################
1426 proc fetch_from
{remote
} {
1427 set w
[new_console \
1429 "Fetching new changes from $remote"]
1430 set cmd
[list git fetch
]
1432 console_exec
$w $cmd console_done
1435 proc push_to
{remote
} {
1436 set w
[new_console \
1438 "Pushing changes to $remote"]
1439 set cmd
[list git push
]
1442 console_exec
$w $cmd console_done
1445 ######################################################################
1449 proc mapicon
{w state path
} {
1452 if {[catch
{set r
$all_icons($state$w)}]} {
1453 puts
"error: no icon for $w state={$state} $path"
1459 proc mapdesc
{state path
} {
1462 if {[catch
{set r
$all_descs($state)}]} {
1463 puts
"error: no desc for state={$state} $path"
1469 proc escape_path
{path
} {
1470 regsub
-all {\\} $path "\\\\" path
1471 regsub
-all "\n" $path "\\n" path
1475 proc short_path
{path
} {
1476 return [escape_path
[lindex
[file split $path] end
]]
1480 set null_sha1
[string repeat
0 40]
1482 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1483 global file_states next_icon_id null_sha1
1485 set s0
[string index
$new_state 0]
1486 set s1
[string index
$new_state 1]
1488 if {[catch
{set info
$file_states($path)}]} {
1490 set icon n
[incr next_icon_id
]
1492 set state
[lindex
$info 0]
1493 set icon
[lindex
$info 1]
1494 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1495 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1498 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1499 elseif
{$s0 eq
{_
}} {set s0 _
}
1501 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1502 elseif
{$s1 eq
{_
}} {set s1 _
}
1504 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1505 set head_info
[list
0 $null_sha1]
1506 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1507 && $head_info eq
{}} {
1508 set head_info
$index_info
1511 set file_states
($path) [list
$s0$s1 $icon \
1512 $head_info $index_info \
1517 proc display_file_helper
{w path icon_name old_m new_m
} {
1520 if {$new_m eq
{_
}} {
1521 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1523 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1525 $w conf
-state normal
1526 $w delete
$lno.0 [expr {$lno + 1}].0
1527 $w conf
-state disabled
1529 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1530 lappend file_lists
($w) $path
1531 set file_lists
($w) [lsort
-unique $file_lists($w)]
1532 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1534 $w conf
-state normal
1535 $w image create
$lno.0 \
1536 -align center
-padx 5 -pady 1 \
1538 -image [mapicon
$w $new_m $path]
1539 $w insert
$lno.1 "[escape_path $path]\n"
1540 $w conf
-state disabled
1541 } elseif
{$old_m ne
$new_m} {
1542 $w conf
-state normal
1543 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1544 $w conf
-state disabled
1548 proc display_file
{path state
} {
1549 global file_states selected_paths
1550 global ui_index ui_workdir
1552 set old_m
[merge_state
$path $state]
1553 set s
$file_states($path)
1554 set new_m
[lindex
$s 0]
1555 set icon_name
[lindex
$s 1]
1557 set o
[string index
$old_m 0]
1558 set n
[string index
$new_m 0]
1565 display_file_helper
$ui_index $path $icon_name $o $n
1567 if {[string index
$old_m 0] eq
{U
}} {
1570 set o
[string index
$old_m 1]
1572 if {[string index
$new_m 0] eq
{U
}} {
1575 set n
[string index
$new_m 1]
1577 display_file_helper
$ui_workdir $path $icon_name $o $n
1579 if {$new_m eq
{__
}} {
1580 unset file_states
($path)
1581 catch
{unset selected_paths
($path)}
1585 proc display_all_files_helper
{w path icon_name m
} {
1588 lappend file_lists
($w) $path
1589 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1590 $w image create end \
1591 -align center
-padx 5 -pady 1 \
1593 -image [mapicon
$w $m $path]
1594 $w insert end
"[escape_path $path]\n"
1597 proc display_all_files
{} {
1598 global ui_index ui_workdir
1599 global file_states file_lists
1602 $ui_index conf
-state normal
1603 $ui_workdir conf
-state normal
1605 $ui_index delete
0.0 end
1606 $ui_workdir delete
0.0 end
1609 set file_lists
($ui_index) [list
]
1610 set file_lists
($ui_workdir) [list
]
1612 foreach path
[lsort
[array names file_states
]] {
1613 set s
$file_states($path)
1615 set icon_name
[lindex
$s 1]
1617 set s
[string index
$m 0]
1618 if {$s ne
{U
} && $s ne
{_
}} {
1619 display_all_files_helper
$ui_index $path \
1623 if {[string index
$m 0] eq
{U
}} {
1626 set s
[string index
$m 1]
1629 display_all_files_helper
$ui_workdir $path \
1634 $ui_index conf
-state disabled
1635 $ui_workdir conf
-state disabled
1638 proc update_indexinfo
{msg pathList after
} {
1639 global update_index_cp ui_status_value
1641 if {![lock_index update
]} return
1643 set update_index_cp
0
1644 set pathList
[lsort
$pathList]
1645 set totalCnt
[llength
$pathList]
1646 set batch [expr {int
($totalCnt * .01) + 1}]
1647 if {$batch > 25} {set batch 25}
1649 set ui_status_value
[format \
1650 "$msg... %i/%i files (%.2f%%)" \
1654 set fd
[open
"| git update-index -z --index-info" w
]
1661 fileevent
$fd writable
[list \
1662 write_update_indexinfo \
1672 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1673 global update_index_cp ui_status_value
1674 global file_states current_diff_path
1676 if {$update_index_cp >= $totalCnt} {
1683 for {set i
$batch} \
1684 {$update_index_cp < $totalCnt && $i > 0} \
1686 set path
[lindex
$pathList $update_index_cp]
1687 incr update_index_cp
1689 set s
$file_states($path)
1690 switch
-glob -- [lindex
$s 0] {
1697 set info
[lindex
$s 2]
1698 if {$info eq
{}} continue
1700 puts
-nonewline $fd "$info\t[encoding convertto $path]\0"
1701 display_file
$path $new
1704 set ui_status_value
[format \
1705 "$msg... %i/%i files (%.2f%%)" \
1708 [expr {100.0 * $update_index_cp / $totalCnt}]]
1711 proc update_index
{msg pathList after
} {
1712 global update_index_cp ui_status_value
1714 if {![lock_index update
]} return
1716 set update_index_cp
0
1717 set pathList
[lsort
$pathList]
1718 set totalCnt
[llength
$pathList]
1719 set batch [expr {int
($totalCnt * .01) + 1}]
1720 if {$batch > 25} {set batch 25}
1722 set ui_status_value
[format \
1723 "$msg... %i/%i files (%.2f%%)" \
1727 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1734 fileevent
$fd writable
[list \
1735 write_update_index \
1745 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1746 global update_index_cp ui_status_value
1747 global file_states current_diff_path
1749 if {$update_index_cp >= $totalCnt} {
1756 for {set i
$batch} \
1757 {$update_index_cp < $totalCnt && $i > 0} \
1759 set path
[lindex
$pathList $update_index_cp]
1760 incr update_index_cp
1762 switch
-glob -- [lindex
$file_states($path) 0] {
1768 if {[file exists
$path]} {
1777 puts
-nonewline $fd "[encoding convertto $path]\0"
1778 display_file
$path $new
1781 set ui_status_value
[format \
1782 "$msg... %i/%i files (%.2f%%)" \
1785 [expr {100.0 * $update_index_cp / $totalCnt}]]
1788 proc checkout_index
{msg pathList after
} {
1789 global update_index_cp ui_status_value
1791 if {![lock_index update
]} return
1793 set update_index_cp
0
1794 set pathList
[lsort
$pathList]
1795 set totalCnt
[llength
$pathList]
1796 set batch [expr {int
($totalCnt * .01) + 1}]
1797 if {$batch > 25} {set batch 25}
1799 set ui_status_value
[format \
1800 "$msg... %i/%i files (%.2f%%)" \
1804 set cmd
[list git checkout-index
]
1810 set fd
[open
"| $cmd " w
]
1817 fileevent
$fd writable
[list \
1818 write_checkout_index \
1828 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1829 global update_index_cp ui_status_value
1830 global file_states current_diff_path
1832 if {$update_index_cp >= $totalCnt} {
1839 for {set i
$batch} \
1840 {$update_index_cp < $totalCnt && $i > 0} \
1842 set path
[lindex
$pathList $update_index_cp]
1843 incr update_index_cp
1844 switch
-glob -- [lindex
$file_states($path) 0] {
1848 puts
-nonewline $fd "[encoding convertto $path]\0"
1849 display_file
$path ?_
1854 set ui_status_value
[format \
1855 "$msg... %i/%i files (%.2f%%)" \
1858 [expr {100.0 * $update_index_cp / $totalCnt}]]
1861 ######################################################################
1863 ## branch management
1865 proc is_tracking_branch
{name
} {
1866 global tracking_branches
1868 if {![catch
{set info
$tracking_branches($name)}]} {
1871 foreach t
[array names tracking_branches
] {
1872 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1879 proc load_all_heads
{} {
1882 set all_heads
[list
]
1883 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1884 while {[gets
$fd line
] > 0} {
1885 if {[is_tracking_branch
$line]} continue
1886 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1887 lappend all_heads
$name
1891 set all_heads
[lsort
$all_heads]
1894 proc populate_branch_menu
{} {
1895 global all_heads disable_on_lock
1898 set last
[$m index last
]
1899 for {set i
0} {$i <= $last} {incr i
} {
1900 if {[$m type $i] eq
{separator
}} {
1903 foreach a
$disable_on_lock {
1904 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1908 set disable_on_lock
$new_dol
1913 if {$all_heads ne
{}} {
1916 foreach b
$all_heads {
1917 $m add radiobutton \
1919 -command [list switch_branch
$b] \
1920 -variable current_branch \
1922 lappend disable_on_lock \
1923 [list
$m entryconf
[$m index last
] -state]
1927 proc all_tracking_branches
{} {
1928 global tracking_branches
1930 set all_trackings
{}
1932 foreach name
[array names tracking_branches
] {
1933 if {[regsub
{/\
*$
} $name {} name
]} {
1936 regsub ^refs
/(heads|remotes
)/ $name {} name
1937 lappend all_trackings
$name
1942 set fd
[open
"| git for-each-ref --format=%(refname) $cmd" r
]
1943 while {[gets
$fd name
] > 0} {
1944 regsub ^refs
/(heads|remotes
)/ $name {} name
1945 lappend all_trackings
$name
1950 return [lsort
-unique $all_trackings]
1953 proc load_all_tags
{} {
1955 set fd
[open
"| git for-each-ref --format=%(refname) refs/tags" r
]
1956 while {[gets
$fd line
] > 0} {
1957 if {![regsub ^refs
/tags
/ $line {} name
]} continue
1958 lappend all_tags
$name
1962 return [lsort
$all_tags]
1965 proc do_create_branch_action
{w
} {
1966 global all_heads null_sha1 repo_config
1967 global create_branch_checkout create_branch_revtype
1968 global create_branch_head create_branch_trackinghead
1969 global create_branch_name create_branch_revexp
1970 global create_branch_tag
1972 set newbranch
$create_branch_name
1973 if {$newbranch eq
{}
1974 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1978 -title [wm title
$w] \
1980 -message "Please supply a branch name."
1981 focus
$w.desc.name_t
1984 if {![catch
{git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1988 -title [wm title
$w] \
1990 -message "Branch '$newbranch' already exists."
1991 focus
$w.desc.name_t
1994 if {[catch
{git check-ref-format
"heads/$newbranch"}]} {
1998 -title [wm title
$w] \
2000 -message "We do not like '$newbranch' as a branch name."
2001 focus
$w.desc.name_t
2006 switch
-- $create_branch_revtype {
2007 head {set rev $create_branch_head}
2008 tracking
{set rev $create_branch_trackinghead}
2009 tag
{set rev $create_branch_tag}
2010 expression
{set rev $create_branch_revexp}
2012 if {[catch
{set cmt
[git rev-parse
--verify "${rev}^0"]}]} {
2016 -title [wm title
$w] \
2018 -message "Invalid starting revision: $rev"
2021 set cmd
[list git update-ref
]
2023 lappend cmd
"branch: Created from $rev"
2024 lappend cmd
"refs/heads/$newbranch"
2026 lappend cmd
$null_sha1
2027 if {[catch
{eval exec $cmd} err
]} {
2031 -title [wm title
$w] \
2033 -message "Failed to create '$newbranch'.\n\n$err"
2037 lappend all_heads
$newbranch
2038 set all_heads
[lsort
$all_heads]
2039 populate_branch_menu
2041 if {$create_branch_checkout} {
2042 switch_branch
$newbranch
2046 proc radio_selector
{varname value args
} {
2047 upvar
#0 $varname var
2051 trace add variable create_branch_head
write \
2052 [list radio_selector create_branch_revtype
head]
2053 trace add variable create_branch_trackinghead
write \
2054 [list radio_selector create_branch_revtype tracking
]
2055 trace add variable create_branch_tag
write \
2056 [list radio_selector create_branch_revtype tag
]
2058 trace add variable delete_branch_head
write \
2059 [list radio_selector delete_branch_checktype
head]
2060 trace add variable delete_branch_trackinghead
write \
2061 [list radio_selector delete_branch_checktype tracking
]
2063 proc do_create_branch
{} {
2064 global all_heads current_branch repo_config
2065 global create_branch_checkout create_branch_revtype
2066 global create_branch_head create_branch_trackinghead
2067 global create_branch_name create_branch_revexp
2068 global create_branch_tag
2070 set w .branch_editor
2072 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2074 label
$w.header
-text {Create New Branch
} \
2076 pack
$w.header
-side top
-fill x
2079 button
$w.buttons.create
-text Create \
2081 -command [list do_create_branch_action
$w]
2082 pack
$w.buttons.create
-side right
2083 button
$w.buttons.cancel
-text {Cancel
} \
2084 -command [list destroy
$w]
2085 pack
$w.buttons.cancel
-side right
-padx 5
2086 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2088 labelframe
$w.desc
-text {Branch Description
}
2089 label
$w.desc.name_l
-text {Name
:}
2090 entry
$w.desc.name_t \
2094 -textvariable create_branch_name \
2097 if {%d
== 1 && [regexp
{[~^
:?
*\
[\
0- ]} %S
]} {return 0}
2100 grid
$w.desc.name_l
$w.desc.name_t
-sticky we
-padx {0 5}
2101 grid columnconfigure
$w.desc
1 -weight 1
2102 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
2104 labelframe
$w.from
-text {Starting Revision
}
2105 radiobutton
$w.from.head_r \
2106 -text {Local Branch
:} \
2108 -variable create_branch_revtype
2109 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
2110 grid
$w.from.head_r
$w.from.head_m
-sticky w
2111 set all_trackings
[all_tracking_branches
]
2112 if {$all_trackings ne
{}} {
2113 set create_branch_trackinghead
[lindex
$all_trackings 0]
2114 radiobutton
$w.from.tracking_r \
2115 -text {Tracking Branch
:} \
2117 -variable create_branch_revtype
2118 eval tk_optionMenu
$w.from.tracking_m \
2119 create_branch_trackinghead \
2121 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
2123 set all_tags
[load_all_tags
]
2124 if {$all_tags ne
{}} {
2125 set create_branch_tag
[lindex
$all_tags 0]
2126 radiobutton
$w.from.tag_r \
2129 -variable create_branch_revtype
2130 eval tk_optionMenu
$w.from.tag_m create_branch_tag
$all_tags
2131 grid
$w.from.tag_r
$w.from.tag_m
-sticky w
2133 radiobutton
$w.from.exp_r \
2134 -text {Revision Expression
:} \
2136 -variable create_branch_revtype
2137 entry
$w.from.exp_t \
2141 -textvariable create_branch_revexp \
2144 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2145 if {%d
== 1 && [string length
%S
] > 0} {
2146 set create_branch_revtype expression
2150 grid
$w.from.exp_r
$w.from.exp_t
-sticky we
-padx {0 5}
2151 grid columnconfigure
$w.from
1 -weight 1
2152 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
2154 labelframe
$w.postActions
-text {Post Creation Actions
}
2155 checkbutton
$w.postActions.checkout \
2156 -text {Checkout after creation
} \
2157 -variable create_branch_checkout
2158 pack
$w.postActions.checkout
-anchor nw
2159 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
2161 set create_branch_checkout
1
2162 set create_branch_head
$current_branch
2163 set create_branch_revtype
head
2164 set create_branch_name
$repo_config(gui.newbranchtemplate
)
2165 set create_branch_revexp
{}
2167 bind $w <Visibility
> "
2169 $w.desc.name_t icursor end
2170 focus $w.desc.name_t
2172 bind $w <Key-Escape
> "destroy $w"
2173 bind $w <Key-Return
> "do_create_branch_action $w;break"
2174 wm title
$w "[appname] ([reponame]): Create Branch"
2178 proc do_delete_branch_action
{w
} {
2180 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2183 switch
-- $delete_branch_checktype {
2184 head {set check_rev
$delete_branch_head}
2185 tracking
{set check_rev
$delete_branch_trackinghead}
2186 always
{set check_rev
{:none
}}
2188 if {$check_rev eq
{:none
}} {
2190 } elseif
{[catch
{set check_cmt
[git rev-parse
--verify "${check_rev}^0"]}]} {
2194 -title [wm title
$w] \
2196 -message "Invalid check revision: $check_rev"
2200 set to_delete
[list
]
2201 set not_merged
[list
]
2202 foreach i
[$w.list.l curselection
] {
2203 set b
[$w.list.l get
$i]
2204 if {[catch
{set o
[git rev-parse
--verify $b]}]} continue
2205 if {$check_cmt ne
{}} {
2206 if {$b eq
$check_rev} continue
2207 if {[catch
{set m
[git merge-base
$o $check_cmt]}]} continue
2209 lappend not_merged
$b
2213 lappend to_delete
[list
$b $o]
2215 if {$not_merged ne
{}} {
2216 set msg
"The following branches are not completely merged into $check_rev:
2218 - [join $not_merged "\n - "]"
2222 -title [wm title
$w] \
2226 if {$to_delete eq
{}} return
2227 if {$delete_branch_checktype eq
{always
}} {
2228 set msg
{Recovering deleted branches is difficult.
2230 Delete the selected branches?
}
2231 if {[tk_messageBox \
2234 -title [wm title
$w] \
2236 -message $msg] ne
yes} {
2242 foreach i
$to_delete {
2245 if {[catch
{git update-ref
-d "refs/heads/$b" $o} err
]} {
2246 append failed
" - $b: $err\n"
2248 set x
[lsearch
-sorted -exact $all_heads $b]
2250 set all_heads
[lreplace
$all_heads $x $x]
2255 if {$failed ne
{}} {
2259 -title [wm title
$w] \
2261 -message "Failed to delete branches:\n$failed"
2264 set all_heads
[lsort
$all_heads]
2265 populate_branch_menu
2269 proc do_delete_branch
{} {
2270 global all_heads tracking_branches current_branch
2271 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2273 set w .branch_editor
2275 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2277 label
$w.header
-text {Delete Local Branch
} \
2279 pack
$w.header
-side top
-fill x
2282 button
$w.buttons.create
-text Delete \
2283 -command [list do_delete_branch_action
$w]
2284 pack
$w.buttons.create
-side right
2285 button
$w.buttons.cancel
-text {Cancel
} \
2286 -command [list destroy
$w]
2287 pack
$w.buttons.cancel
-side right
-padx 5
2288 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2290 labelframe
$w.list
-text {Local Branches
}
2294 -selectmode extended \
2295 -yscrollcommand [list
$w.list.sby
set]
2296 foreach h
$all_heads {
2297 if {$h ne
$current_branch} {
2298 $w.list.l insert end
$h
2301 scrollbar
$w.list.sby
-command [list
$w.list.l yview
]
2302 pack
$w.list.sby
-side right
-fill y
2303 pack
$w.list.l
-side left
-fill both
-expand 1
2304 pack
$w.list
-fill both
-expand 1 -pady 5 -padx 5
2306 labelframe
$w.validate
-text {Delete Only If
}
2307 radiobutton
$w.validate.head_r \
2308 -text {Merged Into Local Branch
:} \
2310 -variable delete_branch_checktype
2311 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2312 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2313 set all_trackings
[all_tracking_branches
]
2314 if {$all_trackings ne
{}} {
2315 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2316 radiobutton
$w.validate.tracking_r \
2317 -text {Merged Into Tracking Branch
:} \
2319 -variable delete_branch_checktype
2320 eval tk_optionMenu
$w.validate.tracking_m \
2321 delete_branch_trackinghead \
2323 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2325 radiobutton
$w.validate.always_r \
2326 -text {Always
(Do not perform merge checks
)} \
2328 -variable delete_branch_checktype
2329 grid
$w.validate.always_r
-columnspan 2 -sticky w
2330 grid columnconfigure
$w.validate
1 -weight 1
2331 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2333 set delete_branch_head
$current_branch
2334 set delete_branch_checktype
head
2336 bind $w <Visibility
> "grab $w; focus $w"
2337 bind $w <Key-Escape
> "destroy $w"
2338 wm title
$w "[appname] ([reponame]): Delete Branch"
2342 proc switch_branch
{new_branch
} {
2343 global HEAD commit_type current_branch repo_config
2345 if {![lock_index switch
]} return
2347 # -- Our in memory state should match the repository.
2349 repository_state curType curHEAD curMERGE_HEAD
2350 if {[string match amend
* $commit_type]
2351 && $curType eq
{normal
}
2352 && $curHEAD eq
$HEAD} {
2353 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2354 info_popup
{Last scanned state does not match repository state.
2356 Another Git program has modified this repository since the last scan. A rescan must be performed before the current branch can be changed.
2358 The rescan will be automatically started now.
2361 rescan
{set ui_status_value
{Ready.
}}
2365 # -- Don't do a pointless switch.
2367 if {$current_branch eq
$new_branch} {
2372 if {$repo_config(gui.trustmtime
) eq
{true
}} {
2373 switch_branch_stage2
{} $new_branch
2375 set ui_status_value
{Refreshing
file status...
}
2376 set cmd
[list git update-index
]
2378 lappend cmd
--unmerged
2379 lappend cmd
--ignore-missing
2380 lappend cmd
--refresh
2381 set fd_rf
[open
"| $cmd" r
]
2382 fconfigure
$fd_rf -blocking 0 -translation binary
2383 fileevent
$fd_rf readable \
2384 [list switch_branch_stage2
$fd_rf $new_branch]
2388 proc switch_branch_stage2
{fd_rf new_branch
} {
2389 global ui_status_value HEAD
2393 if {![eof
$fd_rf]} return
2397 set ui_status_value
"Updating working directory to '$new_branch'..."
2398 set cmd
[list git read-tree
]
2401 lappend cmd
--exclude-per-directory=.gitignore
2403 lappend cmd
$new_branch
2404 set fd_rt
[open
"| $cmd" r
]
2405 fconfigure
$fd_rt -blocking 0 -translation binary
2406 fileevent
$fd_rt readable \
2407 [list switch_branch_readtree_wait
$fd_rt $new_branch]
2410 proc switch_branch_readtree_wait
{fd_rt new_branch
} {
2411 global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
2412 global current_branch
2413 global ui_comm ui_status_value
2415 # -- We never get interesting output on stdout; only stderr.
2418 fconfigure
$fd_rt -blocking 1
2419 if {![eof
$fd_rt]} {
2420 fconfigure
$fd_rt -blocking 0
2424 # -- The working directory wasn't in sync with the index and
2425 # we'd have to overwrite something to make the switch. A
2426 # merge is required.
2428 if {[catch
{close
$fd_rt} err
]} {
2429 regsub
{^fatal
: } $err {} err
2430 warn_popup
"File level merge required.
2434 Staying on branch '$current_branch'."
2435 set ui_status_value
"Aborted checkout of '$new_branch' (file level merging is required)."
2440 # -- Update the symbolic ref. Core git doesn't even check for failure
2441 # here, it Just Works(tm). If it doesn't we are in some really ugly
2442 # state that is difficult to recover from within git-gui.
2444 if {[catch
{git symbolic-ref HEAD
"refs/heads/$new_branch"} err
]} {
2445 error_popup
"Failed to set current branch.
2447 This working directory is only partially switched. We successfully updated your files, but failed to update an internal Git file.
2449 This should not have occurred. [appname] will now close and give up.
2456 # -- Update our repository state. If we were previously in amend mode
2457 # we need to toss the current buffer and do a full rescan to update
2458 # our file lists. If we weren't in amend mode our file lists are
2459 # accurate and we can avoid the rescan.
2462 set selected_commit_type new
2463 if {[string match amend
* $commit_type]} {
2464 $ui_comm delete
0.0 end
2466 $ui_comm edit modified false
2467 rescan
{set ui_status_value
"Checked out branch '$current_branch'."}
2469 repository_state commit_type HEAD MERGE_HEAD
2471 set ui_status_value
"Checked out branch '$current_branch'."
2475 ######################################################################
2477 ## remote management
2479 proc load_all_remotes
{} {
2481 global all_remotes tracking_branches
2483 set all_remotes
[list
]
2484 array
unset tracking_branches
2486 set rm_dir
[gitdir remotes
]
2487 if {[file isdirectory
$rm_dir]} {
2488 set all_remotes
[glob \
2492 -directory $rm_dir *]
2494 foreach name
$all_remotes {
2496 set fd
[open
[file join $rm_dir $name] r
]
2497 while {[gets
$fd line
] >= 0} {
2498 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2499 $line line src dst
]} continue
2500 if {![regexp ^refs
/ $dst]} {
2501 set dst
"refs/heads/$dst"
2503 set tracking_branches
($dst) [list
$name $src]
2510 foreach line
[array names repo_config remote.
*.url
] {
2511 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2512 lappend all_remotes
$name
2514 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2518 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2519 if {![regexp ^refs
/ $dst]} {
2520 set dst
"refs/heads/$dst"
2522 set tracking_branches
($dst) [list
$name $src]
2526 set all_remotes
[lsort
-unique $all_remotes]
2529 proc populate_fetch_menu
{} {
2530 global all_remotes repo_config
2533 foreach r
$all_remotes {
2535 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2536 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2541 set fd
[open
[gitdir remotes
$r] r
]
2542 while {[gets
$fd n
] >= 0} {
2543 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2554 -label "Fetch from $r..." \
2555 -command [list fetch_from
$r]
2560 proc populate_push_menu
{} {
2561 global all_remotes repo_config
2565 foreach r
$all_remotes {
2567 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2568 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2573 set fd
[open
[gitdir remotes
$r] r
]
2574 while {[gets
$fd n
] >= 0} {
2575 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2589 -label "Push to $r..." \
2590 -command [list push_to
$r]
2596 proc start_push_anywhere_action
{w
} {
2597 global push_urltype push_remote push_url push_thin push_tags
2600 switch
-- $push_urltype {
2601 remote
{set r_url
$push_remote}
2602 url
{set r_url
$push_url}
2604 if {$r_url eq
{}} return
2606 set cmd
[list git push
]
2616 foreach i
[$w.
source.l curselection
] {
2617 set b
[$w.
source.l get
$i]
2618 lappend cmd
"refs/heads/$b:refs/heads/$b"
2623 } elseif
{$cnt == 1} {
2629 set cons
[new_console
"push $r_url" "Pushing $cnt $unit to $r_url"]
2630 console_exec
$cons $cmd console_done
2634 trace add variable push_remote
write \
2635 [list radio_selector push_urltype remote
]
2637 proc do_push_anywhere
{} {
2638 global all_heads all_remotes current_branch
2639 global push_urltype push_remote push_url push_thin push_tags
2643 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2645 label
$w.header
-text {Push Branches
} -font font_uibold
2646 pack
$w.header
-side top
-fill x
2649 button
$w.buttons.create
-text Push \
2651 -command [list start_push_anywhere_action
$w]
2652 pack
$w.buttons.create
-side right
2653 button
$w.buttons.cancel
-text {Cancel
} \
2655 -command [list destroy
$w]
2656 pack
$w.buttons.cancel
-side right
-padx 5
2657 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2659 labelframe
$w.
source -text {Source Branches
}
2660 listbox
$w.
source.l \
2663 -selectmode extended \
2664 -yscrollcommand [list
$w.
source.sby
set]
2665 foreach h
$all_heads {
2666 $w.
source.l insert end
$h
2667 if {$h eq
$current_branch} {
2668 $w.
source.l
select set end
2671 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2672 pack
$w.
source.sby
-side right
-fill y
2673 pack
$w.
source.l
-side left
-fill both
-expand 1
2674 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2676 labelframe
$w.dest
-text {Destination Repository
}
2677 if {$all_remotes ne
{}} {
2678 radiobutton
$w.dest.remote_r \
2681 -variable push_urltype
2682 eval tk_optionMenu
$w.dest.remote_m push_remote
$all_remotes
2683 grid
$w.dest.remote_r
$w.dest.remote_m
-sticky w
2684 if {[lsearch
-sorted -exact $all_remotes origin
] != -1} {
2685 set push_remote origin
2687 set push_remote
[lindex
$all_remotes 0]
2689 set push_urltype remote
2691 set push_urltype url
2693 radiobutton
$w.dest.url_r \
2694 -text {Arbitrary URL
:} \
2696 -variable push_urltype
2697 entry
$w.dest.url_t \
2701 -textvariable push_url \
2704 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2705 if {%d
== 1 && [string length
%S
] > 0} {
2706 set push_urltype url
2710 grid
$w.dest.url_r
$w.dest.url_t
-sticky we
-padx {0 5}
2711 grid columnconfigure
$w.dest
1 -weight 1
2712 pack
$w.dest
-anchor nw
-fill x
-pady 5 -padx 5
2714 labelframe
$w.options
-text {Transfer Options
}
2715 checkbutton
$w.options.thin \
2716 -text {Use thin pack
(for slow network connections
)} \
2718 grid
$w.options.thin
-columnspan 2 -sticky w
2719 checkbutton
$w.options.tags \
2720 -text {Include tags
} \
2722 grid
$w.options.tags
-columnspan 2 -sticky w
2723 grid columnconfigure
$w.options
1 -weight 1
2724 pack
$w.options
-anchor nw
-fill x
-pady 5 -padx 5
2730 bind $w <Visibility
> "grab $w; focus $w.buttons.create"
2731 bind $w <Key-Escape
> "destroy $w"
2732 bind $w <Key-Return
> [list start_push_anywhere_action
$w]
2733 wm title
$w "[appname] ([reponame]): Push"
2737 ######################################################################
2742 global HEAD commit_type file_states
2744 if {[string match amend
* $commit_type]} {
2745 info_popup
{Cannot merge
while amending.
2747 You must finish amending this commit before starting any
type of merge.
2752 if {[committer_ident
] eq
{}} {return 0}
2753 if {![lock_index merge
]} {return 0}
2755 # -- Our in memory state should match the repository.
2757 repository_state curType curHEAD curMERGE_HEAD
2758 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2759 info_popup
{Last scanned state does not match repository state.
2761 Another Git program has modified this repository since the last scan. A rescan must be performed before a merge can be performed.
2763 The rescan will be automatically started now.
2766 rescan
{set ui_status_value
{Ready.
}}
2770 foreach path
[array names file_states
] {
2771 switch
-glob -- [lindex
$file_states($path) 0] {
2773 continue; # and pray it works!
2776 error_popup
"You are in the middle of a conflicted merge.
2778 File [short_path $path] has merge conflicts.
2780 You must resolve them, add the file, and commit to complete the current merge. Only then can you begin another merge.
2786 error_popup
"You are in the middle of a change.
2788 File [short_path $path] is modified.
2790 You should complete the current commit before starting a merge. Doing so will help you abort a failed merge, should the need arise.
2801 proc visualize_local_merge
{w
} {
2803 foreach i
[$w.
source.l curselection
] {
2804 lappend revs
[$w.
source.l get
$i]
2806 if {$revs eq
{}} return
2807 lappend revs
--not HEAD
2811 proc start_local_merge_action
{w
} {
2812 global HEAD ui_status_value current_branch
2814 set cmd
[list git merge
]
2817 foreach i
[$w.
source.l curselection
] {
2818 set b
[$w.
source.l get
$i]
2826 } elseif
{$revcnt == 1} {
2828 } elseif
{$revcnt <= 15} {
2832 $w.confirm_octopus \
2834 "Use octopus merge strategy?
2836 You are merging $revcnt branches at once. This requires using the octopus merge driver, which may not succeed if there are file-level conflicts.
2847 -title [wm title
$w] \
2849 -message "Too many branches selected.
2851 You have requested to merge $revcnt branches in an octopus merge. This exceeds Git's internal limit of 15 branches per merge.
2853 Please select fewer branches. To merge more than 15 branches, merge the branches in batches.
2858 set msg
"Merging $current_branch, [join $names {, }]"
2859 set ui_status_value
"$msg..."
2860 set cons
[new_console
"Merge" $msg]
2861 console_exec
$cons $cmd [list finish_merge
$revcnt]
2862 bind $w <Destroy
> {}
2866 proc finish_merge
{revcnt w ok
} {
2869 set msg
{Merge completed successfully.
}
2872 info_popup
"Octopus merge failed.
2874 Your merge of $revcnt branches has failed.
2876 There are file-level conflicts between the branches which must be resolved manually.
2878 The working directory will now be reset.
2880 You can attempt this merge again by merging only one branch at a time." $w
2882 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2883 fconfigure
$fd -blocking 0 -translation binary
2884 fileevent
$fd readable
[list reset_hard_wait
$fd]
2885 set ui_status_value
{Aborting... please
wait...
}
2889 set msg
{Merge failed. Conflict resolution is required.
}
2892 rescan
[list
set ui_status_value
$msg]
2895 proc do_local_merge
{} {
2896 global current_branch
2898 if {![can_merge
]} return
2902 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2905 -text "Merge Into $current_branch" \
2907 pack
$w.header
-side top
-fill x
2910 button
$w.buttons.visualize
-text Visualize \
2911 -command [list visualize_local_merge
$w]
2912 pack
$w.buttons.visualize
-side left
2913 button
$w.buttons.create
-text Merge \
2914 -command [list start_local_merge_action
$w]
2915 pack
$w.buttons.create
-side right
2916 button
$w.buttons.cancel
-text {Cancel
} \
2917 -command [list destroy
$w]
2918 pack
$w.buttons.cancel
-side right
-padx 5
2919 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2921 labelframe
$w.
source -text {Source Branches
}
2922 listbox
$w.
source.l \
2925 -selectmode extended \
2926 -yscrollcommand [list
$w.
source.sby
set]
2927 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2928 pack
$w.
source.sby
-side right
-fill y
2929 pack
$w.
source.l
-side left
-fill both
-expand 1
2930 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2932 set cmd
[list git for-each-ref
]
2933 lappend cmd
{--format=%(objectname
) %(*objectname
) %(refname
)}
2934 lappend cmd refs
/heads
2935 lappend cmd refs
/remotes
2936 lappend cmd refs
/tags
2937 set fr_fd
[open
"| $cmd" r
]
2938 fconfigure
$fr_fd -translation binary
2939 while {[gets
$fr_fd line
] > 0} {
2940 set line
[split $line { }]
2941 set sha1
([lindex
$line 0]) [lindex
$line 2]
2942 set sha1
([lindex
$line 1]) [lindex
$line 2]
2947 set fr_fd
[open
"| git rev-list --all --not HEAD"]
2948 while {[gets
$fr_fd line
] > 0} {
2949 if {[catch
{set ref
$sha1($line)}]} continue
2950 regsub ^refs
/(heads|remotes|tags
)/ $ref {} ref
2951 lappend to_show
$ref
2955 foreach ref
[lsort
-unique $to_show] {
2956 $w.
source.l insert end
$ref
2959 bind $w <Visibility
> "grab $w"
2960 bind $w <Key-Escape
> "unlock_index;destroy $w"
2961 bind $w <Destroy
> unlock_index
2962 wm title
$w "[appname] ([reponame]): Merge"
2966 proc do_reset_hard
{} {
2967 global HEAD commit_type file_states
2969 if {[string match amend
* $commit_type]} {
2970 info_popup
{Cannot abort
while amending.
2972 You must finish amending this commit.
2977 if {![lock_index abort
]} return
2979 if {[string match
*merge
* $commit_type]} {
2985 if {[ask_popup
"Abort $op?
2987 Aborting the current $op will cause *ALL* uncommitted changes to be lost.
2989 Continue with aborting the current $op?"] eq
{yes}} {
2990 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2991 fconfigure
$fd -blocking 0 -translation binary
2992 fileevent
$fd readable
[list reset_hard_wait
$fd]
2993 set ui_status_value
{Aborting... please
wait...
}
2999 proc reset_hard_wait
{fd
} {
3007 $ui_comm delete
0.0 end
3008 $ui_comm edit modified false
3010 catch
{file delete
[gitdir MERGE_HEAD
]}
3011 catch
{file delete
[gitdir rr-cache MERGE_RR
]}
3012 catch
{file delete
[gitdir SQUASH_MSG
]}
3013 catch
{file delete
[gitdir MERGE_MSG
]}
3014 catch
{file delete
[gitdir GITGUI_MSG
]}
3016 rescan
{set ui_status_value
{Abort completed. Ready.
}}
3020 ######################################################################
3024 set next_browser_id
0
3026 proc new_browser
{commit
} {
3027 global next_browser_id cursor_ptr M1B
3028 global browser_commit browser_status browser_stack browser_path browser_busy
3030 if {[winfo ismapped .
]} {
3031 set w .browser
[incr next_browser_id
]
3038 set w_list
$w.list.l
3039 set browser_commit
($w_list) $commit
3040 set browser_status
($w_list) {Starting...
}
3041 set browser_stack
($w_list) {}
3042 set browser_path
($w_list) $browser_commit($w_list):
3043 set browser_busy
($w_list) 1
3045 label
$w.path
-textvariable browser_path
($w_list) \
3051 pack
$w.path
-anchor w
-side top
-fill x
3054 text
$w_list -background white
-borderwidth 0 \
3055 -cursor $cursor_ptr \
3060 -xscrollcommand [list
$w.list.sbx
set] \
3061 -yscrollcommand [list
$w.list.sby
set]
3062 $w_list tag conf in_sel \
3063 -background [$w_list cget
-foreground] \
3064 -foreground [$w_list cget
-background]
3065 scrollbar
$w.list.sbx
-orient h
-command [list
$w_list xview
]
3066 scrollbar
$w.list.sby
-orient v
-command [list
$w_list yview
]
3067 pack
$w.list.sbx
-side bottom
-fill x
3068 pack
$w.list.sby
-side right
-fill y
3069 pack
$w_list -side left
-fill both
-expand 1
3070 pack
$w.list
-side top
-fill both
-expand 1
3072 label
$w.status
-textvariable browser_status
($w_list) \
3077 pack
$w.status
-anchor w
-side bottom
-fill x
3079 bind $w_list <Button-1
> "browser_click 0 $w_list @%x,%y;break"
3080 bind $w_list <Double-Button-1
> "browser_click 1 $w_list @%x,%y;break"
3081 bind $w_list <$M1B-Up> "browser_parent $w_list;break"
3082 bind $w_list <$M1B-Left> "browser_parent $w_list;break"
3083 bind $w_list <Up
> "browser_move -1 $w_list;break"
3084 bind $w_list <Down
> "browser_move 1 $w_list;break"
3085 bind $w_list <$M1B-Right> "browser_enter $w_list;break"
3086 bind $w_list <Return
> "browser_enter $w_list;break"
3087 bind $w_list <Prior
> "browser_page -1 $w_list;break"
3088 bind $w_list <Next
> "browser_page 1 $w_list;break"
3089 bind $w_list <Left
> break
3090 bind $w_list <Right
> break
3092 bind $tl <Visibility
> "focus $w"
3093 bind $tl <Destroy
> "
3094 array unset browser_buffer $w_list
3095 array unset browser_files $w_list
3096 array unset browser_status $w_list
3097 array unset browser_stack $w_list
3098 array unset browser_path $w_list
3099 array unset browser_commit $w_list
3100 array unset browser_busy $w_list
3102 wm title
$tl "[appname] ([reponame]): File Browser"
3103 ls_tree
$w_list $browser_commit($w_list) {}
3106 proc browser_move
{dir w
} {
3107 global browser_files browser_busy
3109 if {$browser_busy($w)} return
3110 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3112 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3113 $w tag remove in_sel
0.0 end
3114 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3119 proc browser_page
{dir w
} {
3120 global browser_files browser_busy
3122 if {$browser_busy($w)} return
3123 $w yview scroll
$dir pages
3125 [lindex
[$w yview
] 0]
3126 * [llength
$browser_files($w)]
3128 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3129 $w tag remove in_sel
0.0 end
3130 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3135 proc browser_parent
{w
} {
3136 global browser_files browser_status browser_path
3137 global browser_stack browser_busy
3139 if {$browser_busy($w)} return
3140 set info
[lindex
$browser_files($w) 0]
3141 if {[lindex
$info 0] eq
{parent
}} {
3142 set parent
[lindex
$browser_stack($w) end-1
]
3143 set browser_stack
($w) [lrange
$browser_stack($w) 0 end-2
]
3144 if {$browser_stack($w) eq
{}} {
3145 regsub
{:.
*$
} $browser_path($w) {:} browser_path
($w)
3147 regsub
{/[^
/]+$
} $browser_path($w) {} browser_path
($w)
3149 set browser_status
($w) "Loading $browser_path($w)..."
3150 ls_tree
$w [lindex
$parent 0] [lindex
$parent 1]
3154 proc browser_enter
{w
} {
3155 global browser_files browser_status browser_path
3156 global browser_commit browser_stack browser_busy
3158 if {$browser_busy($w)} return
3159 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3160 set info
[lindex
$browser_files($w) [expr {$lno - 1}]]
3162 switch
-- [lindex
$info 0] {
3167 set name
[lindex
$info 2]
3168 set escn
[escape_path
$name]
3169 set browser_status
($w) "Loading $escn..."
3170 append browser_path
($w) $escn
3171 ls_tree
$w [lindex
$info 1] $name
3174 set name
[lindex
$info 2]
3176 foreach n
$browser_stack($w) {
3177 append p
[lindex
$n 1]
3180 show_blame
$browser_commit($w) $p
3186 proc browser_click
{was_double_click w pos
} {
3187 global browser_files browser_busy
3189 if {$browser_busy($w)} return
3190 set lno
[lindex
[split [$w index
$pos] .
] 0]
3193 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3194 $w tag remove in_sel
0.0 end
3195 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3196 if {$was_double_click} {
3202 proc ls_tree
{w tree_id name
} {
3203 global browser_buffer browser_files browser_stack browser_busy
3205 set browser_buffer
($w) {}
3206 set browser_files
($w) {}
3207 set browser_busy
($w) 1
3209 $w conf
-state normal
3210 $w tag remove in_sel
0.0 end
3212 if {$browser_stack($w) ne
{}} {
3213 $w image create end \
3214 -align center
-padx 5 -pady 1 \
3217 $w insert end
{[Up To Parent
]}
3218 lappend browser_files
($w) parent
3220 lappend browser_stack
($w) [list
$tree_id $name]
3221 $w conf
-state disabled
3223 set cmd
[list git ls-tree
-z $tree_id]
3224 set fd
[open
"| $cmd" r
]
3225 fconfigure
$fd -blocking 0 -translation binary
-encoding binary
3226 fileevent
$fd readable
[list read_ls_tree
$fd $w]
3229 proc read_ls_tree
{fd w
} {
3230 global browser_buffer browser_files browser_status browser_busy
3232 if {![winfo exists
$w]} {
3237 append browser_buffer
($w) [read $fd]
3238 set pck
[split $browser_buffer($w) "\0"]
3239 set browser_buffer
($w) [lindex
$pck end
]
3241 set n
[llength
$browser_files($w)]
3242 $w conf
-state normal
3243 foreach p
[lrange
$pck 0 end-1
] {
3244 set info
[split $p "\t"]
3245 set path
[lindex
$info 1]
3246 set info
[split [lindex
$info 0] { }]
3247 set type [lindex
$info 1]
3248 set object
[lindex
$info 2]
3259 set image file_question
3263 if {$n > 0} {$w insert end
"\n"}
3264 $w image create end \
3265 -align center
-padx 5 -pady 1 \
3266 -name icon
[incr n
] \
3268 $w insert end
[escape_path
$path]
3269 lappend browser_files
($w) [list
$type $object $path]
3271 $w conf
-state disabled
3275 set browser_status
($w) Ready.
3276 set browser_busy
($w) 0
3277 array
unset browser_buffer
$w
3279 $w tag add in_sel
1.0 2.0
3285 proc show_blame
{commit path
} {
3286 global next_browser_id blame_status blame_data
3288 if {[winfo ismapped .
]} {
3289 set w .browser
[incr next_browser_id
]
3296 set blame_status
($w) {Loading current
file content...
}
3298 label
$w.path
-text "$commit:$path" \
3304 pack
$w.path
-side top
-fill x
3307 text
$w.out.loaded_t \
3308 -background white
-borderwidth 0 \
3314 $w.out.loaded_t tag conf annotated
-background grey
3316 text
$w.out.linenumber_t \
3317 -background white
-borderwidth 0 \
3323 $w.out.linenumber_t tag conf linenumber
-justify right
3325 text
$w.out.file_t \
3326 -background white
-borderwidth 0 \
3331 -xscrollcommand [list
$w.out.sbx
set] \
3334 scrollbar
$w.out.sbx
-orient h
-command [list
$w.out.file_t xview
]
3335 scrollbar
$w.out.sby
-orient v \
3336 -command [list scrollbar2many
[list \
3338 $w.out.linenumber_t \
3342 $w.out.linenumber_t \
3347 grid conf
$w.out.sbx
-column 2 -sticky we
3348 grid columnconfigure
$w.out
2 -weight 1
3349 grid rowconfigure
$w.out
0 -weight 1
3350 pack
$w.out
-fill both
-expand 1
3352 label
$w.status
-textvariable blame_status
($w) \
3357 pack
$w.status
-side bottom
-fill x
3361 -background white
-borderwidth 0 \
3366 -xscrollcommand [list
$w.cm.sbx
set] \
3367 -yscrollcommand [list
$w.cm.sby
set] \
3369 scrollbar
$w.cm.sbx
-orient h
-command [list
$w.cm.t xview
]
3370 scrollbar
$w.cm.sby
-orient v
-command [list
$w.cm.t yview
]
3371 pack
$w.cm.sby
-side right
-fill y
3372 pack
$w.cm.sbx
-side bottom
-fill x
3373 pack
$w.cm.t
-expand 1 -fill both
3374 pack
$w.cm
-side bottom
-fill x
3376 menu
$w.ctxm
-tearoff 0
3377 $w.ctxm add
command -label "Copy Commit" \
3378 -command "blame_copycommit $w \$cursorW @\$cursorX,\$cursorY"
3382 $w.out.linenumber_t \
3384 $i tag conf in_sel \
3385 -background [$i cget
-foreground] \
3386 -foreground [$i cget
-background]
3387 $i conf
-yscrollcommand \
3388 [list many2scrollbar
[list \
3390 $w.out.linenumber_t \
3393 bind $i <Button-1
> "
3396 $w.out.linenumber_t \\
3405 tk_popup $w.ctxm %X %Y
3409 bind $w.cm.t
<Button-1
> "focus $w.cm.t"
3410 bind $tl <Visibility
> "focus $tl"
3411 bind $tl <Destroy
> "
3412 array unset blame_status {$w}
3413 array unset blame_data $w,*
3415 wm title
$tl "[appname] ([reponame]): File Viewer"
3417 set blame_data
($w,commit_count
) 0
3418 set blame_data
($w,commit_list
) {}
3419 set blame_data
($w,total_lines
) 0
3420 set blame_data
($w,blame_lines
) 0
3421 set blame_data
($w,highlight_commit
) {}
3422 set blame_data
($w,highlight_line
) -1
3424 set cmd
[list git cat-file blob
"$commit:$path"]
3425 set fd
[open
"| $cmd" r
]
3426 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3427 fileevent
$fd readable
[list read_blame_catfile \
3428 $fd $w $commit $path \
3429 $w.cm.t
$w.out.loaded_t
$w.out.linenumber_t
$w.out.file_t
]
3432 proc read_blame_catfile
{fd w commit path w_cmit w_load w_line w_file
} {
3433 global blame_status blame_data
3435 if {![winfo exists
$w_file]} {
3440 set n
$blame_data($w,total_lines
)
3441 $w_load conf
-state normal
3442 $w_line conf
-state normal
3443 $w_file conf
-state normal
3444 while {[gets
$fd line
] >= 0} {
3445 regsub
"\r\$" $line {} line
3447 $w_load insert end
"\n"
3448 $w_line insert end
"$n\n" linenumber
3449 $w_file insert end
"$line\n"
3451 $w_load conf
-state disabled
3452 $w_line conf
-state disabled
3453 $w_file conf
-state disabled
3454 set blame_data
($w,total_lines
) $n
3458 blame_incremental_status
$w
3459 set cmd
[list git blame
-M -C --incremental]
3460 lappend cmd
$commit -- $path
3461 set fd
[open
"| $cmd" r
]
3462 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3463 fileevent
$fd readable
[list read_blame_incremental
$fd $w \
3464 $w_load $w_cmit $w_line $w_file]
3468 proc read_blame_incremental
{fd w w_load w_cmit w_line w_file
} {
3469 global blame_status blame_data
3471 if {![winfo exists
$w_file]} {
3476 while {[gets
$fd line
] >= 0} {
3477 if {[regexp
{^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$
} $line line \
3478 cmit original_line final_line line_count
]} {
3479 set blame_data
($w,commit
) $cmit
3480 set blame_data
($w,original_line
) $original_line
3481 set blame_data
($w,final_line
) $final_line
3482 set blame_data
($w,line_count
) $line_count
3484 if {[catch
{set g
$blame_data($w,$cmit,order
)}]} {
3485 $w_line tag conf g
$cmit
3486 $w_file tag conf g
$cmit
3487 $w_line tag raise in_sel
3488 $w_file tag raise in_sel
3489 $w_file tag raise sel
3490 set blame_data
($w,$cmit,order
) $blame_data($w,commit_count
)
3491 incr blame_data
($w,commit_count
)
3492 lappend blame_data
($w,commit_list
) $cmit
3494 } elseif
{[string match
{filename
*} $line]} {
3495 set file [string range
$line 9 end
]
3496 set n
$blame_data($w,line_count
)
3497 set lno
$blame_data($w,final_line
)
3498 set cmit
$blame_data($w,commit
)
3501 if {[catch
{set g g
$blame_data($w,line
$lno,commit
)}]} {
3502 $w_load tag add annotated
$lno.0 "$lno.0 lineend + 1c"
3504 $w_line tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3505 $w_file tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3508 set blame_data
($w,line
$lno,commit
) $cmit
3509 set blame_data
($w,line
$lno,file) $file
3510 $w_line tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3511 $w_file tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3513 if {$blame_data($w,highlight_line
) == -1} {
3514 if {[lindex
[$w_file yview
] 0] == 0} {
3516 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3518 } elseif
{$blame_data($w,highlight_line
) == $lno} {
3519 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3524 incr blame_data
($w,blame_lines
)
3527 set hc
$blame_data($w,highlight_commit
)
3529 && [expr {$blame_data($w,$hc,order
) + 1}]
3530 == $blame_data($w,$cmit,order
)} {
3531 blame_showcommit
$w $w_cmit $w_line $w_file \
3532 $blame_data($w,highlight_line
)
3534 } elseif
{[regexp
{^
([a-z-
]+) (.
*)$
} $line line header data
]} {
3535 set blame_data
($w,$blame_data($w,commit
),$header) $data
3541 set blame_status
($w) {Annotation complete.
}
3543 blame_incremental_status
$w
3547 proc blame_incremental_status
{w
} {
3548 global blame_status blame_data
3550 set have
$blame_data($w,blame_lines
)
3551 set total
$blame_data($w,total_lines
)
3553 if {$total} {set pdone
[expr {100 * $have / $total}]}
3555 set blame_status
($w) [format \
3556 "Loading annotations... %i of %i lines annotated (%2i%%)" \
3557 $have $total $pdone]
3560 proc blame_click
{w w_cmit w_line w_file cur_w pos
} {
3561 set lno
[lindex
[split [$cur_w index
$pos] .
] 0]
3562 if {$lno eq
{}} return
3564 $w_line tag remove in_sel
0.0 end
3565 $w_file tag remove in_sel
0.0 end
3566 $w_line tag add in_sel
$lno.0 "$lno.0 + 1 line"
3567 $w_file tag add in_sel
$lno.0 "$lno.0 + 1 line"
3569 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3578 proc blame_showcommit
{w w_cmit w_line w_file lno
} {
3579 global blame_colors blame_data repo_config
3581 set cmit
$blame_data($w,highlight_commit
)
3583 set idx
$blame_data($w,$cmit,order
)
3585 foreach c
$blame_colors {
3586 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3587 $w_line tag conf g
$h -background white
3588 $w_file tag conf g
$h -background white
3593 $w_cmit conf
-state normal
3594 $w_cmit delete
0.0 end
3595 if {[catch
{set cmit
$blame_data($w,line
$lno,commit
)}]} {
3597 $w_cmit insert end
"Loading annotation..."
3599 set idx
$blame_data($w,$cmit,order
)
3601 foreach c
$blame_colors {
3602 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3603 $w_line tag conf g
$h -background $c
3604 $w_file tag conf g
$h -background $c
3611 catch
{set author_name
$blame_data($w,$cmit,author
)}
3612 catch
{set author_email
$blame_data($w,$cmit,author-mail
)}
3613 catch
{set author_time
[clock format
$blame_data($w,$cmit,author-time
)]}
3615 set committer_name
{}
3616 set committer_email
{}
3617 set committer_time
{}
3618 catch
{set committer_name
$blame_data($w,$cmit,committer
)}
3619 catch
{set committer_email
$blame_data($w,$cmit,committer-mail
)}
3620 catch
{set committer_time
[clock format
$blame_data($w,$cmit,committer-time
)]}
3622 if {[catch
{set msg
$blame_data($w,$cmit,message
)}]} {
3625 set fd
[open
"| git cat-file commit $cmit" r
]
3626 fconfigure
$fd -encoding binary
-translation lf
3627 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
3630 while {[gets
$fd line
] > 0} {
3631 if {[string match
{encoding
*} $line]} {
3632 set enc
[string tolower
[string range
$line 9 end
]]
3635 set msg
[encoding convertfrom
$enc [read $fd]]
3636 set msg
[string trim
$msg]
3639 set author_name
[encoding convertfrom
$enc $author_name]
3640 set committer_name
[encoding convertfrom
$enc $committer_name]
3642 set blame_data
($w,$cmit,author
) $author_name
3643 set blame_data
($w,$cmit,committer
) $committer_name
3645 set blame_data
($w,$cmit,message
) $msg
3648 $w_cmit insert end
"commit $cmit\n"
3649 $w_cmit insert end
"Author: $author_name $author_email $author_time\n"
3650 $w_cmit insert end
"Committer: $committer_name $committer_email $committer_time\n"
3651 $w_cmit insert end
"Original File: [escape_path $blame_data($w,line$lno,file)]\n"
3652 $w_cmit insert end
"\n"
3653 $w_cmit insert end
$msg
3655 $w_cmit conf
-state disabled
3657 set blame_data
($w,highlight_line
) $lno
3658 set blame_data
($w,highlight_commit
) $cmit
3661 proc blame_copycommit
{w i pos
} {
3663 set lno
[lindex
[split [$i index
$pos] .
] 0]
3664 if {![catch
{set commit
$blame_data($w,line
$lno,commit
)}]} {
3673 ######################################################################
3678 #define mask_width 14
3679 #define mask_height 15
3680 static unsigned char mask_bits
[] = {
3681 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3682 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3683 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
3686 image create bitmap file_plain
-background white
-foreground black
-data {
3687 #define plain_width 14
3688 #define plain_height 15
3689 static unsigned char plain_bits
[] = {
3690 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3691 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
3692 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3693 } -maskdata $filemask
3695 image create bitmap file_mod
-background white
-foreground blue
-data {
3696 #define mod_width 14
3697 #define mod_height 15
3698 static unsigned char mod_bits
[] = {
3699 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3700 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3701 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3702 } -maskdata $filemask
3704 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
3705 #define file_fulltick_width 14
3706 #define file_fulltick_height 15
3707 static unsigned char file_fulltick_bits
[] = {
3708 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
3709 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
3710 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3711 } -maskdata $filemask
3713 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
3714 #define parttick_width 14
3715 #define parttick_height 15
3716 static unsigned char parttick_bits
[] = {
3717 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3718 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
3719 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3720 } -maskdata $filemask
3722 image create bitmap file_question
-background white
-foreground black
-data {
3723 #define file_question_width 14
3724 #define file_question_height 15
3725 static unsigned char file_question_bits
[] = {
3726 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
3727 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
3728 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3729 } -maskdata $filemask
3731 image create bitmap file_removed
-background white
-foreground red
-data {
3732 #define file_removed_width 14
3733 #define file_removed_height 15
3734 static unsigned char file_removed_bits
[] = {
3735 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3736 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
3737 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
3738 } -maskdata $filemask
3740 image create bitmap file_merge
-background white
-foreground blue
-data {
3741 #define file_merge_width 14
3742 #define file_merge_height 15
3743 static unsigned char file_merge_bits
[] = {
3744 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
3745 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3746 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3747 } -maskdata $filemask
3750 #define file_width 18
3751 #define file_height 18
3752 static unsigned char file_bits
[] = {
3753 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00,
3754 0x0c, 0x03, 0x00, 0x04, 0xfe, 0x00, 0x06, 0x80, 0x00, 0xff, 0x9f, 0x00,
3755 0x03, 0x98, 0x00, 0x02, 0x90, 0x00, 0x06, 0xb0, 0x00, 0x04, 0xa0, 0x00,
3756 0x0c, 0xe0, 0x00, 0x08, 0xc0, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
3757 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3759 image create bitmap file_dir
-background white
-foreground blue \
3760 -data $file_dir_data -maskdata $file_dir_data
3763 set file_uplevel_data
{
3765 #define up_height 15
3766 static unsigned char up_bits
[] = {
3767 0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f,
3768 0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
3769 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
3771 image create bitmap file_uplevel
-background white
-foreground red \
3772 -data $file_uplevel_data -maskdata $file_uplevel_data
3773 unset file_uplevel_data
3775 set ui_index .vpane.files.index.list
3776 set ui_workdir .vpane.files.workdir.list
3778 set all_icons
(_
$ui_index) file_plain
3779 set all_icons
(A
$ui_index) file_fulltick
3780 set all_icons
(M
$ui_index) file_fulltick
3781 set all_icons
(D
$ui_index) file_removed
3782 set all_icons
(U
$ui_index) file_merge
3784 set all_icons
(_
$ui_workdir) file_plain
3785 set all_icons
(M
$ui_workdir) file_mod
3786 set all_icons
(D
$ui_workdir) file_question
3787 set all_icons
(U
$ui_workdir) file_merge
3788 set all_icons
(O
$ui_workdir) file_plain
3790 set max_status_desc
0
3794 {_M
"Modified, not staged"}
3795 {M_
"Staged for commit"}
3796 {MM
"Portions staged for commit"}
3797 {MD
"Staged for commit, missing"}
3799 {_O
"Untracked, not staged"}
3800 {A_
"Staged for commit"}
3801 {AM
"Portions staged for commit"}
3802 {AD
"Staged for commit, missing"}
3805 {D_
"Staged for removal"}
3806 {DO
"Staged for removal, still present"}
3808 {U_
"Requires merge resolution"}
3809 {UU
"Requires merge resolution"}
3810 {UM
"Requires merge resolution"}
3811 {UD
"Requires merge resolution"}
3813 if {$max_status_desc < [string length
[lindex
$i 1]]} {
3814 set max_status_desc
[string length
[lindex
$i 1]]
3816 set all_descs
([lindex
$i 0]) [lindex
$i 1]
3820 ######################################################################
3824 proc bind_button3
{w cmd
} {
3825 bind $w <Any-Button-3
> $cmd
3827 bind $w <Control-Button-1
> $cmd
3831 proc scrollbar2many
{list mode args
} {
3832 foreach w
$list {eval $w $mode $args}
3835 proc many2scrollbar
{list mode sb top bottom
} {
3836 $sb set $top $bottom
3837 foreach w
$list {$w $mode moveto
$top}
3840 proc incr_font_size
{font
{amt
1}} {
3841 set sz
[font configure
$font -size]
3843 font configure
$font -size $sz
3844 font configure
${font}bold
-size $sz
3847 proc hook_failed_popup
{hook msg
} {
3852 label
$w.m.l1
-text "$hook hook failed:" \
3857 -background white
-borderwidth 1 \
3859 -width 80 -height 10 \
3861 -yscrollcommand [list
$w.m.sby
set]
3863 -text {You must correct the above errors before committing.
} \
3867 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3868 pack
$w.m.l1
-side top
-fill x
3869 pack
$w.m.l2
-side bottom
-fill x
3870 pack
$w.m.sby
-side right
-fill y
3871 pack
$w.m.t
-side left
-fill both
-expand 1
3872 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3874 $w.m.t insert
1.0 $msg
3875 $w.m.t conf
-state disabled
3877 button
$w.ok
-text OK \
3879 -command "destroy $w"
3880 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3882 bind $w <Visibility
> "grab $w; focus $w"
3883 bind $w <Key-Return
> "destroy $w"
3884 wm title
$w "[appname] ([reponame]): error"
3888 set next_console_id
0
3890 proc new_console
{short_title long_title
} {
3891 global next_console_id console_data
3892 set w .console
[incr next_console_id
]
3893 set console_data
($w) [list
$short_title $long_title]
3894 return [console_init
$w]
3897 proc console_init
{w
} {
3898 global console_cr console_data M1B
3900 set console_cr
($w) 1.0
3903 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
3908 -background white
-borderwidth 1 \
3910 -width 80 -height 10 \
3913 -yscrollcommand [list
$w.m.sby
set]
3914 label
$w.m.s
-text {Working... please
wait...
} \
3918 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3919 pack
$w.m.l1
-side top
-fill x
3920 pack
$w.m.s
-side bottom
-fill x
3921 pack
$w.m.sby
-side right
-fill y
3922 pack
$w.m.t
-side left
-fill both
-expand 1
3923 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3925 menu
$w.ctxm
-tearoff 0
3926 $w.ctxm add
command -label "Copy" \
3927 -command "tk_textCopy $w.m.t"
3928 $w.ctxm add
command -label "Select All" \
3929 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
3930 $w.ctxm add
command -label "Copy All" \
3932 $w.m.t tag add sel 0.0 end
3934 $w.m.t tag remove sel 0.0 end
3937 button
$w.ok
-text {Close
} \
3939 -command "destroy $w"
3940 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3942 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
3943 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
3944 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
3945 bind $w <Visibility
> "focus $w"
3946 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
3950 proc console_exec
{w cmd after
} {
3951 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
3952 # But most users need that so we have to relogin. :-(
3955 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
3958 # -- Tcl won't let us redirect both stdout and stderr to
3959 # the same pipe. So pass it through cat...
3961 set cmd
[concat |
$cmd |
& cat]
3963 set fd_f
[open
$cmd r
]
3964 fconfigure
$fd_f -blocking 0 -translation binary
3965 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
3968 proc console_read
{w fd after
} {
3973 if {![winfo exists
$w]} {console_init
$w}
3974 $w.m.t conf
-state normal
3976 set n
[string length
$buf]
3978 set cr
[string first
"\r" $buf $c]
3979 set lf
[string first
"\n" $buf $c]
3980 if {$cr < 0} {set cr
[expr {$n + 1}]}
3981 if {$lf < 0} {set lf
[expr {$n + 1}]}
3984 $w.m.t insert end
[string range
$buf $c $lf]
3985 set console_cr
($w) [$w.m.t index
{end
-1c}]
3989 $w.m.t delete
$console_cr($w) end
3990 $w.m.t insert end
"\n"
3991 $w.m.t insert end
[string range
$buf $c $cr]
3996 $w.m.t conf
-state disabled
4000 fconfigure
$fd -blocking 1
4002 if {[catch
{close
$fd}]} {
4007 uplevel
#0 $after $w $ok
4010 fconfigure
$fd -blocking 0
4013 proc console_chain
{cmdlist w
{ok
1}} {
4015 if {[llength
$cmdlist] == 0} {
4020 set cmd
[lindex
$cmdlist 0]
4021 set cmdlist
[lrange
$cmdlist 1 end
]
4023 if {[lindex
$cmd 0] eq
{console_exec
}} {
4026 [list console_chain
$cmdlist]
4028 uplevel
#0 $cmd $cmdlist $w $ok
4035 proc console_done
{args
} {
4036 global console_cr console_data
4038 switch
-- [llength
$args] {
4040 set w
[lindex
$args 0]
4041 set ok
[lindex
$args 1]
4044 set w
[lindex
$args 1]
4045 set ok
[lindex
$args 2]
4048 error
"wrong number of args: console_done ?ignored? w ok"
4053 if {[winfo exists
$w]} {
4054 $w.m.s conf
-background green
-text {Success
}
4055 $w.ok conf
-state normal
4059 if {![winfo exists
$w]} {
4062 $w.m.s conf
-background red
-text {Error
: Command Failed
}
4063 $w.ok conf
-state normal
4067 array
unset console_cr
$w
4068 array
unset console_data
$w
4071 ######################################################################
4075 set starting_gitk_msg
{Starting gitk... please
wait...
}
4077 proc do_gitk
{revs
} {
4078 global env ui_status_value starting_gitk_msg
4080 # -- Always start gitk through whatever we were loaded with. This
4081 # lets us bypass using shell process on Windows systems.
4083 set cmd
[list
[info nameofexecutable
]]
4084 lappend cmd
[gitexec gitk
]
4090 if {[catch
{eval exec $cmd &} err
]} {
4091 error_popup
"Failed to start gitk:\n\n$err"
4093 set ui_status_value
$starting_gitk_msg
4095 if {$ui_status_value eq
$starting_gitk_msg} {
4096 set ui_status_value
{Ready.
}
4103 set fd
[open
"| git count-objects -v" r
]
4104 while {[gets
$fd line
] > 0} {
4105 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
4106 set stats
($name) $value
4112 foreach p
[glob
-directory [gitdir objects pack
] \
4115 incr packed_sz
[file size
$p]
4117 if {$packed_sz > 0} {
4118 set stats
(size-pack
) [expr {$packed_sz / 1024}]
4123 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4125 label
$w.header
-text {Database Statistics
}
4126 pack
$w.header
-side top
-fill x
4128 frame
$w.buttons
-border 1
4129 button
$w.buttons.close
-text Close \
4131 -command [list destroy
$w]
4132 button
$w.buttons.gc
-text {Compress Database
} \
4134 -command "destroy $w;do_gc"
4135 pack
$w.buttons.close
-side right
4136 pack
$w.buttons.gc
-side left
4137 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4139 frame
$w.stat
-borderwidth 1 -relief solid
4141 {count
{Number of loose objects
}}
4142 {size
{Disk space used by loose objects
} { KiB
}}
4143 {in-pack
{Number of packed objects
}}
4144 {packs
{Number of packs
}}
4145 {size-pack
{Disk space used by packed objects
} { KiB
}}
4146 {prune-packable
{Packed objects waiting
for pruning
}}
4147 {garbage
{Garbage files
}}
4149 set name
[lindex
$s 0]
4150 set label
[lindex
$s 1]
4151 if {[catch
{set value
$stats($name)}]} continue
4152 if {[llength
$s] > 2} {
4153 set value
"$value[lindex $s 2]"
4156 label
$w.stat.l_
$name -text "$label:" -anchor w
4157 label
$w.stat.v_
$name -text $value -anchor w
4158 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
4160 pack
$w.stat
-pady 10 -padx 10
4162 bind $w <Visibility
> "grab $w; focus $w.buttons.close"
4163 bind $w <Key-Escape
> [list destroy
$w]
4164 bind $w <Key-Return
> [list destroy
$w]
4165 wm title
$w "[appname] ([reponame]): Database Statistics"
4170 set w
[new_console
{gc
} {Compressing the object database
}]
4172 {console_exec
{git pack-refs
--prune}}
4173 {console_exec
{git reflog expire
--all}}
4174 {console_exec
{git repack
-a -d -l}}
4175 {console_exec
{git rerere gc
}}
4179 proc do_fsck_objects
{} {
4180 set w
[new_console
{fsck-objects
} \
4181 {Verifying the object database with fsck-objects
}]
4182 set cmd
[list git fsck-objects
]
4185 lappend cmd
--strict
4186 console_exec
$w $cmd console_done
4192 global ui_comm is_quitting repo_config commit_type
4194 if {$is_quitting} return
4197 if {[winfo exists
$ui_comm]} {
4198 # -- Stash our current commit buffer.
4200 set save
[gitdir GITGUI_MSG
]
4201 set msg
[string trim
[$ui_comm get
0.0 end
]]
4202 regsub
-all -line {[ \r\t]+$
} $msg {} msg
4203 if {(![string match amend
* $commit_type]
4204 ||
[$ui_comm edit modified
])
4207 set fd
[open
$save w
]
4208 puts
-nonewline $fd $msg
4212 catch
{file delete
$save}
4215 # -- Stash our current window geometry into this repository.
4217 set cfg_geometry
[list
]
4218 lappend cfg_geometry
[wm geometry .
]
4219 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
4220 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
4221 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
4224 if {$cfg_geometry ne
$rc_geometry} {
4225 catch
{git config gui.geometry
$cfg_geometry}
4233 rescan
{set ui_status_value
{Ready.
}}
4236 proc unstage_helper
{txt paths
} {
4237 global file_states current_diff_path
4239 if {![lock_index begin-update
]} return
4243 foreach path
$paths {
4244 switch
-glob -- [lindex
$file_states($path) 0] {
4248 lappend pathList
$path
4249 if {$path eq
$current_diff_path} {
4250 set after
{reshow_diff
;}
4255 if {$pathList eq
{}} {
4261 [concat
$after {set ui_status_value
{Ready.
}}]
4265 proc do_unstage_selection
{} {
4266 global current_diff_path selected_paths
4268 if {[array size selected_paths
] > 0} {
4270 {Unstaging selected files from commit
} \
4271 [array names selected_paths
]
4272 } elseif
{$current_diff_path ne
{}} {
4274 "Unstaging [short_path $current_diff_path] from commit" \
4275 [list
$current_diff_path]
4279 proc add_helper
{txt paths
} {
4280 global file_states current_diff_path
4282 if {![lock_index begin-update
]} return
4286 foreach path
$paths {
4287 switch
-glob -- [lindex
$file_states($path) 0] {
4292 lappend pathList
$path
4293 if {$path eq
$current_diff_path} {
4294 set after
{reshow_diff
;}
4299 if {$pathList eq
{}} {
4305 [concat
$after {set ui_status_value
{Ready to commit.
}}]
4309 proc do_add_selection
{} {
4310 global current_diff_path selected_paths
4312 if {[array size selected_paths
] > 0} {
4314 {Adding selected files
} \
4315 [array names selected_paths
]
4316 } elseif
{$current_diff_path ne
{}} {
4318 "Adding [short_path $current_diff_path]" \
4319 [list
$current_diff_path]
4323 proc do_add_all
{} {
4327 foreach path
[array names file_states
] {
4328 switch
-glob -- [lindex
$file_states($path) 0] {
4331 ?D
{lappend paths
$path}
4334 add_helper
{Adding all changed files
} $paths
4337 proc revert_helper
{txt paths
} {
4338 global file_states current_diff_path
4340 if {![lock_index begin-update
]} return
4344 foreach path
$paths {
4345 switch
-glob -- [lindex
$file_states($path) 0] {
4349 lappend pathList
$path
4350 if {$path eq
$current_diff_path} {
4351 set after
{reshow_diff
;}
4357 set n
[llength
$pathList]
4361 } elseif
{$n == 1} {
4362 set s
"[short_path [lindex $pathList]]"
4364 set s
"these $n files"
4367 set reply
[tk_dialog \
4369 "[appname] ([reponame])" \
4370 "Revert changes in $s?
4372 Any unadded changes will be permanently lost by the revert." \
4382 [concat
$after {set ui_status_value
{Ready.
}}]
4388 proc do_revert_selection
{} {
4389 global current_diff_path selected_paths
4391 if {[array size selected_paths
] > 0} {
4393 {Reverting selected files
} \
4394 [array names selected_paths
]
4395 } elseif
{$current_diff_path ne
{}} {
4397 "Reverting [short_path $current_diff_path]" \
4398 [list
$current_diff_path]
4402 proc do_signoff
{} {
4405 set me
[committer_ident
]
4406 if {$me eq
{}} return
4408 set sob
"Signed-off-by: $me"
4409 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
4410 if {$last ne
$sob} {
4411 $ui_comm edit separator
4413 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
4414 $ui_comm insert end
"\n"
4416 $ui_comm insert end
"\n$sob"
4417 $ui_comm edit separator
4422 proc do_select_commit_type
{} {
4423 global commit_type selected_commit_type
4425 if {$selected_commit_type eq
{new
}
4426 && [string match amend
* $commit_type]} {
4428 } elseif
{$selected_commit_type eq
{amend
}
4429 && ![string match amend
* $commit_type]} {
4432 # The amend request was rejected...
4434 if {![string match amend
* $commit_type]} {
4435 set selected_commit_type new
4445 global appvers copyright
4446 global tcl_patchLevel tk_patchLevel
4450 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4452 label
$w.header
-text "About [appname]" \
4454 pack
$w.header
-side top
-fill x
4457 button
$w.buttons.close
-text {Close
} \
4459 -command [list destroy
$w]
4460 pack
$w.buttons.close
-side right
4461 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4464 -text "git-gui - a graphical user interface for Git.
4471 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
4474 append v
"git-gui version $appvers\n"
4475 append v
"[git version]\n"
4477 if {$tcl_patchLevel eq
$tk_patchLevel} {
4478 append v
"Tcl/Tk version $tcl_patchLevel"
4480 append v
"Tcl version $tcl_patchLevel"
4481 append v
", Tk version $tk_patchLevel"
4491 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
4493 menu
$w.ctxm
-tearoff 0
4494 $w.ctxm add
command \
4498 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
4501 bind $w <Visibility
> "grab $w; focus $w.buttons.close"
4502 bind $w <Key-Escape
> "destroy $w"
4503 bind $w <Key-Return
> "destroy $w"
4504 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
4505 wm title
$w "About [appname]"
4509 proc do_options
{} {
4510 global repo_config global_config font_descs
4511 global repo_config_new global_config_new
4513 array
unset repo_config_new
4514 array
unset global_config_new
4515 foreach name
[array names repo_config
] {
4516 set repo_config_new
($name) $repo_config($name)
4519 foreach name
[array names repo_config
] {
4521 gui.diffcontext
{continue}
4523 set repo_config_new
($name) $repo_config($name)
4525 foreach name
[array names global_config
] {
4526 set global_config_new
($name) $global_config($name)
4529 set w .options_editor
4531 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4533 label
$w.header
-text "Options" \
4535 pack
$w.header
-side top
-fill x
4538 button
$w.buttons.restore
-text {Restore Defaults
} \
4540 -command do_restore_defaults
4541 pack
$w.buttons.restore
-side left
4542 button
$w.buttons.save
-text Save \
4544 -command [list do_save_config
$w]
4545 pack
$w.buttons.save
-side right
4546 button
$w.buttons.cancel
-text {Cancel
} \
4548 -command [list destroy
$w]
4549 pack
$w.buttons.cancel
-side right
-padx 5
4550 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4552 labelframe
$w.repo
-text "[reponame] Repository"
4553 labelframe
$w.global
-text {Global
(All Repositories
)}
4554 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
4555 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
4559 {t user.name
{User Name
}}
4560 {t user.email
{Email Address
}}
4562 {b merge.summary
{Summarize Merge Commits
}}
4563 {i-1.
.5 merge.verbosity
{Merge Verbosity
}}
4565 {b gui.trustmtime
{Trust File Modification Timestamps
}}
4566 {i-1.
.99 gui.diffcontext
{Number of Diff Context Lines
}}
4567 {t gui.newbranchtemplate
{New Branch Name Template
}}
4569 set type [lindex
$option 0]
4570 set name
[lindex
$option 1]
4571 set text
[lindex
$option 2]
4573 foreach f
{repo global
} {
4574 switch
-glob -- $type {
4576 checkbutton
$w.
$f.
$optid -text $text \
4577 -variable ${f}_config_new
($name) \
4580 pack
$w.
$f.
$optid -side top
-anchor w
4583 regexp
-- {-(\d
+)\.\.
(\d
+)$
} $type _junk min max
4585 label
$w.
$f.
$optid.l
-text "$text:"
4586 pack
$w.
$f.
$optid.l
-side left
-anchor w
-fill x
4587 spinbox
$w.
$f.
$optid.v \
4588 -textvariable ${f}_config_new
($name) \
4592 -width [expr {1 + [string length
$max]}]
4593 bind $w.
$f.
$optid.v
<FocusIn
> {%W selection range
0 end
}
4594 pack
$w.
$f.
$optid.v
-side right
-anchor e
-padx 5
4595 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4599 label
$w.
$f.
$optid.l
-text "$text:"
4600 entry
$w.
$f.
$optid.v \
4604 -textvariable ${f}_config_new
($name)
4605 pack
$w.
$f.
$optid.l
-side left
-anchor w
4606 pack
$w.
$f.
$optid.v
-side left
-anchor w \
4609 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4615 set all_fonts
[lsort
[font families
]]
4616 foreach option
$font_descs {
4617 set name
[lindex
$option 0]
4618 set font
[lindex
$option 1]
4619 set text
[lindex
$option 2]
4621 set global_config_new
(gui.
$font^^family
) \
4622 [font configure
$font -family]
4623 set global_config_new
(gui.
$font^^size
) \
4624 [font configure
$font -size]
4626 frame
$w.global.
$name
4627 label
$w.global.
$name.l
-text "$text:"
4628 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
4629 eval tk_optionMenu
$w.global.
$name.family \
4630 global_config_new
(gui.
$font^^family
) \
4632 spinbox
$w.global.
$name.size \
4633 -textvariable global_config_new
(gui.
$font^^size
) \
4634 -from 2 -to 80 -increment 1 \
4636 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
4637 pack
$w.global.
$name.size
-side right
-anchor e
4638 pack
$w.global.
$name.family
-side right
-anchor e
4639 pack
$w.global.
$name -side top
-anchor w
-fill x
4642 bind $w <Visibility
> "grab $w; focus $w.buttons.save"
4643 bind $w <Key-Escape
> "destroy $w"
4644 bind $w <Key-Return
> [list do_save_config
$w]
4645 wm title
$w "[appname] ([reponame]): Options"
4649 proc do_restore_defaults
{} {
4650 global font_descs default_config repo_config
4651 global repo_config_new global_config_new
4653 foreach name
[array names default_config
] {
4654 set repo_config_new
($name) $default_config($name)
4655 set global_config_new
($name) $default_config($name)
4658 foreach option
$font_descs {
4659 set name
[lindex
$option 0]
4660 set repo_config
(gui.
$name) $default_config(gui.
$name)
4664 foreach option
$font_descs {
4665 set name
[lindex
$option 0]
4666 set font
[lindex
$option 1]
4667 set global_config_new
(gui.
$font^^family
) \
4668 [font configure
$font -family]
4669 set global_config_new
(gui.
$font^^size
) \
4670 [font configure
$font -size]
4674 proc do_save_config
{w
} {
4675 if {[catch
{save_config
} err
]} {
4676 error_popup
"Failed to completely save options:\n\n$err"
4682 proc do_windows_shortcut
{} {
4685 set fn
[tk_getSaveFile \
4687 -title "[appname] ([reponame]): Create Desktop Icon" \
4688 -initialfile "Git [reponame].bat"]
4692 puts
$fd "@ECHO Entering [reponame]"
4693 puts
$fd "@ECHO Starting git-gui... please wait..."
4694 puts
$fd "@SET PATH=[file normalize [gitexec]];%PATH%"
4695 puts
$fd "@SET GIT_DIR=[file normalize [gitdir]]"
4696 puts
-nonewline $fd "@\"[info nameofexecutable]\""
4697 puts
$fd " \"[file normalize $argv0]\""
4700 error_popup
"Cannot write script:\n\n$err"
4705 proc do_cygwin_shortcut
{} {
4709 set desktop
[exec cygpath \
4717 set fn
[tk_getSaveFile \
4719 -title "[appname] ([reponame]): Create Desktop Icon" \
4720 -initialdir $desktop \
4721 -initialfile "Git [reponame].bat"]
4725 set sh
[exec cygpath \
4729 set me
[exec cygpath \
4733 set gd
[exec cygpath \
4737 set gw
[exec cygpath \
4740 [file dirname [gitdir
]]]
4741 regsub
-all ' $me "'\\''" me
4742 regsub -all ' $gd "'\\''" gd
4743 puts $fd "@ECHO Entering $gw"
4744 puts $fd "@ECHO Starting git-gui... please wait..."
4745 puts -nonewline $fd "@\"$sh\" --login -c \""
4746 puts -nonewline $fd "GIT_DIR='$gd'"
4747 puts -nonewline $fd " '$me'"
4751 error_popup "Cannot write script:\n\n$err"
4756 proc do_macosx_app {} {
4759 set fn [tk_getSaveFile \
4761 -title "[appname] ([reponame]): Create Desktop Icon" \
4762 -initialdir [file join $env(HOME) Desktop] \
4763 -initialfile "Git [reponame].app"]
4766 set Contents [file join $fn Contents]
4767 set MacOS [file join $Contents MacOS]
4768 set exe [file join $MacOS git-gui]
4772 set fd [open [file join $Contents Info.plist] w]
4773 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
4774 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4775 <plist version="1.0">
4777 <key>CFBundleDevelopmentRegion</key>
4778 <string>English</string>
4779 <key>CFBundleExecutable</key>
4780 <string>git-gui</string>
4781 <key>CFBundleIdentifier</key>
4782 <string>org.spearce.git-gui</string>
4783 <key>CFBundleInfoDictionaryVersion</key>
4784 <string>6.0</string>
4785 <key>CFBundlePackageType</key>
4786 <string>APPL</string>
4787 <key>CFBundleSignature</key>
4788 <string>????</string>
4789 <key>CFBundleVersion</key>
4790 <string>1.0</string>
4791 <key>NSPrincipalClass</key>
4792 <string>NSApplication</string>
4797 set fd [open $exe w]
4798 set gd [file normalize [gitdir]]
4799 set ep [file normalize [gitexec]]
4800 regsub -all ' $gd "'\\''" gd
4801 regsub
-all ' $ep "'\\''" ep
4802 puts $fd "#!/bin/sh"
4803 foreach name
[array names env
] {
4804 if {[string match GIT_
* $name]} {
4805 regsub
-all ' $env($name) "'\\''" v
4806 puts $fd "export $name='$v'"
4809 puts $fd "export PATH
='$ep':\
$PATH"
4810 puts $fd "export GIT_DIR
='$gd'"
4811 puts $fd "exec [file normalize
$argv0]"
4814 file attributes $exe -permissions u+x,g+x,o+x
4816 error_popup "Cannot
write icon
:\n\n$err"
4821 proc toggle_or_diff {w x y} {
4822 global file_states file_lists current_diff_path ui_index ui_workdir
4823 global last_clicked selected_paths
4825 set pos [split [$w index @$x,$y] .]
4826 set lno [lindex $pos 0]
4827 set col [lindex $pos 1]
4828 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4834 set last_clicked [list $w $lno]
4835 array unset selected_paths
4836 $ui_index tag remove in_sel 0.0 end
4837 $ui_workdir tag remove in_sel 0.0 end
4840 if {$current_diff_path eq $path} {
4841 set after {reshow_diff;}
4845 if {$w eq $ui_index} {
4847 "Unstaging
[short_path
$path] from commit
" \
4849 [concat $after {set ui_status_value {Ready.}}]
4850 } elseif {$w eq $ui_workdir} {
4852 "Adding
[short_path
$path]" \
4854 [concat $after {set ui_status_value {Ready.}}]
4857 show_diff $path $w $lno
4861 proc add_one_to_selection {w x y} {
4862 global file_lists last_clicked selected_paths
4864 set lno [lindex [split [$w index @$x,$y] .] 0]
4865 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4871 if {$last_clicked ne {}
4872 && [lindex $last_clicked 0] ne $w} {
4873 array unset selected_paths
4874 [lindex $last_clicked 0] tag remove in_sel 0.0 end
4877 set last_clicked [list $w $lno]
4878 if {[catch {set in_sel $selected_paths($path)}]} {
4882 unset selected_paths($path)
4883 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
4885 set selected_paths($path) 1
4886 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
4890 proc add_range_to_selection {w x y} {
4891 global file_lists last_clicked selected_paths
4893 if {[lindex $last_clicked 0] ne $w} {
4894 toggle_or_diff $w $x $y
4898 set lno [lindex [split [$w index @$x,$y] .] 0]
4899 set lc [lindex $last_clicked 1]
4908 foreach path [lrange $file_lists($w) \
4909 [expr {$begin - 1}] \
4910 [expr {$end - 1}]] {
4911 set selected_paths($path) 1
4913 $w tag add in_sel $begin.0 [expr {$end + 1}].0
4916 ######################################################################
4920 set cursor_ptr arrow
4921 font create font_diff -family Courier -size 10
4925 eval font configure font_ui [font actual [.dummy cget -font]]
4929 font create font_uibold
4930 font create font_diffbold
4932 foreach class {Button Checkbutton Entry Label
4933 Labelframe Listbox Menu Message
4935 option add *$class.font font_ui
4942 } elseif {[is_MacOSX]} {
4950 proc apply_config {} {
4951 global repo_config font_descs
4953 foreach option $font_descs {
4954 set name [lindex $option 0]
4955 set font [lindex $option 1]
4957 foreach {cn cv} $repo_config(gui.$name) {
4958 font configure $font $cn $cv
4961 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
4963 foreach {cn cv} [font configure $font] {
4964 font configure ${font}bold $cn $cv
4966 font configure ${font}bold -weight bold
4970 set default_config(merge.summary) false
4971 set default_config(merge.verbosity) 2
4972 set default_config(user.name) {}
4973 set default_config(user.email) {}
4975 set default_config(gui.trustmtime) false
4976 set default_config(gui.diffcontext) 5
4977 set default_config(gui.newbranchtemplate) {}
4978 set default_config(gui.fontui) [font configure font_ui]
4979 set default_config(gui.fontdiff) [font configure font_diff]
4981 {fontui font_ui {Main Font}}
4982 {fontdiff font_diff {Diff/Console Font}}
4987 ######################################################################
4989 ## feature option selection
4991 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
4996 if {$subcommand eq {gui.sh}} {
4999 if {$subcommand eq {gui} && [llength $argv] > 0} {
5000 set subcommand [lindex $argv 0]
5001 set argv [lrange $argv 1 end]
5004 enable_option multicommit
5005 enable_option branch
5006 enable_option transport
5008 switch -- $subcommand {
5011 disable_option multicommit
5012 disable_option branch
5013 disable_option transport
5016 enable_option singlecommit
5018 disable_option multicommit
5019 disable_option branch
5020 disable_option transport
5024 ######################################################################
5032 menu .mbar -tearoff 0
5033 .mbar add cascade -label Repository -menu .mbar.repository
5034 .mbar add cascade -label Edit -menu .mbar.edit
5035 if {[is_enabled branch]} {
5036 .mbar add cascade -label Branch -menu .mbar.branch
5038 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
5039 .mbar add cascade -label Commit -menu .mbar.commit
5041 if {[is_enabled transport]} {
5042 .mbar add cascade -label Merge -menu .mbar.merge
5043 .mbar add cascade -label Fetch -menu .mbar.fetch
5044 .mbar add cascade -label Push -menu .mbar.push
5046 . configure -menu .mbar
5048 # -- Repository Menu
5050 menu .mbar.repository
5052 .mbar.repository add command \
5053 -label {Browse Current Branch} \
5054 -command {new_browser $current_branch}
5055 trace add variable current_branch write ".mbar.repository entryconf
[.mbar.repository index last
] -label \"Browse \
$current_branch\" ;#"
5056 .mbar.repository add separator
5058 .mbar.repository add
command \
5059 -label {Visualize Current Branch
} \
5060 -command {do_gitk
$current_branch}
5061 trace add variable current_branch
write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#"
5062 .mbar.repository add
command \
5063 -label {Visualize All Branches
} \
5064 -command {do_gitk
--all}
5065 .mbar.repository add separator
5067 if {[is_enabled multicommit
]} {
5068 .mbar.repository add
command -label {Database Statistics
} \
5071 .mbar.repository add
command -label {Compress Database
} \
5074 .mbar.repository add
command -label {Verify Database
} \
5075 -command do_fsck_objects
5077 .mbar.repository add separator
5080 .mbar.repository add
command \
5081 -label {Create Desktop Icon
} \
5082 -command do_cygwin_shortcut
5083 } elseif
{[is_Windows
]} {
5084 .mbar.repository add
command \
5085 -label {Create Desktop Icon
} \
5086 -command do_windows_shortcut
5087 } elseif
{[is_MacOSX
]} {
5088 .mbar.repository add
command \
5089 -label {Create Desktop Icon
} \
5090 -command do_macosx_app
5094 .mbar.repository add
command -label Quit \
5101 .mbar.edit add
command -label Undo \
5102 -command {catch
{[focus
] edit undo
}} \
5104 .mbar.edit add
command -label Redo \
5105 -command {catch
{[focus
] edit redo
}} \
5107 .mbar.edit add separator
5108 .mbar.edit add
command -label Cut \
5109 -command {catch
{tk_textCut
[focus
]}} \
5111 .mbar.edit add
command -label Copy \
5112 -command {catch
{tk_textCopy
[focus
]}} \
5114 .mbar.edit add
command -label Paste \
5115 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
5117 .mbar.edit add
command -label Delete \
5118 -command {catch
{[focus
] delete sel.first sel.last
}} \
5120 .mbar.edit add separator
5121 .mbar.edit add
command -label {Select All
} \
5122 -command {catch
{[focus
] tag add sel
0.0 end
}} \
5127 if {[is_enabled branch
]} {
5130 .mbar.branch add
command -label {Create...
} \
5131 -command do_create_branch \
5133 lappend disable_on_lock
[list .mbar.branch entryconf \
5134 [.mbar.branch index last
] -state]
5136 .mbar.branch add
command -label {Delete...
} \
5137 -command do_delete_branch
5138 lappend disable_on_lock
[list .mbar.branch entryconf \
5139 [.mbar.branch index last
] -state]
5141 .mbar.branch add
command -label {Reset...
} \
5142 -command do_reset_hard
5143 lappend disable_on_lock
[list .mbar.branch entryconf \
5144 [.mbar.branch index last
] -state]
5149 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
5152 .mbar.commit add radiobutton \
5153 -label {New Commit
} \
5154 -command do_select_commit_type \
5155 -variable selected_commit_type \
5157 lappend disable_on_lock \
5158 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5160 .mbar.commit add radiobutton \
5161 -label {Amend Last Commit
} \
5162 -command do_select_commit_type \
5163 -variable selected_commit_type \
5165 lappend disable_on_lock \
5166 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5168 .mbar.commit add separator
5170 .mbar.commit add
command -label Rescan \
5171 -command do_rescan \
5173 lappend disable_on_lock \
5174 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5176 .mbar.commit add
command -label {Add To Commit
} \
5177 -command do_add_selection
5178 lappend disable_on_lock \
5179 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5181 .mbar.commit add
command -label {Add Existing To Commit
} \
5182 -command do_add_all \
5184 lappend disable_on_lock \
5185 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5187 .mbar.commit add
command -label {Unstage From Commit
} \
5188 -command do_unstage_selection
5189 lappend disable_on_lock \
5190 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5192 .mbar.commit add
command -label {Revert Changes
} \
5193 -command do_revert_selection
5194 lappend disable_on_lock \
5195 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5197 .mbar.commit add separator
5199 .mbar.commit add
command -label {Sign Off
} \
5200 -command do_signoff \
5203 .mbar.commit add
command -label Commit \
5204 -command do_commit \
5205 -accelerator $M1T-Return
5206 lappend disable_on_lock \
5207 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5212 if {[is_enabled branch
]} {
5214 .mbar.merge add
command -label {Local Merge...
} \
5215 -command do_local_merge
5216 lappend disable_on_lock \
5217 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5218 .mbar.merge add
command -label {Abort Merge...
} \
5219 -command do_reset_hard
5220 lappend disable_on_lock \
5221 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5227 if {[is_enabled transport
]} {
5231 .mbar.push add
command -label {Push...
} \
5232 -command do_push_anywhere
5236 # -- Apple Menu (Mac OS X only)
5238 .mbar add cascade
-label Apple
-menu .mbar.apple
5241 .mbar.apple add
command -label "About [appname]" \
5243 .mbar.apple add
command -label "Options..." \
5248 .mbar.edit add separator
5249 .mbar.edit add
command -label {Options...
} \
5254 if {[file exists
/usr
/local
/miga
/lib
/gui-miga
]
5255 && [file exists .pvcsrc
]} {
5257 global ui_status_value
5258 if {![lock_index update
]} return
5259 set cmd
[list sh
--login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
5260 set miga_fd
[open
"|$cmd" r
]
5261 fconfigure
$miga_fd -blocking 0
5262 fileevent
$miga_fd readable
[list miga_done
$miga_fd]
5263 set ui_status_value
{Running miga...
}
5265 proc miga_done
{fd
} {
5270 rescan
[list
set ui_status_value
{Ready.
}]
5273 .mbar add cascade
-label Tools
-menu .mbar.tools
5275 .mbar.tools add
command -label "Migrate" \
5277 lappend disable_on_lock \
5278 [list .mbar.tools entryconf
[.mbar.tools index last
] -state]
5284 .mbar add cascade
-label Help
-menu .mbar.
help
5288 .mbar.
help add
command -label "About [appname]" \
5293 catch
{set browser
$repo_config(instaweb.browser
)}
5294 set doc_path
[file dirname [gitexec
]]
5295 set doc_path
[file join $doc_path Documentation index.html
]
5298 set doc_path
[exec cygpath
--mixed $doc_path]
5301 if {$browser eq
{}} {
5304 } elseif
{[is_Cygwin
]} {
5305 set program_files
[file dirname [exec cygpath
--windir]]
5306 set program_files
[file join $program_files {Program Files
}]
5307 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
5308 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
5309 if {[file exists
$firefox]} {
5310 set browser
$firefox
5311 } elseif
{[file exists
$ie]} {
5314 unset program_files firefox ie
5318 if {[file isfile
$doc_path]} {
5319 set doc_url
"file:$doc_path"
5321 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
5324 if {$browser ne
{}} {
5325 .mbar.
help add
command -label {Online Documentation
} \
5326 -command [list
exec $browser $doc_url &]
5328 unset browser doc_path doc_url
5330 # -- Standard bindings
5332 bind .
<Destroy
> do_quit
5333 bind all
<$M1B-Key-q> do_quit
5334 bind all
<$M1B-Key-Q> do_quit
5335 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
5336 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
5338 # -- Not a normal commit type invocation? Do that instead!
5340 switch
-- $subcommand {
5342 if {[llength
$argv] != 1} {
5343 puts stderr
"usage: $argv0 browser commit"
5346 set current_branch
[lindex
$argv 0]
5347 new_browser
$current_branch
5351 if {[llength
$argv] != 2} {
5352 puts stderr
"usage: $argv0 blame commit path"
5355 set current_branch
[lindex
$argv 0]
5356 show_blame
$current_branch [lindex
$argv 1]
5361 if {[llength
$argv] != 0} {
5362 puts
-nonewline stderr
"usage: $argv0"
5363 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
5364 puts
-nonewline stderr
" $subcommand"
5369 # fall through to setup UI for commits
5372 puts stderr
"usage: $argv0 \[{blame|browser|citool}\]"
5383 -text {Current Branch
:} \
5387 -textvariable current_branch \
5390 pack .branch.l1
-side left
5391 pack .branch.cb
-side left
-fill x
5392 pack .branch
-side top
-fill x
5394 # -- Main Window Layout
5396 panedwindow .vpane
-orient vertical
5397 panedwindow .vpane.files
-orient horizontal
5398 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
5399 pack .vpane
-anchor n
-side top
-fill both
-expand 1
5401 # -- Index File List
5403 frame .vpane.files.index
-height 100 -width 200
5404 label .vpane.files.index.title
-text {Changes To Be Committed
} \
5406 text
$ui_index -background white
-borderwidth 0 \
5407 -width 20 -height 10 \
5409 -cursor $cursor_ptr \
5410 -xscrollcommand {.vpane.files.index.sx
set} \
5411 -yscrollcommand {.vpane.files.index.sy
set} \
5413 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
5414 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
5415 pack .vpane.files.index.title
-side top
-fill x
5416 pack .vpane.files.index.sx
-side bottom
-fill x
5417 pack .vpane.files.index.sy
-side right
-fill y
5418 pack
$ui_index -side left
-fill both
-expand 1
5419 .vpane.files add .vpane.files.index
-sticky nsew
5421 # -- Working Directory File List
5423 frame .vpane.files.workdir
-height 100 -width 200
5424 label .vpane.files.workdir.title
-text {Changed But Not Updated
} \
5426 text
$ui_workdir -background white
-borderwidth 0 \
5427 -width 20 -height 10 \
5429 -cursor $cursor_ptr \
5430 -xscrollcommand {.vpane.files.workdir.sx
set} \
5431 -yscrollcommand {.vpane.files.workdir.sy
set} \
5433 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
5434 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
5435 pack .vpane.files.workdir.title
-side top
-fill x
5436 pack .vpane.files.workdir.sx
-side bottom
-fill x
5437 pack .vpane.files.workdir.sy
-side right
-fill y
5438 pack
$ui_workdir -side left
-fill both
-expand 1
5439 .vpane.files add .vpane.files.workdir
-sticky nsew
5441 foreach i
[list
$ui_index $ui_workdir] {
5442 $i tag conf in_diff
-font font_uibold
5443 $i tag conf in_sel \
5444 -background [$i cget
-foreground] \
5445 -foreground [$i cget
-background]
5449 # -- Diff and Commit Area
5451 frame .vpane.lower
-height 300 -width 400
5452 frame .vpane.lower.commarea
5453 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
5454 pack .vpane.lower.commarea
-side top
-fill x
5455 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
5456 .vpane add .vpane.lower
-sticky nsew
5458 # -- Commit Area Buttons
5460 frame .vpane.lower.commarea.buttons
5461 label .vpane.lower.commarea.buttons.l
-text {} \
5464 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
5465 pack .vpane.lower.commarea.buttons
-side left
-fill y
5467 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
5469 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
5470 lappend disable_on_lock \
5471 {.vpane.lower.commarea.buttons.rescan conf
-state}
5473 button .vpane.lower.commarea.buttons.incall
-text {Add Existing
} \
5475 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
5476 lappend disable_on_lock \
5477 {.vpane.lower.commarea.buttons.incall conf
-state}
5479 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
5481 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
5483 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
5485 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
5486 lappend disable_on_lock \
5487 {.vpane.lower.commarea.buttons.commit conf
-state}
5489 # -- Commit Message Buffer
5491 frame .vpane.lower.commarea.buffer
5492 frame .vpane.lower.commarea.buffer.header
5493 set ui_comm .vpane.lower.commarea.buffer.t
5494 set ui_coml .vpane.lower.commarea.buffer.header.l
5495 radiobutton .vpane.lower.commarea.buffer.header.new \
5496 -text {New Commit
} \
5497 -command do_select_commit_type \
5498 -variable selected_commit_type \
5500 lappend disable_on_lock \
5501 [list .vpane.lower.commarea.buffer.header.new conf
-state]
5502 radiobutton .vpane.lower.commarea.buffer.header.amend \
5503 -text {Amend Last Commit
} \
5504 -command do_select_commit_type \
5505 -variable selected_commit_type \
5507 lappend disable_on_lock \
5508 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
5512 proc trace_commit_type
{varname args
} {
5513 global ui_coml commit_type
5514 switch
-glob -- $commit_type {
5515 initial
{set txt
{Initial Commit Message
:}}
5516 amend
{set txt
{Amended Commit Message
:}}
5517 amend-initial
{set txt
{Amended Initial Commit Message
:}}
5518 amend-merge
{set txt
{Amended Merge Commit Message
:}}
5519 merge
{set txt
{Merge Commit Message
:}}
5520 * {set txt
{Commit Message
:}}
5522 $ui_coml conf
-text $txt
5524 trace add variable commit_type
write trace_commit_type
5525 pack
$ui_coml -side left
-fill x
5526 pack .vpane.lower.commarea.buffer.header.amend
-side right
5527 pack .vpane.lower.commarea.buffer.header.new
-side right
5529 text
$ui_comm -background white
-borderwidth 1 \
5532 -autoseparators true \
5534 -width 75 -height 9 -wrap none \
5536 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
5537 scrollbar .vpane.lower.commarea.buffer.sby \
5538 -command [list
$ui_comm yview
]
5539 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
5540 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
5541 pack
$ui_comm -side left
-fill y
5542 pack .vpane.lower.commarea.buffer
-side left
-fill y
5544 # -- Commit Message Buffer Context Menu
5546 set ctxm .vpane.lower.commarea.buffer.ctxm
5547 menu
$ctxm -tearoff 0
5550 -command {tk_textCut
$ui_comm}
5553 -command {tk_textCopy
$ui_comm}
5556 -command {tk_textPaste
$ui_comm}
5559 -command {$ui_comm delete sel.first sel.last
}
5562 -label {Select All
} \
5563 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
5567 $ui_comm tag add sel
0.0 end
5568 tk_textCopy
$ui_comm
5569 $ui_comm tag remove sel
0.0 end
5575 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
5579 proc trace_current_diff_path
{varname args
} {
5580 global current_diff_path diff_actions file_states
5581 if {$current_diff_path eq
{}} {
5587 set p
$current_diff_path
5588 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
5590 set p
[escape_path
$p]
5594 .vpane.lower.
diff.header.status configure
-text $s
5595 .vpane.lower.
diff.header.
file configure
-text $f
5596 .vpane.lower.
diff.header.path configure
-text $p
5597 foreach w
$diff_actions {
5601 trace add variable current_diff_path
write trace_current_diff_path
5603 frame .vpane.lower.
diff.header
-background orange
5604 label .vpane.lower.
diff.header.status \
5605 -background orange \
5606 -width $max_status_desc \
5609 label .vpane.lower.
diff.header.
file \
5610 -background orange \
5613 label .vpane.lower.
diff.header.path \
5614 -background orange \
5617 pack .vpane.lower.
diff.header.status
-side left
5618 pack .vpane.lower.
diff.header.
file -side left
5619 pack .vpane.lower.
diff.header.path
-fill x
5620 set ctxm .vpane.lower.
diff.header.ctxm
5621 menu
$ctxm -tearoff 0
5629 -- $current_diff_path
5631 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5632 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
5636 frame .vpane.lower.
diff.body
5637 set ui_diff .vpane.lower.
diff.body.t
5638 text
$ui_diff -background white
-borderwidth 0 \
5639 -width 80 -height 15 -wrap none \
5641 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
5642 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
5644 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
5645 -command [list
$ui_diff xview
]
5646 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
5647 -command [list
$ui_diff yview
]
5648 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
5649 pack .vpane.lower.
diff.body.sby
-side right
-fill y
5650 pack
$ui_diff -side left
-fill both
-expand 1
5651 pack .vpane.lower.
diff.header
-side top
-fill x
5652 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
5654 $ui_diff tag conf d_cr
-elide true
5655 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
5656 $ui_diff tag conf d_
+ -foreground {#00a000}
5657 $ui_diff tag conf d_-
-foreground red
5659 $ui_diff tag conf d_
++ -foreground {#00a000}
5660 $ui_diff tag conf d_--
-foreground red
5661 $ui_diff tag conf d_
+s \
5662 -foreground {#00a000} \
5663 -background {#e2effa}
5664 $ui_diff tag conf d_-s \
5666 -background {#e2effa}
5667 $ui_diff tag conf d_s
+ \
5668 -foreground {#00a000} \
5670 $ui_diff tag conf d_s- \
5674 $ui_diff tag conf d
<<<<<<< \
5675 -foreground orange \
5677 $ui_diff tag conf d
======= \
5678 -foreground orange \
5680 $ui_diff tag conf d
>>>>>>> \
5681 -foreground orange \
5684 $ui_diff tag raise sel
5686 # -- Diff Body Context Menu
5688 set ctxm .vpane.lower.
diff.body.ctxm
5689 menu
$ctxm -tearoff 0
5692 -command reshow_diff
5693 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5696 -command {tk_textCopy
$ui_diff}
5697 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5699 -label {Select All
} \
5700 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
5701 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5705 $ui_diff tag add sel
0.0 end
5706 tk_textCopy
$ui_diff
5707 $ui_diff tag remove sel
0.0 end
5709 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5712 -label {Apply
/Reverse Hunk
} \
5713 -command {apply_hunk
$cursorX $cursorY}
5714 set ui_diff_applyhunk
[$ctxm index last
]
5715 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
5718 -label {Decrease Font Size
} \
5719 -command {incr_font_size font_diff
-1}
5720 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5722 -label {Increase Font Size
} \
5723 -command {incr_font_size font_diff
1}
5724 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5727 -label {Show Less Context
} \
5728 -command {if {$repo_config(gui.diffcontext
) >= 2} {
5729 incr repo_config
(gui.diffcontext
) -1
5732 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5734 -label {Show More Context
} \
5736 incr repo_config
(gui.diffcontext
)
5739 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5741 $ctxm add
command -label {Options...
} \
5743 bind_button3
$ui_diff "
5746 if {\$ui_index eq \$current_diff_side} {
5747 $ctxm entryconf $ui_diff_applyhunk -label {Unstage Hunk From Commit}
5749 $ctxm entryconf $ui_diff_applyhunk -label {Stage Hunk For Commit}
5751 tk_popup $ctxm %X %Y
5753 unset ui_diff_applyhunk
5757 label .status
-textvariable ui_status_value \
5762 pack .status
-anchor w
-side bottom
-fill x
5767 set gm
$repo_config(gui.geometry
)
5768 wm geometry .
[lindex
$gm 0]
5769 .vpane sash place
0 \
5770 [lindex
[.vpane sash coord
0] 0] \
5772 .vpane.files sash place
0 \
5774 [lindex
[.vpane.files sash coord
0] 1]
5780 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
5781 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
5782 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
5783 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
5784 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
5785 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
5786 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
5787 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
5788 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
5789 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5790 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5792 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
5793 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
5794 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
5795 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
5796 bind $ui_diff <$M1B-Key-v> {break}
5797 bind $ui_diff <$M1B-Key-V> {break}
5798 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5799 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5800 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
5801 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
5802 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
5803 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
5804 bind $ui_diff <Button-1
> {focus
%W
}
5806 if {[is_enabled branch
]} {
5807 bind .
<$M1B-Key-n> do_create_branch
5808 bind .
<$M1B-Key-N> do_create_branch
5811 bind all
<Key-F5
> do_rescan
5812 bind all
<$M1B-Key-r> do_rescan
5813 bind all
<$M1B-Key-R> do_rescan
5814 bind .
<$M1B-Key-s> do_signoff
5815 bind .
<$M1B-Key-S> do_signoff
5816 bind .
<$M1B-Key-i> do_add_all
5817 bind .
<$M1B-Key-I> do_add_all
5818 bind .
<$M1B-Key-Return> do_commit
5819 foreach i
[list
$ui_index $ui_workdir] {
5820 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
5821 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
5822 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
5826 set file_lists
($ui_index) [list
]
5827 set file_lists
($ui_workdir) [list
]
5829 wm title .
"[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"
5830 focus
-force $ui_comm
5832 # -- Warn the user about environmental problems. Cygwin's Tcl
5833 # does *not* pass its env array onto any processes it spawns.
5834 # This means that git processes get none of our environment.
5839 set msg
"Possible environment issues exist.
5841 The following environment variables are probably
5842 going to be ignored by any Git subprocess run
5846 foreach name
[array names env
] {
5847 switch
-regexp -- $name {
5848 {^GIT_INDEX_FILE$
} -
5849 {^GIT_OBJECT_DIRECTORY$
} -
5850 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
5852 {^GIT_EXTERNAL_DIFF$
} -
5856 {^GIT_CONFIG_LOCAL$
} -
5857 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
5858 append msg
" - $name\n"
5861 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
5862 append msg
" - $name\n"
5864 set suggest_user
$name
5868 if {$ignored_env > 0} {
5870 This is due to a known issue with the
5871 Tcl binary distributed by Cygwin."
5873 if {$suggest_user ne
{}} {
5876 A good replacement for $suggest_user
5877 is placing values for the user.name and
5878 user.email settings into your personal
5884 unset ignored_env msg suggest_user name
5887 # -- Only initialize complex UI if we are going to stay running.
5889 if {[is_enabled transport
]} {
5893 populate_branch_menu
5898 # -- Only suggest a gc run if we are going to stay running.
5900 if {[is_enabled multicommit
]} {
5901 set object_limit
2000
5902 if {[is_Windows
]} {set object_limit
200}
5903 regexp
{^
([0-9]+) objects
,} [git count-objects
] _junk objects_current
5904 if {$objects_current >= $object_limit} {
5906 "This repository currently has $objects_current loose objects.
5908 To maintain optimal performance it is strongly recommended that you compress the database when more than $object_limit loose objects exist.
5910 Compress the database now?"] eq
yes} {
5914 unset object_limit _junk objects_current
5917 lock_index begin-read