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 option add
*Dialog.msg.font font_ui
246 option add
*Button.font font_ui
247 set cmd
[list tk_messageBox \
250 -title "$title: error" \
252 if {[winfo ismapped .
]} {
253 lappend cmd
-parent .
258 proc warn_popup
{msg
} {
260 if {[reponame
] ne
{}} {
261 append title
" ([reponame])"
263 option add
*Dialog.msg.font font_ui
264 option add
*Button.font font_ui
265 set cmd
[list tk_messageBox \
268 -title "$title: warning" \
270 if {[winfo ismapped .
]} {
271 lappend cmd
-parent .
276 proc info_popup
{msg
{parent .
}} {
278 if {[reponame
] ne
{}} {
279 append title
" ([reponame])"
281 option add
*Dialog.msg.font font_ui
282 option add
*Button.font font_ui
291 proc ask_popup
{msg
} {
293 if {[reponame
] ne
{}} {
294 append title
" ([reponame])"
296 option add
*Dialog.msg.font font_ui
297 option add
*Button.font font_ui
298 return [tk_messageBox \
306 ######################################################################
310 if {{--version} eq
$argv ||
{version
} eq
$argv} {
311 puts
"git-gui version $appvers"
318 if {[catch
{set v
[git
--version]} err
]} {
319 catch
{wm withdraw .
}
320 error_popup
"Cannot determine Git version:
324 [appname] requires Git $req_maj.$req_min or later."
327 if {[regexp
{^git version
(\d
+)\.
(\d
+)} $v _junk act_maj act_min
]} {
328 if {$act_maj < $req_maj
329 ||
($act_maj == $req_maj && $act_min < $req_min)} {
330 catch
{wm withdraw .
}
331 error_popup
"[appname] requires Git $req_maj.$req_min or later.
337 catch
{wm withdraw .
}
338 error_popup
"Cannot parse Git version string:\n\n$v"
341 unset -nocomplain v _junk act_maj act_min req_maj req_min
343 ######################################################################
347 if { [catch
{set _gitdir
$env(GIT_DIR
)}]
348 && [catch
{set _gitdir
[git rev-parse
--git-dir]} err
]} {
349 catch
{wm withdraw .
}
350 error_popup
"Cannot find the git directory:\n\n$err"
353 if {![file isdirectory
$_gitdir] && [is_Cygwin
]} {
354 catch
{set _gitdir
[exec cygpath
--unix $_gitdir]}
356 if {![file isdirectory
$_gitdir]} {
357 catch
{wm withdraw .
}
358 error_popup
"Git directory not found:\n\n$_gitdir"
361 if {[lindex
[file split $_gitdir] end
] ne
{.git
}} {
362 catch
{wm withdraw .
}
363 error_popup
"Cannot use funny .git directory:\n\n$_gitdir"
366 if {[catch
{cd [file dirname $_gitdir]} err
]} {
367 catch
{wm withdraw .
}
368 error_popup
"No working directory [file dirname $_gitdir]:\n\n$err"
371 set _reponame
[lindex
[file split \
372 [file normalize
[file dirname $_gitdir]]] \
375 ######################################################################
379 set current_diff_path
{}
380 set current_diff_side
{}
381 set diff_actions
[list
]
382 set ui_status_value
{Initializing...
}
386 set MERGE_HEAD
[list
]
389 set current_branch
{}
390 set current_diff_path
{}
391 set selected_commit_type new
393 ######################################################################
401 set disable_on_lock
[list
]
402 set index_lock_type none
404 proc lock_index
{type} {
405 global index_lock_type disable_on_lock
407 if {$index_lock_type eq
{none
}} {
408 set index_lock_type
$type
409 foreach w
$disable_on_lock {
410 uplevel
#0 $w disabled
413 } elseif
{$index_lock_type eq
"begin-$type"} {
414 set index_lock_type
$type
420 proc unlock_index
{} {
421 global index_lock_type disable_on_lock
423 set index_lock_type none
424 foreach w
$disable_on_lock {
429 ######################################################################
433 proc repository_state
{ctvar hdvar mhvar
} {
434 global current_branch
435 upvar
$ctvar ct
$hdvar hd
$mhvar mh
439 if {[catch
{set current_branch
[git symbolic-ref HEAD
]}]} {
440 set current_branch
{}
442 regsub ^refs
/((heads|tags|remotes
)/)? \
448 if {[catch
{set hd
[git rev-parse
--verify HEAD
]}]} {
454 set merge_head
[gitdir MERGE_HEAD
]
455 if {[file exists
$merge_head]} {
457 set fd_mh
[open
$merge_head r
]
458 while {[gets
$fd_mh line
] >= 0} {
469 global PARENT empty_tree
471 set p
[lindex
$PARENT 0]
475 if {$empty_tree eq
{}} {
476 set empty_tree
[git mktree
<< {}]
481 proc rescan
{after
{honor_trustmtime
1}} {
482 global HEAD PARENT MERGE_HEAD commit_type
483 global ui_index ui_workdir ui_status_value ui_comm
484 global rescan_active file_states
487 if {$rescan_active > 0 ||
![lock_index
read]} return
489 repository_state newType newHEAD newMERGE_HEAD
490 if {[string match amend
* $commit_type]
491 && $newType eq
{normal
}
492 && $newHEAD eq
$HEAD} {
496 set MERGE_HEAD
$newMERGE_HEAD
497 set commit_type
$newType
500 array
unset file_states
502 if {![$ui_comm edit modified
]
503 ||
[string trim
[$ui_comm get
0.0 end
]] eq
{}} {
504 if {[load_message GITGUI_MSG
]} {
505 } elseif
{[load_message MERGE_MSG
]} {
506 } elseif
{[load_message SQUASH_MSG
]} {
509 $ui_comm edit modified false
512 if {[is_enabled branch
]} {
517 if {$honor_trustmtime && $repo_config(gui.trustmtime
) eq
{true
}} {
518 rescan_stage2
{} $after
521 set ui_status_value
{Refreshing
file status...
}
522 set cmd
[list git update-index
]
524 lappend cmd
--unmerged
525 lappend cmd
--ignore-missing
526 lappend cmd
--refresh
527 set fd_rf
[open
"| $cmd" r
]
528 fconfigure
$fd_rf -blocking 0 -translation binary
529 fileevent
$fd_rf readable \
530 [list rescan_stage2
$fd_rf $after]
534 proc rescan_stage2
{fd after
} {
535 global ui_status_value
536 global rescan_active buf_rdi buf_rdf buf_rlo
540 if {![eof
$fd]} return
544 set ls_others
[list | git ls-files
--others -z \
545 --exclude-per-directory=.gitignore
]
546 set info_exclude
[gitdir info exclude
]
547 if {[file readable
$info_exclude]} {
548 lappend ls_others
"--exclude-from=$info_exclude"
556 set ui_status_value
{Scanning
for modified files ...
}
557 set fd_di
[open
"| git diff-index --cached -z [PARENT]" r
]
558 set fd_df
[open
"| git diff-files -z" r
]
559 set fd_lo
[open
$ls_others r
]
561 fconfigure
$fd_di -blocking 0 -translation binary
-encoding binary
562 fconfigure
$fd_df -blocking 0 -translation binary
-encoding binary
563 fconfigure
$fd_lo -blocking 0 -translation binary
-encoding binary
564 fileevent
$fd_di readable
[list read_diff_index
$fd_di $after]
565 fileevent
$fd_df readable
[list read_diff_files
$fd_df $after]
566 fileevent
$fd_lo readable
[list read_ls_others
$fd_lo $after]
569 proc load_message
{file} {
573 if {[file isfile
$f]} {
574 if {[catch
{set fd
[open
$f r
]}]} {
577 set content
[string trim
[read $fd]]
579 regsub
-all -line {[ \r\t]+$
} $content {} content
580 $ui_comm delete
0.0 end
581 $ui_comm insert end
$content
587 proc read_diff_index
{fd after
} {
590 append buf_rdi
[read $fd]
592 set n
[string length
$buf_rdi]
594 set z1
[string first
"\0" $buf_rdi $c]
597 set z2
[string first
"\0" $buf_rdi $z1]
601 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
602 set p
[string range
$buf_rdi $z1 [expr {$z2 - 1}]]
604 [encoding convertfrom
$p] \
606 [list
[lindex
$i 0] [lindex
$i 2]] \
612 set buf_rdi
[string range
$buf_rdi $c end
]
617 rescan_done
$fd buf_rdi
$after
620 proc read_diff_files
{fd after
} {
623 append buf_rdf
[read $fd]
625 set n
[string length
$buf_rdf]
627 set z1
[string first
"\0" $buf_rdf $c]
630 set z2
[string first
"\0" $buf_rdf $z1]
634 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
635 set p
[string range
$buf_rdf $z1 [expr {$z2 - 1}]]
637 [encoding convertfrom
$p] \
640 [list
[lindex
$i 0] [lindex
$i 2]]
645 set buf_rdf
[string range
$buf_rdf $c end
]
650 rescan_done
$fd buf_rdf
$after
653 proc read_ls_others
{fd after
} {
656 append buf_rlo
[read $fd]
657 set pck
[split $buf_rlo "\0"]
658 set buf_rlo
[lindex
$pck end
]
659 foreach p
[lrange
$pck 0 end-1
] {
660 merge_state
[encoding convertfrom
$p] ?O
662 rescan_done
$fd buf_rlo
$after
665 proc rescan_done
{fd buf after
} {
667 global file_states repo_config
670 if {![eof
$fd]} return
673 if {[incr rescan_active
-1] > 0} return
682 proc prune_selection
{} {
683 global file_states selected_paths
685 foreach path
[array names selected_paths
] {
686 if {[catch
{set still_here
$file_states($path)}]} {
687 unset selected_paths
($path)
692 ######################################################################
697 global ui_diff current_diff_path current_diff_header
698 global ui_index ui_workdir
700 $ui_diff conf
-state normal
701 $ui_diff delete
0.0 end
702 $ui_diff conf
-state disabled
704 set current_diff_path
{}
705 set current_diff_header
{}
707 $ui_index tag remove in_diff
0.0 end
708 $ui_workdir tag remove in_diff
0.0 end
711 proc reshow_diff
{} {
712 global ui_status_value file_states file_lists
713 global current_diff_path current_diff_side
715 set p
$current_diff_path
717 # No diff is being shown.
718 } elseif
{$current_diff_side eq
{}
719 ||
[catch
{set s
$file_states($p)}]
720 ||
[lsearch
-sorted -exact $file_lists($current_diff_side) $p] == -1} {
723 show_diff
$p $current_diff_side
727 proc handle_empty_diff
{} {
728 global current_diff_path file_states file_lists
730 set path
$current_diff_path
731 set s
$file_states($path)
732 if {[lindex
$s 0] ne
{_M
}} return
734 info_popup
"No differences detected.
736 [short_path $path] has no changes.
738 The modification date of this file was updated by another application, but the content within the file was not changed.
740 A rescan will be automatically started to find other files which may have the same state."
743 display_file
$path __
744 rescan
{set ui_status_value
{Ready.
}} 0
747 proc show_diff
{path w
{lno
{}}} {
748 global file_states file_lists
749 global is_3way_diff diff_active repo_config
750 global ui_diff ui_status_value ui_index ui_workdir
751 global current_diff_path current_diff_side current_diff_header
753 if {$diff_active ||
![lock_index
read]} return
757 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
763 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
766 set s
$file_states($path)
770 set current_diff_path
$path
771 set current_diff_side
$w
772 set current_diff_header
{}
773 set ui_status_value
"Loading diff of [escape_path $path]..."
775 # - Git won't give us the diff, there's nothing to compare to!
778 set max_sz
[expr {128 * 1024}]
780 set fd
[open
$path r
]
781 set content
[read $fd $max_sz]
783 set sz
[file size
$path]
787 set ui_status_value
"Unable to display [escape_path $path]"
788 error_popup
"Error loading file:\n\n$err"
791 $ui_diff conf
-state normal
792 if {![catch
{set type [exec file $path]}]} {
793 set n
[string length
$path]
794 if {[string equal
-length $n $path $type]} {
795 set type [string range
$type $n end
]
796 regsub
{^
:?\s
*} $type {} type
798 $ui_diff insert end
"* $type\n" d_@
800 if {[string first
"\0" $content] != -1} {
801 $ui_diff insert end \
802 "* Binary file (not showing content)." \
806 $ui_diff insert end \
807 "* Untracked file is $sz bytes.
808 * Showing only first $max_sz bytes.
811 $ui_diff insert end
$content
813 $ui_diff insert end
"
814 * Untracked file clipped here by [appname].
815 * To see the entire file, use an external editor.
819 $ui_diff conf
-state disabled
822 set ui_status_value
{Ready.
}
827 if {$w eq
$ui_index} {
828 lappend cmd diff-index
830 } elseif
{$w eq
$ui_workdir} {
831 if {[string index
$m 0] eq
{U
}} {
834 lappend cmd diff-files
839 lappend cmd
--no-color
840 if {$repo_config(gui.diffcontext
) > 0} {
841 lappend cmd
"-U$repo_config(gui.diffcontext)"
843 if {$w eq
$ui_index} {
849 if {[catch
{set fd
[open
$cmd r
]} err
]} {
852 set ui_status_value
"Unable to display [escape_path $path]"
853 error_popup
"Error loading diff:\n\n$err"
861 fileevent
$fd readable
[list read_diff
$fd]
864 proc read_diff
{fd
} {
865 global ui_diff ui_status_value diff_active
866 global is_3way_diff current_diff_header
868 $ui_diff conf
-state normal
869 while {[gets
$fd line
] >= 0} {
870 # -- Cleanup uninteresting diff header lines.
872 if { [string match
{diff --git *} $line]
873 ||
[string match
{diff --cc *} $line]
874 ||
[string match
{diff --combined *} $line]
875 ||
[string match
{--- *} $line]
876 ||
[string match
{+++ *} $line]} {
877 append current_diff_header
$line "\n"
880 if {[string match
{index
*} $line]} continue
881 if {$line eq
{deleted
file mode
120000}} {
882 set line
"deleted symlink"
885 # -- Automatically detect if this is a 3 way diff.
887 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
889 if {[string match
{mode
*} $line]
890 ||
[string match
{new
file *} $line]
891 ||
[string match
{deleted
file *} $line]
892 ||
[string match
{Binary files
* and
* differ
} $line]
893 ||
$line eq
{\ No newline
at end of
file}
894 ||
[regexp
{^\
* Unmerged path
} $line]} {
896 } elseif
{$is_3way_diff} {
897 set op
[string range
$line 0 1]
907 if {[regexp
{^\
+\
+([<>]{7} |
={7})} $line _g op
]} {
908 set line
[string replace
$line 0 1 { }]
915 puts
"error: Unhandled 3 way diff marker: {$op}"
920 set op
[string index
$line 0]
926 if {[regexp
{^\
+([<>]{7} |
={7})} $line _g op
]} {
927 set line
[string replace
$line 0 0 { }]
934 puts
"error: Unhandled 2 way diff marker: {$op}"
939 $ui_diff insert end
$line $tags
940 if {[string index
$line end
] eq
"\r"} {
941 $ui_diff tag add d_cr
{end
- 2c
}
943 $ui_diff insert end
"\n" $tags
945 $ui_diff conf
-state disabled
951 set ui_status_value
{Ready.
}
953 if {[$ui_diff index end
] eq
{2.0}} {
959 proc apply_hunk
{x y
} {
960 global current_diff_path current_diff_header current_diff_side
961 global ui_diff ui_index file_states
963 if {$current_diff_path eq
{} ||
$current_diff_header eq
{}} return
964 if {![lock_index apply_hunk
]} return
966 set apply_cmd
{git apply
--cached --whitespace=nowarn
}
967 set mi
[lindex
$file_states($current_diff_path) 0]
968 if {$current_diff_side eq
$ui_index} {
970 lappend apply_cmd
--reverse
971 if {[string index
$mi 0] ne
{M
}} {
977 if {[string index
$mi 1] ne
{M
}} {
983 set s_lno
[lindex
[split [$ui_diff index @
$x,$y] .
] 0]
984 set s_lno
[$ui_diff search
-backwards -regexp ^@@
$s_lno.0 0.0]
990 set e_lno
[$ui_diff search
-forwards -regexp ^@@
"$s_lno + 1 lines" end
]
996 set p
[open
"| $apply_cmd" w
]
997 fconfigure
$p -translation binary
-encoding binary
998 puts
-nonewline $p $current_diff_header
999 puts
-nonewline $p [$ui_diff get
$s_lno $e_lno]
1001 error_popup
"Failed to $mode selected hunk.\n\n$err"
1006 $ui_diff conf
-state normal
1007 $ui_diff delete
$s_lno $e_lno
1008 $ui_diff conf
-state disabled
1010 if {[$ui_diff get
1.0 end
] eq
"\n"} {
1016 if {$current_diff_side eq
$ui_index} {
1018 } elseif
{[string index
$mi 0] eq
{_
}} {
1024 display_file
$current_diff_path $mi
1030 ######################################################################
1034 proc load_last_commit
{} {
1035 global HEAD PARENT MERGE_HEAD commit_type ui_comm
1038 if {[llength
$PARENT] == 0} {
1039 error_popup
{There is nothing to amend.
1041 You are about to create the initial commit. There is no commit before this to amend.
1046 repository_state curType curHEAD curMERGE_HEAD
1047 if {$curType eq
{merge
}} {
1048 error_popup
{Cannot amend
while merging.
1050 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.
1058 set fd
[open
"| git cat-file commit $curHEAD" r
]
1059 fconfigure
$fd -encoding binary
-translation lf
1060 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1063 while {[gets
$fd line
] > 0} {
1064 if {[string match
{parent
*} $line]} {
1065 lappend parents
[string range
$line 7 end
]
1066 } elseif
{[string match
{encoding
*} $line]} {
1067 set enc
[string tolower
[string range
$line 9 end
]]
1070 set msg
[encoding convertfrom
$enc [read $fd]]
1071 set msg
[string trim
$msg]
1074 error_popup
"Error loading commit data for amend:\n\n$err"
1080 set MERGE_HEAD
[list
]
1081 switch
-- [llength
$parents] {
1082 0 {set commit_type amend-initial
}
1083 1 {set commit_type amend
}
1084 default
{set commit_type amend-merge
}
1087 $ui_comm delete
0.0 end
1088 $ui_comm insert end
$msg
1090 $ui_comm edit modified false
1091 rescan
{set ui_status_value
{Ready.
}}
1094 proc create_new_commit
{} {
1095 global commit_type ui_comm
1097 set commit_type normal
1098 $ui_comm delete
0.0 end
1100 $ui_comm edit modified false
1101 rescan
{set ui_status_value
{Ready.
}}
1104 set GIT_COMMITTER_IDENT
{}
1106 proc committer_ident
{} {
1107 global GIT_COMMITTER_IDENT
1109 if {$GIT_COMMITTER_IDENT eq
{}} {
1110 if {[catch
{set me
[git var GIT_COMMITTER_IDENT
]} err
]} {
1111 error_popup
"Unable to obtain your identity:\n\n$err"
1114 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
1115 $me me GIT_COMMITTER_IDENT
]} {
1116 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
1121 return $GIT_COMMITTER_IDENT
1124 proc commit_tree
{} {
1125 global HEAD commit_type file_states ui_comm repo_config
1126 global ui_status_value pch_error
1128 if {[committer_ident
] eq
{}} return
1129 if {![lock_index update
]} return
1131 # -- Our in memory state should match the repository.
1133 repository_state curType curHEAD curMERGE_HEAD
1134 if {[string match amend
* $commit_type]
1135 && $curType eq
{normal
}
1136 && $curHEAD eq
$HEAD} {
1137 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1138 info_popup
{Last scanned state does not match repository state.
1140 Another Git program has modified this repository since the last scan. A rescan must be performed before another commit can be created.
1142 The rescan will be automatically started now.
1145 rescan
{set ui_status_value
{Ready.
}}
1149 # -- At least one file should differ in the index.
1152 foreach path
[array names file_states
] {
1153 switch
-glob -- [lindex
$file_states($path) 0] {
1157 M?
{set files_ready
1}
1159 error_popup
"Unmerged files cannot be committed.
1161 File [short_path $path] has merge conflicts. You must resolve them and add the file before committing.
1167 error_popup
"Unknown file state [lindex $s 0] detected.
1169 File [short_path $path] cannot be committed by this program.
1174 if {!$files_ready && ![string match
*merge
$curType]} {
1175 info_popup
{No changes to commit.
1177 You must add
at least
1 file before you can commit.
1183 # -- A message is required.
1185 set msg
[string trim
[$ui_comm get
1.0 end
]]
1186 regsub
-all -line {[ \t\r]+$
} $msg {} msg
1188 error_popup
{Please supply a commit message.
1190 A good commit message has the following format
:
1192 - First line
: Describe
in one sentance what you did.
1193 - Second line
: Blank
1194 - Remaining lines
: Describe why this change is good.
1200 # -- Run the pre-commit hook.
1202 set pchook
[gitdir hooks pre-commit
]
1204 # On Cygwin [file executable] might lie so we need to ask
1205 # the shell if the hook is executable. Yes that's annoying.
1207 if {[is_Cygwin
] && [file isfile
$pchook]} {
1208 set pchook
[list sh
-c [concat \
1209 "if test -x \"$pchook\";" \
1210 "then exec \"$pchook\" 2>&1;" \
1212 } elseif
{[file executable
$pchook]} {
1213 set pchook
[list
$pchook |
& cat]
1215 commit_writetree
$curHEAD $msg
1219 set ui_status_value
{Calling pre-commit hook...
}
1221 set fd_ph
[open
"| $pchook" r
]
1222 fconfigure
$fd_ph -blocking 0 -translation binary
1223 fileevent
$fd_ph readable \
1224 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
1227 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
1228 global pch_error ui_status_value
1230 append pch_error
[read $fd_ph]
1231 fconfigure
$fd_ph -blocking 1
1233 if {[catch
{close
$fd_ph}]} {
1234 set ui_status_value
{Commit declined by pre-commit hook.
}
1235 hook_failed_popup pre-commit
$pch_error
1238 commit_writetree
$curHEAD $msg
1243 fconfigure
$fd_ph -blocking 0
1246 proc commit_writetree
{curHEAD msg
} {
1247 global ui_status_value
1249 set ui_status_value
{Committing changes...
}
1250 set fd_wt
[open
"| git write-tree" r
]
1251 fileevent
$fd_wt readable \
1252 [list commit_committree
$fd_wt $curHEAD $msg]
1255 proc commit_committree
{fd_wt curHEAD msg
} {
1256 global HEAD PARENT MERGE_HEAD commit_type
1257 global all_heads current_branch
1258 global ui_status_value ui_comm selected_commit_type
1259 global file_states selected_paths rescan_active
1263 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1264 error_popup
"write-tree failed:\n\n$err"
1265 set ui_status_value
{Commit failed.
}
1270 # -- Verify this wasn't an empty change.
1272 if {$commit_type eq
{normal
}} {
1273 set old_tree
[git rev-parse
"$PARENT^{tree}"]
1274 if {$tree_id eq
$old_tree} {
1275 info_popup
{No changes to commit.
1277 No files were modified by this commit and it was not a merge commit.
1279 A rescan will be automatically started now.
1282 rescan
{set ui_status_value
{No changes to commit.
}}
1287 # -- Build the message.
1289 set msg_p
[gitdir COMMIT_EDITMSG
]
1290 set msg_wt
[open
$msg_p w
]
1291 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1294 fconfigure
$msg_wt -encoding binary
-translation binary
1295 puts
-nonewline $msg_wt [encoding convertto
$enc $msg]
1298 # -- Create the commit.
1300 set cmd
[list git commit-tree
$tree_id]
1301 foreach p
[concat
$PARENT $MERGE_HEAD] {
1305 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1306 error_popup
"commit-tree failed:\n\n$err"
1307 set ui_status_value
{Commit failed.
}
1312 # -- Update the HEAD ref.
1315 if {$commit_type ne
{normal
}} {
1316 append reflogm
" ($commit_type)"
1318 set i
[string first
"\n" $msg]
1320 set subject
[string range
$msg 0 [expr {$i - 1}]]
1324 append reflogm
{: } $subject
1325 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1326 if {[catch
{eval exec $cmd} err
]} {
1327 error_popup
"update-ref failed:\n\n$err"
1328 set ui_status_value
{Commit failed.
}
1333 # -- Cleanup after ourselves.
1335 catch
{file delete
$msg_p}
1336 catch
{file delete
[gitdir MERGE_HEAD
]}
1337 catch
{file delete
[gitdir MERGE_MSG
]}
1338 catch
{file delete
[gitdir SQUASH_MSG
]}
1339 catch
{file delete
[gitdir GITGUI_MSG
]}
1341 # -- Let rerere do its thing.
1343 if {[file isdirectory
[gitdir rr-cache
]]} {
1347 # -- Run the post-commit hook.
1349 set pchook
[gitdir hooks post-commit
]
1350 if {[is_Cygwin
] && [file isfile
$pchook]} {
1351 set pchook
[list sh
-c [concat \
1352 "if test -x \"$pchook\";" \
1353 "then exec \"$pchook\";" \
1355 } elseif
{![file executable
$pchook]} {
1358 if {$pchook ne
{}} {
1359 catch
{exec $pchook &}
1362 $ui_comm delete
0.0 end
1364 $ui_comm edit modified false
1366 if {[is_enabled singlecommit
]} do_quit
1368 # -- Make sure our current branch exists.
1370 if {$commit_type eq
{initial
}} {
1371 lappend all_heads
$current_branch
1372 set all_heads
[lsort
-unique $all_heads]
1373 populate_branch_menu
1376 # -- Update in memory status
1378 set selected_commit_type new
1379 set commit_type normal
1382 set MERGE_HEAD
[list
]
1384 foreach path
[array names file_states
] {
1385 set s
$file_states($path)
1387 switch
-glob -- $m {
1395 unset file_states
($path)
1396 catch
{unset selected_paths
($path)}
1399 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1405 set file_states
($path) [list \
1406 _
[string index
$m 1] \
1417 set ui_status_value \
1418 "Created commit [string range $cmt_id 0 7]: $subject"
1421 ######################################################################
1425 proc fetch_from
{remote
} {
1426 set w
[new_console \
1428 "Fetching new changes from $remote"]
1429 set cmd
[list git fetch
]
1431 console_exec
$w $cmd console_done
1434 proc push_to
{remote
} {
1435 set w
[new_console \
1437 "Pushing changes to $remote"]
1438 set cmd
[list git push
]
1441 console_exec
$w $cmd console_done
1444 ######################################################################
1448 proc mapicon
{w state path
} {
1451 if {[catch
{set r
$all_icons($state$w)}]} {
1452 puts
"error: no icon for $w state={$state} $path"
1458 proc mapdesc
{state path
} {
1461 if {[catch
{set r
$all_descs($state)}]} {
1462 puts
"error: no desc for state={$state} $path"
1468 proc escape_path
{path
} {
1469 regsub
-all {\\} $path "\\\\" path
1470 regsub
-all "\n" $path "\\n" path
1474 proc short_path
{path
} {
1475 return [escape_path
[lindex
[file split $path] end
]]
1479 set null_sha1
[string repeat
0 40]
1481 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1482 global file_states next_icon_id null_sha1
1484 set s0
[string index
$new_state 0]
1485 set s1
[string index
$new_state 1]
1487 if {[catch
{set info
$file_states($path)}]} {
1489 set icon n
[incr next_icon_id
]
1491 set state
[lindex
$info 0]
1492 set icon
[lindex
$info 1]
1493 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1494 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1497 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1498 elseif
{$s0 eq
{_
}} {set s0 _
}
1500 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1501 elseif
{$s1 eq
{_
}} {set s1 _
}
1503 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1504 set head_info
[list
0 $null_sha1]
1505 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1506 && $head_info eq
{}} {
1507 set head_info
$index_info
1510 set file_states
($path) [list
$s0$s1 $icon \
1511 $head_info $index_info \
1516 proc display_file_helper
{w path icon_name old_m new_m
} {
1519 if {$new_m eq
{_
}} {
1520 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1522 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1524 $w conf
-state normal
1525 $w delete
$lno.0 [expr {$lno + 1}].0
1526 $w conf
-state disabled
1528 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1529 lappend file_lists
($w) $path
1530 set file_lists
($w) [lsort
-unique $file_lists($w)]
1531 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1533 $w conf
-state normal
1534 $w image create
$lno.0 \
1535 -align center
-padx 5 -pady 1 \
1537 -image [mapicon
$w $new_m $path]
1538 $w insert
$lno.1 "[escape_path $path]\n"
1539 $w conf
-state disabled
1540 } elseif
{$old_m ne
$new_m} {
1541 $w conf
-state normal
1542 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1543 $w conf
-state disabled
1547 proc display_file
{path state
} {
1548 global file_states selected_paths
1549 global ui_index ui_workdir
1551 set old_m
[merge_state
$path $state]
1552 set s
$file_states($path)
1553 set new_m
[lindex
$s 0]
1554 set icon_name
[lindex
$s 1]
1556 set o
[string index
$old_m 0]
1557 set n
[string index
$new_m 0]
1564 display_file_helper
$ui_index $path $icon_name $o $n
1566 if {[string index
$old_m 0] eq
{U
}} {
1569 set o
[string index
$old_m 1]
1571 if {[string index
$new_m 0] eq
{U
}} {
1574 set n
[string index
$new_m 1]
1576 display_file_helper
$ui_workdir $path $icon_name $o $n
1578 if {$new_m eq
{__
}} {
1579 unset file_states
($path)
1580 catch
{unset selected_paths
($path)}
1584 proc display_all_files_helper
{w path icon_name m
} {
1587 lappend file_lists
($w) $path
1588 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1589 $w image create end \
1590 -align center
-padx 5 -pady 1 \
1592 -image [mapicon
$w $m $path]
1593 $w insert end
"[escape_path $path]\n"
1596 proc display_all_files
{} {
1597 global ui_index ui_workdir
1598 global file_states file_lists
1601 $ui_index conf
-state normal
1602 $ui_workdir conf
-state normal
1604 $ui_index delete
0.0 end
1605 $ui_workdir delete
0.0 end
1608 set file_lists
($ui_index) [list
]
1609 set file_lists
($ui_workdir) [list
]
1611 foreach path
[lsort
[array names file_states
]] {
1612 set s
$file_states($path)
1614 set icon_name
[lindex
$s 1]
1616 set s
[string index
$m 0]
1617 if {$s ne
{U
} && $s ne
{_
}} {
1618 display_all_files_helper
$ui_index $path \
1622 if {[string index
$m 0] eq
{U
}} {
1625 set s
[string index
$m 1]
1628 display_all_files_helper
$ui_workdir $path \
1633 $ui_index conf
-state disabled
1634 $ui_workdir conf
-state disabled
1637 proc update_indexinfo
{msg pathList after
} {
1638 global update_index_cp ui_status_value
1640 if {![lock_index update
]} return
1642 set update_index_cp
0
1643 set pathList
[lsort
$pathList]
1644 set totalCnt
[llength
$pathList]
1645 set batch [expr {int
($totalCnt * .01) + 1}]
1646 if {$batch > 25} {set batch 25}
1648 set ui_status_value
[format \
1649 "$msg... %i/%i files (%.2f%%)" \
1653 set fd
[open
"| git update-index -z --index-info" w
]
1660 fileevent
$fd writable
[list \
1661 write_update_indexinfo \
1671 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1672 global update_index_cp ui_status_value
1673 global file_states current_diff_path
1675 if {$update_index_cp >= $totalCnt} {
1682 for {set i
$batch} \
1683 {$update_index_cp < $totalCnt && $i > 0} \
1685 set path
[lindex
$pathList $update_index_cp]
1686 incr update_index_cp
1688 set s
$file_states($path)
1689 switch
-glob -- [lindex
$s 0] {
1696 set info
[lindex
$s 2]
1697 if {$info eq
{}} continue
1699 puts
-nonewline $fd "$info\t[encoding convertto $path]\0"
1700 display_file
$path $new
1703 set ui_status_value
[format \
1704 "$msg... %i/%i files (%.2f%%)" \
1707 [expr {100.0 * $update_index_cp / $totalCnt}]]
1710 proc update_index
{msg pathList after
} {
1711 global update_index_cp ui_status_value
1713 if {![lock_index update
]} return
1715 set update_index_cp
0
1716 set pathList
[lsort
$pathList]
1717 set totalCnt
[llength
$pathList]
1718 set batch [expr {int
($totalCnt * .01) + 1}]
1719 if {$batch > 25} {set batch 25}
1721 set ui_status_value
[format \
1722 "$msg... %i/%i files (%.2f%%)" \
1726 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1733 fileevent
$fd writable
[list \
1734 write_update_index \
1744 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1745 global update_index_cp ui_status_value
1746 global file_states current_diff_path
1748 if {$update_index_cp >= $totalCnt} {
1755 for {set i
$batch} \
1756 {$update_index_cp < $totalCnt && $i > 0} \
1758 set path
[lindex
$pathList $update_index_cp]
1759 incr update_index_cp
1761 switch
-glob -- [lindex
$file_states($path) 0] {
1767 if {[file exists
$path]} {
1776 puts
-nonewline $fd "[encoding convertto $path]\0"
1777 display_file
$path $new
1780 set ui_status_value
[format \
1781 "$msg... %i/%i files (%.2f%%)" \
1784 [expr {100.0 * $update_index_cp / $totalCnt}]]
1787 proc checkout_index
{msg pathList after
} {
1788 global update_index_cp ui_status_value
1790 if {![lock_index update
]} return
1792 set update_index_cp
0
1793 set pathList
[lsort
$pathList]
1794 set totalCnt
[llength
$pathList]
1795 set batch [expr {int
($totalCnt * .01) + 1}]
1796 if {$batch > 25} {set batch 25}
1798 set ui_status_value
[format \
1799 "$msg... %i/%i files (%.2f%%)" \
1803 set cmd
[list git checkout-index
]
1809 set fd
[open
"| $cmd " w
]
1816 fileevent
$fd writable
[list \
1817 write_checkout_index \
1827 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1828 global update_index_cp ui_status_value
1829 global file_states current_diff_path
1831 if {$update_index_cp >= $totalCnt} {
1838 for {set i
$batch} \
1839 {$update_index_cp < $totalCnt && $i > 0} \
1841 set path
[lindex
$pathList $update_index_cp]
1842 incr update_index_cp
1843 switch
-glob -- [lindex
$file_states($path) 0] {
1847 puts
-nonewline $fd "[encoding convertto $path]\0"
1848 display_file
$path ?_
1853 set ui_status_value
[format \
1854 "$msg... %i/%i files (%.2f%%)" \
1857 [expr {100.0 * $update_index_cp / $totalCnt}]]
1860 ######################################################################
1862 ## branch management
1864 proc is_tracking_branch
{name
} {
1865 global tracking_branches
1867 if {![catch
{set info
$tracking_branches($name)}]} {
1870 foreach t
[array names tracking_branches
] {
1871 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1878 proc load_all_heads
{} {
1881 set all_heads
[list
]
1882 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1883 while {[gets
$fd line
] > 0} {
1884 if {[is_tracking_branch
$line]} continue
1885 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1886 lappend all_heads
$name
1890 set all_heads
[lsort
$all_heads]
1893 proc populate_branch_menu
{} {
1894 global all_heads disable_on_lock
1897 set last
[$m index last
]
1898 for {set i
0} {$i <= $last} {incr i
} {
1899 if {[$m type $i] eq
{separator
}} {
1902 foreach a
$disable_on_lock {
1903 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1907 set disable_on_lock
$new_dol
1912 if {$all_heads ne
{}} {
1915 foreach b
$all_heads {
1916 $m add radiobutton \
1918 -command [list switch_branch
$b] \
1919 -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 \
2082 -command [list do_create_branch_action
$w]
2083 pack
$w.buttons.create
-side right
2084 button
$w.buttons.cancel
-text {Cancel
} \
2086 -command [list destroy
$w]
2087 pack
$w.buttons.cancel
-side right
-padx 5
2088 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2090 labelframe
$w.desc \
2091 -text {Branch Description
} \
2093 label
$w.desc.name_l
-text {Name
:} -font font_ui
2094 entry
$w.desc.name_t \
2098 -textvariable create_branch_name \
2102 if {%d
== 1 && [regexp
{[~^
:?
*\
[\
0- ]} %S
]} {return 0}
2105 grid
$w.desc.name_l
$w.desc.name_t
-sticky we
-padx {0 5}
2106 grid columnconfigure
$w.desc
1 -weight 1
2107 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
2109 labelframe
$w.from \
2110 -text {Starting Revision
} \
2112 radiobutton
$w.from.head_r \
2113 -text {Local Branch
:} \
2115 -variable create_branch_revtype \
2117 set lbranchm
[eval tk_optionMenu
$w.from.head_m create_branch_head \
2119 $lbranchm configure
-font font_ui
2120 $w.from.head_m configure
-font font_ui
2121 grid
$w.from.head_r
$w.from.head_m
-sticky w
2122 set all_trackings
[all_tracking_branches
]
2123 if {$all_trackings ne
{}} {
2124 set create_branch_trackinghead
[lindex
$all_trackings 0]
2125 radiobutton
$w.from.tracking_r \
2126 -text {Tracking Branch
:} \
2128 -variable create_branch_revtype \
2130 set tbranchm
[eval tk_optionMenu
$w.from.tracking_m \
2131 create_branch_trackinghead \
2133 $tbranchm configure
-font font_ui
2134 $w.from.tracking_m configure
-font font_ui
2135 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
2137 set all_tags
[load_all_tags
]
2138 if {$all_tags ne
{}} {
2139 set create_branch_tag
[lindex
$all_tags 0]
2140 radiobutton
$w.from.tag_r \
2143 -variable create_branch_revtype \
2145 set tagsm
[eval tk_optionMenu
$w.from.tag_m \
2148 $tagsm configure
-font font_ui
2149 $w.from.tag_m configure
-font font_ui
2150 grid
$w.from.tag_r
$w.from.tag_m
-sticky w
2152 radiobutton
$w.from.exp_r \
2153 -text {Revision Expression
:} \
2155 -variable create_branch_revtype \
2157 entry
$w.from.exp_t \
2161 -textvariable create_branch_revexp \
2165 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2166 if {%d
== 1 && [string length
%S
] > 0} {
2167 set create_branch_revtype expression
2171 grid
$w.from.exp_r
$w.from.exp_t
-sticky we
-padx {0 5}
2172 grid columnconfigure
$w.from
1 -weight 1
2173 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
2175 labelframe
$w.postActions \
2176 -text {Post Creation Actions
} \
2178 checkbutton
$w.postActions.checkout \
2179 -text {Checkout after creation
} \
2180 -variable create_branch_checkout \
2182 pack
$w.postActions.checkout
-anchor nw
2183 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
2185 set create_branch_checkout
1
2186 set create_branch_head
$current_branch
2187 set create_branch_revtype
head
2188 set create_branch_name
$repo_config(gui.newbranchtemplate
)
2189 set create_branch_revexp
{}
2191 bind $w <Visibility
> "
2193 $w.desc.name_t icursor end
2194 focus $w.desc.name_t
2196 bind $w <Key-Escape
> "destroy $w"
2197 bind $w <Key-Return
> "do_create_branch_action $w;break"
2198 wm title
$w "[appname] ([reponame]): Create Branch"
2202 proc do_delete_branch_action
{w
} {
2204 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2207 switch
-- $delete_branch_checktype {
2208 head {set check_rev
$delete_branch_head}
2209 tracking
{set check_rev
$delete_branch_trackinghead}
2210 always
{set check_rev
{:none
}}
2212 if {$check_rev eq
{:none
}} {
2214 } elseif
{[catch
{set check_cmt
[git rev-parse
--verify "${check_rev}^0"]}]} {
2218 -title [wm title
$w] \
2220 -message "Invalid check revision: $check_rev"
2224 set to_delete
[list
]
2225 set not_merged
[list
]
2226 foreach i
[$w.list.l curselection
] {
2227 set b
[$w.list.l get
$i]
2228 if {[catch
{set o
[git rev-parse
--verify $b]}]} continue
2229 if {$check_cmt ne
{}} {
2230 if {$b eq
$check_rev} continue
2231 if {[catch
{set m
[git merge-base
$o $check_cmt]}]} continue
2233 lappend not_merged
$b
2237 lappend to_delete
[list
$b $o]
2239 if {$not_merged ne
{}} {
2240 set msg
"The following branches are not completely merged into $check_rev:
2242 - [join $not_merged "\n - "]"
2246 -title [wm title
$w] \
2250 if {$to_delete eq
{}} return
2251 if {$delete_branch_checktype eq
{always
}} {
2252 set msg
{Recovering deleted branches is difficult.
2254 Delete the selected branches?
}
2255 if {[tk_messageBox \
2258 -title [wm title
$w] \
2260 -message $msg] ne
yes} {
2266 foreach i
$to_delete {
2269 if {[catch
{git update-ref
-d "refs/heads/$b" $o} err
]} {
2270 append failed
" - $b: $err\n"
2272 set x
[lsearch
-sorted -exact $all_heads $b]
2274 set all_heads
[lreplace
$all_heads $x $x]
2279 if {$failed ne
{}} {
2283 -title [wm title
$w] \
2285 -message "Failed to delete branches:\n$failed"
2288 set all_heads
[lsort
$all_heads]
2289 populate_branch_menu
2293 proc do_delete_branch
{} {
2294 global all_heads tracking_branches current_branch
2295 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2297 set w .branch_editor
2299 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2301 label
$w.header
-text {Delete Local Branch
} \
2303 pack
$w.header
-side top
-fill x
2306 button
$w.buttons.create
-text Delete \
2308 -command [list do_delete_branch_action
$w]
2309 pack
$w.buttons.create
-side right
2310 button
$w.buttons.cancel
-text {Cancel
} \
2312 -command [list destroy
$w]
2313 pack
$w.buttons.cancel
-side right
-padx 5
2314 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2316 labelframe
$w.list \
2317 -text {Local Branches
} \
2322 -selectmode extended \
2323 -yscrollcommand [list
$w.list.sby
set] \
2325 foreach h
$all_heads {
2326 if {$h ne
$current_branch} {
2327 $w.list.l insert end
$h
2330 scrollbar
$w.list.sby
-command [list
$w.list.l yview
]
2331 pack
$w.list.sby
-side right
-fill y
2332 pack
$w.list.l
-side left
-fill both
-expand 1
2333 pack
$w.list
-fill both
-expand 1 -pady 5 -padx 5
2335 labelframe
$w.validate \
2336 -text {Delete Only If
} \
2338 radiobutton
$w.validate.head_r \
2339 -text {Merged Into Local Branch
:} \
2341 -variable delete_branch_checktype \
2343 set mergedlocalm
[eval tk_optionMenu
$w.validate.head_m \
2344 delete_branch_head \
2346 $mergedlocalm configure
-font font_ui
2347 $w.validate.head_m configure
-font font_ui
2348 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2349 set all_trackings
[all_tracking_branches
]
2350 if {$all_trackings ne
{}} {
2351 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2352 radiobutton
$w.validate.tracking_r \
2353 -text {Merged Into Tracking Branch
:} \
2355 -variable delete_branch_checktype \
2357 set mergedtrackm
[eval tk_optionMenu
$w.validate.tracking_m \
2358 delete_branch_trackinghead \
2360 $mergedtrackm configure
-font font_ui
2361 $w.validate.tracking_m configure
-font font_ui
2362 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2364 radiobutton
$w.validate.always_r \
2365 -text {Always
(Do not perform merge checks
)} \
2367 -variable delete_branch_checktype \
2369 grid
$w.validate.always_r
-columnspan 2 -sticky w
2370 grid columnconfigure
$w.validate
1 -weight 1
2371 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2373 set delete_branch_head
$current_branch
2374 set delete_branch_checktype
head
2376 bind $w <Visibility
> "grab $w; focus $w"
2377 bind $w <Key-Escape
> "destroy $w"
2378 wm title
$w "[appname] ([reponame]): Delete Branch"
2382 proc switch_branch
{new_branch
} {
2383 global HEAD commit_type current_branch repo_config
2385 if {![lock_index switch
]} return
2387 # -- Our in memory state should match the repository.
2389 repository_state curType curHEAD curMERGE_HEAD
2390 if {[string match amend
* $commit_type]
2391 && $curType eq
{normal
}
2392 && $curHEAD eq
$HEAD} {
2393 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2394 info_popup
{Last scanned state does not match repository state.
2396 Another Git program has modified this repository since the last scan. A rescan must be performed before the current branch can be changed.
2398 The rescan will be automatically started now.
2401 rescan
{set ui_status_value
{Ready.
}}
2405 # -- Don't do a pointless switch.
2407 if {$current_branch eq
$new_branch} {
2412 if {$repo_config(gui.trustmtime
) eq
{true
}} {
2413 switch_branch_stage2
{} $new_branch
2415 set ui_status_value
{Refreshing
file status...
}
2416 set cmd
[list git update-index
]
2418 lappend cmd
--unmerged
2419 lappend cmd
--ignore-missing
2420 lappend cmd
--refresh
2421 set fd_rf
[open
"| $cmd" r
]
2422 fconfigure
$fd_rf -blocking 0 -translation binary
2423 fileevent
$fd_rf readable \
2424 [list switch_branch_stage2
$fd_rf $new_branch]
2428 proc switch_branch_stage2
{fd_rf new_branch
} {
2429 global ui_status_value HEAD
2433 if {![eof
$fd_rf]} return
2437 set ui_status_value
"Updating working directory to '$new_branch'..."
2438 set cmd
[list git read-tree
]
2441 lappend cmd
--exclude-per-directory=.gitignore
2443 lappend cmd
$new_branch
2444 set fd_rt
[open
"| $cmd" r
]
2445 fconfigure
$fd_rt -blocking 0 -translation binary
2446 fileevent
$fd_rt readable \
2447 [list switch_branch_readtree_wait
$fd_rt $new_branch]
2450 proc switch_branch_readtree_wait
{fd_rt new_branch
} {
2451 global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
2452 global current_branch
2453 global ui_comm ui_status_value
2455 # -- We never get interesting output on stdout; only stderr.
2458 fconfigure
$fd_rt -blocking 1
2459 if {![eof
$fd_rt]} {
2460 fconfigure
$fd_rt -blocking 0
2464 # -- The working directory wasn't in sync with the index and
2465 # we'd have to overwrite something to make the switch. A
2466 # merge is required.
2468 if {[catch
{close
$fd_rt} err
]} {
2469 regsub
{^fatal
: } $err {} err
2470 warn_popup
"File level merge required.
2474 Staying on branch '$current_branch'."
2475 set ui_status_value
"Aborted checkout of '$new_branch' (file level merging is required)."
2480 # -- Update the symbolic ref. Core git doesn't even check for failure
2481 # here, it Just Works(tm). If it doesn't we are in some really ugly
2482 # state that is difficult to recover from within git-gui.
2484 if {[catch
{git symbolic-ref HEAD
"refs/heads/$new_branch"} err
]} {
2485 error_popup
"Failed to set current branch.
2487 This working directory is only partially switched. We successfully updated your files, but failed to update an internal Git file.
2489 This should not have occurred. [appname] will now close and give up.
2496 # -- Update our repository state. If we were previously in amend mode
2497 # we need to toss the current buffer and do a full rescan to update
2498 # our file lists. If we weren't in amend mode our file lists are
2499 # accurate and we can avoid the rescan.
2502 set selected_commit_type new
2503 if {[string match amend
* $commit_type]} {
2504 $ui_comm delete
0.0 end
2506 $ui_comm edit modified false
2507 rescan
{set ui_status_value
"Checked out branch '$current_branch'."}
2509 repository_state commit_type HEAD MERGE_HEAD
2511 set ui_status_value
"Checked out branch '$current_branch'."
2515 ######################################################################
2517 ## remote management
2519 proc load_all_remotes
{} {
2521 global all_remotes tracking_branches
2523 set all_remotes
[list
]
2524 array
unset tracking_branches
2526 set rm_dir
[gitdir remotes
]
2527 if {[file isdirectory
$rm_dir]} {
2528 set all_remotes
[glob \
2532 -directory $rm_dir *]
2534 foreach name
$all_remotes {
2536 set fd
[open
[file join $rm_dir $name] r
]
2537 while {[gets
$fd line
] >= 0} {
2538 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2539 $line line src dst
]} continue
2540 if {![regexp ^refs
/ $dst]} {
2541 set dst
"refs/heads/$dst"
2543 set tracking_branches
($dst) [list
$name $src]
2550 foreach line
[array names repo_config remote.
*.url
] {
2551 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2552 lappend all_remotes
$name
2554 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2558 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2559 if {![regexp ^refs
/ $dst]} {
2560 set dst
"refs/heads/$dst"
2562 set tracking_branches
($dst) [list
$name $src]
2566 set all_remotes
[lsort
-unique $all_remotes]
2569 proc populate_fetch_menu
{} {
2570 global all_remotes repo_config
2573 foreach r
$all_remotes {
2575 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2576 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2581 set fd
[open
[gitdir remotes
$r] r
]
2582 while {[gets
$fd n
] >= 0} {
2583 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2594 -label "Fetch from $r..." \
2595 -command [list fetch_from
$r] \
2601 proc populate_push_menu
{} {
2602 global all_remotes repo_config
2606 foreach r
$all_remotes {
2608 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2609 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2614 set fd
[open
[gitdir remotes
$r] r
]
2615 while {[gets
$fd n
] >= 0} {
2616 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2630 -label "Push to $r..." \
2631 -command [list push_to
$r] \
2638 proc start_push_anywhere_action
{w
} {
2639 global push_urltype push_remote push_url push_thin push_tags
2642 switch
-- $push_urltype {
2643 remote
{set r_url
$push_remote}
2644 url
{set r_url
$push_url}
2646 if {$r_url eq
{}} return
2648 set cmd
[list git push
]
2658 foreach i
[$w.
source.l curselection
] {
2659 set b
[$w.
source.l get
$i]
2660 lappend cmd
"refs/heads/$b:refs/heads/$b"
2665 } elseif
{$cnt == 1} {
2671 set cons
[new_console
"push $r_url" "Pushing $cnt $unit to $r_url"]
2672 console_exec
$cons $cmd console_done
2676 trace add variable push_remote
write \
2677 [list radio_selector push_urltype remote
]
2679 proc do_push_anywhere
{} {
2680 global all_heads all_remotes current_branch
2681 global push_urltype push_remote push_url push_thin push_tags
2685 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2687 label
$w.header
-text {Push Branches
} -font font_uibold
2688 pack
$w.header
-side top
-fill x
2691 button
$w.buttons.create
-text Push \
2694 -command [list start_push_anywhere_action
$w]
2695 pack
$w.buttons.create
-side right
2696 button
$w.buttons.cancel
-text {Cancel
} \
2699 -command [list destroy
$w]
2700 pack
$w.buttons.cancel
-side right
-padx 5
2701 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2703 labelframe
$w.
source \
2704 -text {Source Branches
} \
2706 listbox
$w.
source.l \
2709 -selectmode extended \
2710 -yscrollcommand [list
$w.
source.sby
set] \
2712 foreach h
$all_heads {
2713 $w.
source.l insert end
$h
2714 if {$h eq
$current_branch} {
2715 $w.
source.l
select set end
2718 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2719 pack
$w.
source.sby
-side right
-fill y
2720 pack
$w.
source.l
-side left
-fill both
-expand 1
2721 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2723 labelframe
$w.dest \
2724 -text {Destination Repository
} \
2726 if {$all_remotes ne
{}} {
2727 radiobutton
$w.dest.remote_r \
2730 -variable push_urltype \
2732 set remmenu
[eval tk_optionMenu
$w.dest.remote_m push_remote \
2734 $remmenu configure
-font font_ui
2735 $w.dest.remote_m configure
-font font_ui
2736 grid
$w.dest.remote_r
$w.dest.remote_m
-sticky w
2737 if {[lsearch
-sorted -exact $all_remotes origin
] != -1} {
2738 set push_remote origin
2740 set push_remote
[lindex
$all_remotes 0]
2742 set push_urltype remote
2744 set push_urltype url
2746 radiobutton
$w.dest.url_r \
2747 -text {Arbitrary URL
:} \
2749 -variable push_urltype \
2751 entry
$w.dest.url_t \
2755 -textvariable push_url \
2759 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2760 if {%d
== 1 && [string length
%S
] > 0} {
2761 set push_urltype url
2765 grid
$w.dest.url_r
$w.dest.url_t
-sticky we
-padx {0 5}
2766 grid columnconfigure
$w.dest
1 -weight 1
2767 pack
$w.dest
-anchor nw
-fill x
-pady 5 -padx 5
2769 labelframe
$w.options \
2770 -text {Transfer Options
} \
2772 checkbutton
$w.options.thin \
2773 -text {Use thin pack
(for slow network connections
)} \
2774 -variable push_thin \
2776 grid
$w.options.thin
-columnspan 2 -sticky w
2777 checkbutton
$w.options.tags \
2778 -text {Include tags
} \
2779 -variable push_tags \
2781 grid
$w.options.tags
-columnspan 2 -sticky w
2782 grid columnconfigure
$w.options
1 -weight 1
2783 pack
$w.options
-anchor nw
-fill x
-pady 5 -padx 5
2789 bind $w <Visibility
> "grab $w; focus $w.buttons.create"
2790 bind $w <Key-Escape
> "destroy $w"
2791 bind $w <Key-Return
> [list start_push_anywhere_action
$w]
2792 wm title
$w "[appname] ([reponame]): Push"
2796 ######################################################################
2801 global HEAD commit_type file_states
2803 if {[string match amend
* $commit_type]} {
2804 info_popup
{Cannot merge
while amending.
2806 You must finish amending this commit before starting any
type of merge.
2811 if {[committer_ident
] eq
{}} {return 0}
2812 if {![lock_index merge
]} {return 0}
2814 # -- Our in memory state should match the repository.
2816 repository_state curType curHEAD curMERGE_HEAD
2817 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2818 info_popup
{Last scanned state does not match repository state.
2820 Another Git program has modified this repository since the last scan. A rescan must be performed before a merge can be performed.
2822 The rescan will be automatically started now.
2825 rescan
{set ui_status_value
{Ready.
}}
2829 foreach path
[array names file_states
] {
2830 switch
-glob -- [lindex
$file_states($path) 0] {
2832 continue; # and pray it works!
2835 error_popup
"You are in the middle of a conflicted merge.
2837 File [short_path $path] has merge conflicts.
2839 You must resolve them, add the file, and commit to complete the current merge. Only then can you begin another merge.
2845 error_popup
"You are in the middle of a change.
2847 File [short_path $path] is modified.
2849 You should complete the current commit before starting a merge. Doing so will help you abort a failed merge, should the need arise.
2860 proc visualize_local_merge
{w
} {
2862 foreach i
[$w.
source.l curselection
] {
2863 lappend revs
[$w.
source.l get
$i]
2865 if {$revs eq
{}} return
2866 lappend revs
--not HEAD
2870 proc start_local_merge_action
{w
} {
2871 global HEAD ui_status_value current_branch
2873 set cmd
[list git merge
]
2876 foreach i
[$w.
source.l curselection
] {
2877 set b
[$w.
source.l get
$i]
2885 } elseif
{$revcnt == 1} {
2887 } elseif
{$revcnt <= 15} {
2891 $w.confirm_octopus \
2893 "Use octopus merge strategy?
2895 You are merging $revcnt branches at once. This requires using the octopus merge driver, which may not succeed if there are file-level conflicts.
2906 -title [wm title
$w] \
2908 -message "Too many branches selected.
2910 You have requested to merge $revcnt branches
2911 in an octopus merge. This exceeds Git's
2912 internal limit of 15 branches per merge.
2914 Please select fewer branches. To merge more
2915 than 15 branches, merge the branches in batches.
2920 set msg
"Merging $current_branch, [join $names {, }]"
2921 set ui_status_value
"$msg..."
2922 set cons
[new_console
"Merge" $msg]
2923 console_exec
$cons $cmd [list finish_merge
$revcnt]
2924 bind $w <Destroy
> {}
2928 proc finish_merge
{revcnt w ok
} {
2931 set msg
{Merge completed successfully.
}
2934 info_popup
"Octopus merge failed.
2936 Your merge of $revcnt branches has failed.
2938 There are file-level conflicts between the branches which must be resolved manually.
2940 The working directory will now be reset.
2942 You can attempt this merge again by merging only one branch at a time." $w
2944 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2945 fconfigure
$fd -blocking 0 -translation binary
2946 fileevent
$fd readable
[list reset_hard_wait
$fd]
2947 set ui_status_value
{Aborting... please
wait...
}
2951 set msg
{Merge failed. Conflict resolution is required.
}
2954 rescan
[list
set ui_status_value
$msg]
2957 proc do_local_merge
{} {
2958 global current_branch
2960 if {![can_merge
]} return
2964 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2967 -text "Merge Into $current_branch" \
2969 pack
$w.header
-side top
-fill x
2972 button
$w.buttons.visualize
-text Visualize \
2974 -command [list visualize_local_merge
$w]
2975 pack
$w.buttons.visualize
-side left
2976 button
$w.buttons.create
-text Merge \
2978 -command [list start_local_merge_action
$w]
2979 pack
$w.buttons.create
-side right
2980 button
$w.buttons.cancel
-text {Cancel
} \
2982 -command [list destroy
$w]
2983 pack
$w.buttons.cancel
-side right
-padx 5
2984 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2986 labelframe
$w.
source \
2987 -text {Source Branches
} \
2989 listbox
$w.
source.l \
2992 -selectmode extended \
2993 -yscrollcommand [list
$w.
source.sby
set] \
2995 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2996 pack
$w.
source.sby
-side right
-fill y
2997 pack
$w.
source.l
-side left
-fill both
-expand 1
2998 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
3000 set cmd
[list git for-each-ref
]
3001 lappend cmd
{--format=%(objectname
) %(*objectname
) %(refname
)}
3002 lappend cmd refs
/heads
3003 lappend cmd refs
/remotes
3004 lappend cmd refs
/tags
3005 set fr_fd
[open
"| $cmd" r
]
3006 fconfigure
$fr_fd -translation binary
3007 while {[gets
$fr_fd line
] > 0} {
3008 set line
[split $line { }]
3009 set sha1
([lindex
$line 0]) [lindex
$line 2]
3010 set sha1
([lindex
$line 1]) [lindex
$line 2]
3015 set fr_fd
[open
"| git rev-list --all --not HEAD"]
3016 while {[gets
$fr_fd line
] > 0} {
3017 if {[catch
{set ref
$sha1($line)}]} continue
3018 regsub ^refs
/(heads|remotes|tags
)/ $ref {} ref
3019 lappend to_show
$ref
3023 foreach ref
[lsort
-unique $to_show] {
3024 $w.
source.l insert end
$ref
3027 bind $w <Visibility
> "grab $w"
3028 bind $w <Key-Escape
> "unlock_index;destroy $w"
3029 bind $w <Destroy
> unlock_index
3030 wm title
$w "[appname] ([reponame]): Merge"
3034 proc do_reset_hard
{} {
3035 global HEAD commit_type file_states
3037 if {[string match amend
* $commit_type]} {
3038 info_popup
{Cannot abort
while amending.
3040 You must finish amending this commit.
3045 if {![lock_index abort
]} return
3047 if {[string match
*merge
* $commit_type]} {
3053 if {[ask_popup
"Abort $op?
3055 Aborting the current $op will cause *ALL* uncommitted changes to be lost.
3057 Continue with aborting the current $op?"] eq
{yes}} {
3058 set fd
[open
"| git read-tree --reset -u HEAD" r
]
3059 fconfigure
$fd -blocking 0 -translation binary
3060 fileevent
$fd readable
[list reset_hard_wait
$fd]
3061 set ui_status_value
{Aborting... please
wait...
}
3067 proc reset_hard_wait
{fd
} {
3075 $ui_comm delete
0.0 end
3076 $ui_comm edit modified false
3078 catch
{file delete
[gitdir MERGE_HEAD
]}
3079 catch
{file delete
[gitdir rr-cache MERGE_RR
]}
3080 catch
{file delete
[gitdir SQUASH_MSG
]}
3081 catch
{file delete
[gitdir MERGE_MSG
]}
3082 catch
{file delete
[gitdir GITGUI_MSG
]}
3084 rescan
{set ui_status_value
{Abort completed. Ready.
}}
3088 ######################################################################
3092 set next_browser_id
0
3094 proc new_browser
{commit
} {
3095 global next_browser_id cursor_ptr M1B
3096 global browser_commit browser_status browser_stack browser_path browser_busy
3098 if {[winfo ismapped .
]} {
3099 set w .browser
[incr next_browser_id
]
3106 set w_list
$w.list.l
3107 set browser_commit
($w_list) $commit
3108 set browser_status
($w_list) {Starting...
}
3109 set browser_stack
($w_list) {}
3110 set browser_path
($w_list) $browser_commit($w_list):
3111 set browser_busy
($w_list) 1
3113 label
$w.path
-textvariable browser_path
($w_list) \
3119 pack
$w.path
-anchor w
-side top
-fill x
3122 text
$w_list -background white
-borderwidth 0 \
3123 -cursor $cursor_ptr \
3128 -xscrollcommand [list
$w.list.sbx
set] \
3129 -yscrollcommand [list
$w.list.sby
set] \
3131 $w_list tag conf in_sel \
3132 -background [$w_list cget
-foreground] \
3133 -foreground [$w_list cget
-background]
3134 scrollbar
$w.list.sbx
-orient h
-command [list
$w_list xview
]
3135 scrollbar
$w.list.sby
-orient v
-command [list
$w_list yview
]
3136 pack
$w.list.sbx
-side bottom
-fill x
3137 pack
$w.list.sby
-side right
-fill y
3138 pack
$w_list -side left
-fill both
-expand 1
3139 pack
$w.list
-side top
-fill both
-expand 1
3141 label
$w.status
-textvariable browser_status
($w_list) \
3147 pack
$w.status
-anchor w
-side bottom
-fill x
3149 bind $w_list <Button-1
> "browser_click 0 $w_list @%x,%y;break"
3150 bind $w_list <Double-Button-1
> "browser_click 1 $w_list @%x,%y;break"
3151 bind $w_list <$M1B-Up> "browser_parent $w_list;break"
3152 bind $w_list <$M1B-Left> "browser_parent $w_list;break"
3153 bind $w_list <Up
> "browser_move -1 $w_list;break"
3154 bind $w_list <Down
> "browser_move 1 $w_list;break"
3155 bind $w_list <$M1B-Right> "browser_enter $w_list;break"
3156 bind $w_list <Return
> "browser_enter $w_list;break"
3157 bind $w_list <Prior
> "browser_page -1 $w_list;break"
3158 bind $w_list <Next
> "browser_page 1 $w_list;break"
3159 bind $w_list <Left
> break
3160 bind $w_list <Right
> break
3162 bind $tl <Visibility
> "focus $w"
3163 bind $tl <Destroy
> "
3164 array unset browser_buffer $w_list
3165 array unset browser_files $w_list
3166 array unset browser_status $w_list
3167 array unset browser_stack $w_list
3168 array unset browser_path $w_list
3169 array unset browser_commit $w_list
3170 array unset browser_busy $w_list
3172 wm title
$tl "[appname] ([reponame]): File Browser"
3173 ls_tree
$w_list $browser_commit($w_list) {}
3176 proc browser_move
{dir w
} {
3177 global browser_files browser_busy
3179 if {$browser_busy($w)} return
3180 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3182 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3183 $w tag remove in_sel
0.0 end
3184 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3189 proc browser_page
{dir w
} {
3190 global browser_files browser_busy
3192 if {$browser_busy($w)} return
3193 $w yview scroll
$dir pages
3195 [lindex
[$w yview
] 0]
3196 * [llength
$browser_files($w)]
3198 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3199 $w tag remove in_sel
0.0 end
3200 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3205 proc browser_parent
{w
} {
3206 global browser_files browser_status browser_path
3207 global browser_stack browser_busy
3209 if {$browser_busy($w)} return
3210 set info
[lindex
$browser_files($w) 0]
3211 if {[lindex
$info 0] eq
{parent
}} {
3212 set parent
[lindex
$browser_stack($w) end-1
]
3213 set browser_stack
($w) [lrange
$browser_stack($w) 0 end-2
]
3214 if {$browser_stack($w) eq
{}} {
3215 regsub
{:.
*$
} $browser_path($w) {:} browser_path
($w)
3217 regsub
{/[^
/]+$
} $browser_path($w) {} browser_path
($w)
3219 set browser_status
($w) "Loading $browser_path($w)..."
3220 ls_tree
$w [lindex
$parent 0] [lindex
$parent 1]
3224 proc browser_enter
{w
} {
3225 global browser_files browser_status browser_path
3226 global browser_commit browser_stack browser_busy
3228 if {$browser_busy($w)} return
3229 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3230 set info
[lindex
$browser_files($w) [expr {$lno - 1}]]
3232 switch
-- [lindex
$info 0] {
3237 set name
[lindex
$info 2]
3238 set escn
[escape_path
$name]
3239 set browser_status
($w) "Loading $escn..."
3240 append browser_path
($w) $escn
3241 ls_tree
$w [lindex
$info 1] $name
3244 set name
[lindex
$info 2]
3246 foreach n
$browser_stack($w) {
3247 append p
[lindex
$n 1]
3250 show_blame
$browser_commit($w) $p
3256 proc browser_click
{was_double_click w pos
} {
3257 global browser_files browser_busy
3259 if {$browser_busy($w)} return
3260 set lno
[lindex
[split [$w index
$pos] .
] 0]
3263 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3264 $w tag remove in_sel
0.0 end
3265 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3266 if {$was_double_click} {
3272 proc ls_tree
{w tree_id name
} {
3273 global browser_buffer browser_files browser_stack browser_busy
3275 set browser_buffer
($w) {}
3276 set browser_files
($w) {}
3277 set browser_busy
($w) 1
3279 $w conf
-state normal
3280 $w tag remove in_sel
0.0 end
3282 if {$browser_stack($w) ne
{}} {
3283 $w image create end \
3284 -align center
-padx 5 -pady 1 \
3287 $w insert end
{[Up To Parent
]}
3288 lappend browser_files
($w) parent
3290 lappend browser_stack
($w) [list
$tree_id $name]
3291 $w conf
-state disabled
3293 set cmd
[list git ls-tree
-z $tree_id]
3294 set fd
[open
"| $cmd" r
]
3295 fconfigure
$fd -blocking 0 -translation binary
-encoding binary
3296 fileevent
$fd readable
[list read_ls_tree
$fd $w]
3299 proc read_ls_tree
{fd w
} {
3300 global browser_buffer browser_files browser_status browser_busy
3302 if {![winfo exists
$w]} {
3307 append browser_buffer
($w) [read $fd]
3308 set pck
[split $browser_buffer($w) "\0"]
3309 set browser_buffer
($w) [lindex
$pck end
]
3311 set n
[llength
$browser_files($w)]
3312 $w conf
-state normal
3313 foreach p
[lrange
$pck 0 end-1
] {
3314 set info
[split $p "\t"]
3315 set path
[lindex
$info 1]
3316 set info
[split [lindex
$info 0] { }]
3317 set type [lindex
$info 1]
3318 set object
[lindex
$info 2]
3329 set image file_question
3333 if {$n > 0} {$w insert end
"\n"}
3334 $w image create end \
3335 -align center
-padx 5 -pady 1 \
3336 -name icon
[incr n
] \
3338 $w insert end
[escape_path
$path]
3339 lappend browser_files
($w) [list
$type $object $path]
3341 $w conf
-state disabled
3345 set browser_status
($w) Ready.
3346 set browser_busy
($w) 0
3347 array
unset browser_buffer
$w
3349 $w tag add in_sel
1.0 2.0
3355 proc show_blame
{commit path
} {
3356 global next_browser_id blame_status blame_data
3358 if {[winfo ismapped .
]} {
3359 set w .browser
[incr next_browser_id
]
3366 set blame_status
($w) {Loading current
file content...
}
3368 label
$w.path
-text "$commit:$path" \
3374 pack
$w.path
-side top
-fill x
3377 text
$w.out.loaded_t \
3378 -background white
-borderwidth 0 \
3384 $w.out.loaded_t tag conf annotated
-background grey
3386 text
$w.out.linenumber_t \
3387 -background white
-borderwidth 0 \
3393 $w.out.linenumber_t tag conf linenumber
-justify right
3395 text
$w.out.file_t \
3396 -background white
-borderwidth 0 \
3401 -xscrollcommand [list
$w.out.sbx
set] \
3404 scrollbar
$w.out.sbx
-orient h
-command [list
$w.out.file_t xview
]
3405 scrollbar
$w.out.sby
-orient v \
3406 -command [list scrollbar2many
[list \
3408 $w.out.linenumber_t \
3412 $w.out.linenumber_t \
3417 grid conf
$w.out.sbx
-column 2 -sticky we
3418 grid columnconfigure
$w.out
2 -weight 1
3419 grid rowconfigure
$w.out
0 -weight 1
3420 pack
$w.out
-fill both
-expand 1
3422 label
$w.status
-textvariable blame_status
($w) \
3428 pack
$w.status
-side bottom
-fill x
3432 -background white
-borderwidth 0 \
3437 -xscrollcommand [list
$w.cm.sbx
set] \
3438 -yscrollcommand [list
$w.cm.sby
set] \
3440 scrollbar
$w.cm.sbx
-orient h
-command [list
$w.cm.t xview
]
3441 scrollbar
$w.cm.sby
-orient v
-command [list
$w.cm.t yview
]
3442 pack
$w.cm.sby
-side right
-fill y
3443 pack
$w.cm.sbx
-side bottom
-fill x
3444 pack
$w.cm.t
-expand 1 -fill both
3445 pack
$w.cm
-side bottom
-fill x
3447 menu
$w.ctxm
-tearoff 0
3448 $w.ctxm add
command -label "Copy Commit" \
3450 -command "blame_copycommit $w \$cursorW @\$cursorX,\$cursorY"
3454 $w.out.linenumber_t \
3456 $i tag conf in_sel \
3457 -background [$i cget
-foreground] \
3458 -foreground [$i cget
-background]
3459 $i conf
-yscrollcommand \
3460 [list many2scrollbar
[list \
3462 $w.out.linenumber_t \
3465 bind $i <Button-1
> "
3468 $w.out.linenumber_t \\
3477 tk_popup $w.ctxm %X %Y
3481 bind $w.cm.t
<Button-1
> "focus $w.cm.t"
3482 bind $tl <Visibility
> "focus $tl"
3483 bind $tl <Destroy
> "
3484 array unset blame_status {$w}
3485 array unset blame_data $w,*
3487 wm title
$tl "[appname] ([reponame]): File Viewer"
3489 set blame_data
($w,commit_count
) 0
3490 set blame_data
($w,commit_list
) {}
3491 set blame_data
($w,total_lines
) 0
3492 set blame_data
($w,blame_lines
) 0
3493 set blame_data
($w,highlight_commit
) {}
3494 set blame_data
($w,highlight_line
) -1
3496 set cmd
[list git cat-file blob
"$commit:$path"]
3497 set fd
[open
"| $cmd" r
]
3498 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3499 fileevent
$fd readable
[list read_blame_catfile \
3500 $fd $w $commit $path \
3501 $w.cm.t
$w.out.loaded_t
$w.out.linenumber_t
$w.out.file_t
]
3504 proc read_blame_catfile
{fd w commit path w_cmit w_load w_line w_file
} {
3505 global blame_status blame_data
3507 if {![winfo exists
$w_file]} {
3512 set n
$blame_data($w,total_lines
)
3513 $w_load conf
-state normal
3514 $w_line conf
-state normal
3515 $w_file conf
-state normal
3516 while {[gets
$fd line
] >= 0} {
3517 regsub
"\r\$" $line {} line
3519 $w_load insert end
"\n"
3520 $w_line insert end
"$n\n" linenumber
3521 $w_file insert end
"$line\n"
3523 $w_load conf
-state disabled
3524 $w_line conf
-state disabled
3525 $w_file conf
-state disabled
3526 set blame_data
($w,total_lines
) $n
3530 blame_incremental_status
$w
3531 set cmd
[list git blame
-M -C --incremental]
3532 lappend cmd
$commit -- $path
3533 set fd
[open
"| $cmd" r
]
3534 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3535 fileevent
$fd readable
[list read_blame_incremental
$fd $w \
3536 $w_load $w_cmit $w_line $w_file]
3540 proc read_blame_incremental
{fd w w_load w_cmit w_line w_file
} {
3541 global blame_status blame_data
3543 if {![winfo exists
$w_file]} {
3548 while {[gets
$fd line
] >= 0} {
3549 if {[regexp
{^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$
} $line line \
3550 cmit original_line final_line line_count
]} {
3551 set blame_data
($w,commit
) $cmit
3552 set blame_data
($w,original_line
) $original_line
3553 set blame_data
($w,final_line
) $final_line
3554 set blame_data
($w,line_count
) $line_count
3556 if {[catch
{set g
$blame_data($w,$cmit,order
)}]} {
3557 $w_line tag conf g
$cmit
3558 $w_file tag conf g
$cmit
3559 $w_line tag raise in_sel
3560 $w_file tag raise in_sel
3561 $w_file tag raise sel
3562 set blame_data
($w,$cmit,order
) $blame_data($w,commit_count
)
3563 incr blame_data
($w,commit_count
)
3564 lappend blame_data
($w,commit_list
) $cmit
3566 } elseif
{[string match
{filename
*} $line]} {
3567 set file [string range
$line 9 end
]
3568 set n
$blame_data($w,line_count
)
3569 set lno
$blame_data($w,final_line
)
3570 set cmit
$blame_data($w,commit
)
3573 if {[catch
{set g g
$blame_data($w,line
$lno,commit
)}]} {
3574 $w_load tag add annotated
$lno.0 "$lno.0 lineend + 1c"
3576 $w_line tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3577 $w_file tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3580 set blame_data
($w,line
$lno,commit
) $cmit
3581 set blame_data
($w,line
$lno,file) $file
3582 $w_line tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3583 $w_file tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3585 if {$blame_data($w,highlight_line
) == -1} {
3586 if {[lindex
[$w_file yview
] 0] == 0} {
3588 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3590 } elseif
{$blame_data($w,highlight_line
) == $lno} {
3591 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3596 incr blame_data
($w,blame_lines
)
3599 set hc
$blame_data($w,highlight_commit
)
3601 && [expr {$blame_data($w,$hc,order
) + 1}]
3602 == $blame_data($w,$cmit,order
)} {
3603 blame_showcommit
$w $w_cmit $w_line $w_file \
3604 $blame_data($w,highlight_line
)
3606 } elseif
{[regexp
{^
([a-z-
]+) (.
*)$
} $line line header data
]} {
3607 set blame_data
($w,$blame_data($w,commit
),$header) $data
3613 set blame_status
($w) {Annotation complete.
}
3615 blame_incremental_status
$w
3619 proc blame_incremental_status
{w
} {
3620 global blame_status blame_data
3622 set have
$blame_data($w,blame_lines
)
3623 set total
$blame_data($w,total_lines
)
3625 if {$total} {set pdone
[expr {100 * $have / $total}]}
3627 set blame_status
($w) [format \
3628 "Loading annotations... %i of %i lines annotated (%2i%%)" \
3629 $have $total $pdone]
3632 proc blame_click
{w w_cmit w_line w_file cur_w pos
} {
3633 set lno
[lindex
[split [$cur_w index
$pos] .
] 0]
3634 if {$lno eq
{}} return
3636 $w_line tag remove in_sel
0.0 end
3637 $w_file tag remove in_sel
0.0 end
3638 $w_line tag add in_sel
$lno.0 "$lno.0 + 1 line"
3639 $w_file tag add in_sel
$lno.0 "$lno.0 + 1 line"
3641 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3650 proc blame_showcommit
{w w_cmit w_line w_file lno
} {
3651 global blame_colors blame_data repo_config
3653 set cmit
$blame_data($w,highlight_commit
)
3655 set idx
$blame_data($w,$cmit,order
)
3657 foreach c
$blame_colors {
3658 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3659 $w_line tag conf g
$h -background white
3660 $w_file tag conf g
$h -background white
3665 $w_cmit conf
-state normal
3666 $w_cmit delete
0.0 end
3667 if {[catch
{set cmit
$blame_data($w,line
$lno,commit
)}]} {
3669 $w_cmit insert end
"Loading annotation..."
3671 set idx
$blame_data($w,$cmit,order
)
3673 foreach c
$blame_colors {
3674 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3675 $w_line tag conf g
$h -background $c
3676 $w_file tag conf g
$h -background $c
3683 catch
{set author_name
$blame_data($w,$cmit,author
)}
3684 catch
{set author_email
$blame_data($w,$cmit,author-mail
)}
3685 catch
{set author_time
[clock format
$blame_data($w,$cmit,author-time
)]}
3687 set committer_name
{}
3688 set committer_email
{}
3689 set committer_time
{}
3690 catch
{set committer_name
$blame_data($w,$cmit,committer
)}
3691 catch
{set committer_email
$blame_data($w,$cmit,committer-mail
)}
3692 catch
{set committer_time
[clock format
$blame_data($w,$cmit,committer-time
)]}
3694 if {[catch
{set msg
$blame_data($w,$cmit,message
)}]} {
3697 set fd
[open
"| git cat-file commit $cmit" r
]
3698 fconfigure
$fd -encoding binary
-translation lf
3699 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
3702 while {[gets
$fd line
] > 0} {
3703 if {[string match
{encoding
*} $line]} {
3704 set enc
[string tolower
[string range
$line 9 end
]]
3707 set msg
[encoding convertfrom
$enc [read $fd]]
3708 set msg
[string trim
$msg]
3711 set author_name
[encoding convertfrom
$enc $author_name]
3712 set committer_name
[encoding convertfrom
$enc $committer_name]
3714 set blame_data
($w,$cmit,author
) $author_name
3715 set blame_data
($w,$cmit,committer
) $committer_name
3717 set blame_data
($w,$cmit,message
) $msg
3720 $w_cmit insert end
"commit $cmit\n"
3721 $w_cmit insert end
"Author: $author_name $author_email $author_time\n"
3722 $w_cmit insert end
"Committer: $committer_name $committer_email $committer_time\n"
3723 $w_cmit insert end
"Original File: [escape_path $blame_data($w,line$lno,file)]\n"
3724 $w_cmit insert end
"\n"
3725 $w_cmit insert end
$msg
3727 $w_cmit conf
-state disabled
3729 set blame_data
($w,highlight_line
) $lno
3730 set blame_data
($w,highlight_commit
) $cmit
3733 proc blame_copycommit
{w i pos
} {
3735 set lno
[lindex
[split [$i index
$pos] .
] 0]
3736 if {![catch
{set commit
$blame_data($w,line
$lno,commit
)}]} {
3745 ######################################################################
3750 #define mask_width 14
3751 #define mask_height 15
3752 static unsigned char mask_bits
[] = {
3753 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3754 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3755 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
3758 image create bitmap file_plain
-background white
-foreground black
-data {
3759 #define plain_width 14
3760 #define plain_height 15
3761 static unsigned char plain_bits
[] = {
3762 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3763 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
3764 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3765 } -maskdata $filemask
3767 image create bitmap file_mod
-background white
-foreground blue
-data {
3768 #define mod_width 14
3769 #define mod_height 15
3770 static unsigned char mod_bits
[] = {
3771 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3772 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3773 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3774 } -maskdata $filemask
3776 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
3777 #define file_fulltick_width 14
3778 #define file_fulltick_height 15
3779 static unsigned char file_fulltick_bits
[] = {
3780 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
3781 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
3782 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3783 } -maskdata $filemask
3785 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
3786 #define parttick_width 14
3787 #define parttick_height 15
3788 static unsigned char parttick_bits
[] = {
3789 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3790 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
3791 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3792 } -maskdata $filemask
3794 image create bitmap file_question
-background white
-foreground black
-data {
3795 #define file_question_width 14
3796 #define file_question_height 15
3797 static unsigned char file_question_bits
[] = {
3798 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
3799 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
3800 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3801 } -maskdata $filemask
3803 image create bitmap file_removed
-background white
-foreground red
-data {
3804 #define file_removed_width 14
3805 #define file_removed_height 15
3806 static unsigned char file_removed_bits
[] = {
3807 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3808 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
3809 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
3810 } -maskdata $filemask
3812 image create bitmap file_merge
-background white
-foreground blue
-data {
3813 #define file_merge_width 14
3814 #define file_merge_height 15
3815 static unsigned char file_merge_bits
[] = {
3816 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
3817 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3818 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3819 } -maskdata $filemask
3822 #define file_width 18
3823 #define file_height 18
3824 static unsigned char file_bits
[] = {
3825 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00,
3826 0x0c, 0x03, 0x00, 0x04, 0xfe, 0x00, 0x06, 0x80, 0x00, 0xff, 0x9f, 0x00,
3827 0x03, 0x98, 0x00, 0x02, 0x90, 0x00, 0x06, 0xb0, 0x00, 0x04, 0xa0, 0x00,
3828 0x0c, 0xe0, 0x00, 0x08, 0xc0, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
3829 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3831 image create bitmap file_dir
-background white
-foreground blue \
3832 -data $file_dir_data -maskdata $file_dir_data
3835 set file_uplevel_data
{
3837 #define up_height 15
3838 static unsigned char up_bits
[] = {
3839 0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f,
3840 0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
3841 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
3843 image create bitmap file_uplevel
-background white
-foreground red \
3844 -data $file_uplevel_data -maskdata $file_uplevel_data
3845 unset file_uplevel_data
3847 set ui_index .vpane.files.index.list
3848 set ui_workdir .vpane.files.workdir.list
3850 set all_icons
(_
$ui_index) file_plain
3851 set all_icons
(A
$ui_index) file_fulltick
3852 set all_icons
(M
$ui_index) file_fulltick
3853 set all_icons
(D
$ui_index) file_removed
3854 set all_icons
(U
$ui_index) file_merge
3856 set all_icons
(_
$ui_workdir) file_plain
3857 set all_icons
(M
$ui_workdir) file_mod
3858 set all_icons
(D
$ui_workdir) file_question
3859 set all_icons
(U
$ui_workdir) file_merge
3860 set all_icons
(O
$ui_workdir) file_plain
3862 set max_status_desc
0
3866 {_M
"Modified, not staged"}
3867 {M_
"Staged for commit"}
3868 {MM
"Portions staged for commit"}
3869 {MD
"Staged for commit, missing"}
3871 {_O
"Untracked, not staged"}
3872 {A_
"Staged for commit"}
3873 {AM
"Portions staged for commit"}
3874 {AD
"Staged for commit, missing"}
3877 {D_
"Staged for removal"}
3878 {DO
"Staged for removal, still present"}
3880 {U_
"Requires merge resolution"}
3881 {UU
"Requires merge resolution"}
3882 {UM
"Requires merge resolution"}
3883 {UD
"Requires merge resolution"}
3885 if {$max_status_desc < [string length
[lindex
$i 1]]} {
3886 set max_status_desc
[string length
[lindex
$i 1]]
3888 set all_descs
([lindex
$i 0]) [lindex
$i 1]
3892 ######################################################################
3896 proc bind_button3
{w cmd
} {
3897 bind $w <Any-Button-3
> $cmd
3899 bind $w <Control-Button-1
> $cmd
3903 proc scrollbar2many
{list mode args
} {
3904 foreach w
$list {eval $w $mode $args}
3907 proc many2scrollbar
{list mode sb top bottom
} {
3908 $sb set $top $bottom
3909 foreach w
$list {$w $mode moveto
$top}
3912 proc incr_font_size
{font
{amt
1}} {
3913 set sz
[font configure
$font -size]
3915 font configure
$font -size $sz
3916 font configure
${font}bold
-size $sz
3919 proc hook_failed_popup
{hook msg
} {
3924 label
$w.m.l1
-text "$hook hook failed:" \
3929 -background white
-borderwidth 1 \
3931 -width 80 -height 10 \
3933 -yscrollcommand [list
$w.m.sby
set]
3935 -text {You must correct the above errors before committing.
} \
3939 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3940 pack
$w.m.l1
-side top
-fill x
3941 pack
$w.m.l2
-side bottom
-fill x
3942 pack
$w.m.sby
-side right
-fill y
3943 pack
$w.m.t
-side left
-fill both
-expand 1
3944 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3946 $w.m.t insert
1.0 $msg
3947 $w.m.t conf
-state disabled
3949 button
$w.ok
-text OK \
3952 -command "destroy $w"
3953 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3955 bind $w <Visibility
> "grab $w; focus $w"
3956 bind $w <Key-Return
> "destroy $w"
3957 wm title
$w "[appname] ([reponame]): error"
3961 set next_console_id
0
3963 proc new_console
{short_title long_title
} {
3964 global next_console_id console_data
3965 set w .console
[incr next_console_id
]
3966 set console_data
($w) [list
$short_title $long_title]
3967 return [console_init
$w]
3970 proc console_init
{w
} {
3971 global console_cr console_data M1B
3973 set console_cr
($w) 1.0
3976 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
3981 -background white
-borderwidth 1 \
3983 -width 80 -height 10 \
3986 -yscrollcommand [list
$w.m.sby
set]
3987 label
$w.m.s
-text {Working... please
wait...
} \
3991 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3992 pack
$w.m.l1
-side top
-fill x
3993 pack
$w.m.s
-side bottom
-fill x
3994 pack
$w.m.sby
-side right
-fill y
3995 pack
$w.m.t
-side left
-fill both
-expand 1
3996 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3998 menu
$w.ctxm
-tearoff 0
3999 $w.ctxm add
command -label "Copy" \
4001 -command "tk_textCopy $w.m.t"
4002 $w.ctxm add
command -label "Select All" \
4004 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
4005 $w.ctxm add
command -label "Copy All" \
4008 $w.m.t tag add sel 0.0 end
4010 $w.m.t tag remove sel 0.0 end
4013 button
$w.ok
-text {Close
} \
4016 -command "destroy $w"
4017 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
4019 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
4020 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
4021 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
4022 bind $w <Visibility
> "focus $w"
4023 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
4027 proc console_exec
{w cmd after
} {
4028 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
4029 # But most users need that so we have to relogin. :-(
4032 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
4035 # -- Tcl won't let us redirect both stdout and stderr to
4036 # the same pipe. So pass it through cat...
4038 set cmd
[concat |
$cmd |
& cat]
4040 set fd_f
[open
$cmd r
]
4041 fconfigure
$fd_f -blocking 0 -translation binary
4042 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
4045 proc console_read
{w fd after
} {
4050 if {![winfo exists
$w]} {console_init
$w}
4051 $w.m.t conf
-state normal
4053 set n
[string length
$buf]
4055 set cr
[string first
"\r" $buf $c]
4056 set lf
[string first
"\n" $buf $c]
4057 if {$cr < 0} {set cr
[expr {$n + 1}]}
4058 if {$lf < 0} {set lf
[expr {$n + 1}]}
4061 $w.m.t insert end
[string range
$buf $c $lf]
4062 set console_cr
($w) [$w.m.t index
{end
-1c}]
4066 $w.m.t delete
$console_cr($w) end
4067 $w.m.t insert end
"\n"
4068 $w.m.t insert end
[string range
$buf $c $cr]
4073 $w.m.t conf
-state disabled
4077 fconfigure
$fd -blocking 1
4079 if {[catch
{close
$fd}]} {
4084 uplevel
#0 $after $w $ok
4087 fconfigure
$fd -blocking 0
4090 proc console_chain
{cmdlist w
{ok
1}} {
4092 if {[llength
$cmdlist] == 0} {
4097 set cmd
[lindex
$cmdlist 0]
4098 set cmdlist
[lrange
$cmdlist 1 end
]
4100 if {[lindex
$cmd 0] eq
{console_exec
}} {
4103 [list console_chain
$cmdlist]
4105 uplevel
#0 $cmd $cmdlist $w $ok
4112 proc console_done
{args
} {
4113 global console_cr console_data
4115 switch
-- [llength
$args] {
4117 set w
[lindex
$args 0]
4118 set ok
[lindex
$args 1]
4121 set w
[lindex
$args 1]
4122 set ok
[lindex
$args 2]
4125 error
"wrong number of args: console_done ?ignored? w ok"
4130 if {[winfo exists
$w]} {
4131 $w.m.s conf
-background green
-text {Success
}
4132 $w.ok conf
-state normal
4136 if {![winfo exists
$w]} {
4139 $w.m.s conf
-background red
-text {Error
: Command Failed
}
4140 $w.ok conf
-state normal
4144 array
unset console_cr
$w
4145 array
unset console_data
$w
4148 ######################################################################
4152 set starting_gitk_msg
{Starting gitk... please
wait...
}
4154 proc do_gitk
{revs
} {
4155 global env ui_status_value starting_gitk_msg
4157 # -- Always start gitk through whatever we were loaded with. This
4158 # lets us bypass using shell process on Windows systems.
4160 set cmd
[list
[info nameofexecutable
]]
4161 lappend cmd
[gitexec gitk
]
4167 if {[catch
{eval exec $cmd &} err
]} {
4168 error_popup
"Failed to start gitk:\n\n$err"
4170 set ui_status_value
$starting_gitk_msg
4172 if {$ui_status_value eq
$starting_gitk_msg} {
4173 set ui_status_value
{Ready.
}
4180 set fd
[open
"| git count-objects -v" r
]
4181 while {[gets
$fd line
] > 0} {
4182 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
4183 set stats
($name) $value
4189 foreach p
[glob
-directory [gitdir objects pack
] \
4192 incr packed_sz
[file size
$p]
4194 if {$packed_sz > 0} {
4195 set stats
(size-pack
) [expr {$packed_sz / 1024}]
4200 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4202 label
$w.header
-text {Database Statistics
} \
4204 pack
$w.header
-side top
-fill x
4206 frame
$w.buttons
-border 1
4207 button
$w.buttons.close
-text Close \
4210 -command [list destroy
$w]
4211 button
$w.buttons.gc
-text {Compress Database
} \
4214 -command "destroy $w;do_gc"
4215 pack
$w.buttons.close
-side right
4216 pack
$w.buttons.gc
-side left
4217 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4219 frame
$w.stat
-borderwidth 1 -relief solid
4221 {count
{Number of loose objects
}}
4222 {size
{Disk space used by loose objects
} { KiB
}}
4223 {in-pack
{Number of packed objects
}}
4224 {packs
{Number of packs
}}
4225 {size-pack
{Disk space used by packed objects
} { KiB
}}
4226 {prune-packable
{Packed objects waiting
for pruning
}}
4227 {garbage
{Garbage files
}}
4229 set name
[lindex
$s 0]
4230 set label
[lindex
$s 1]
4231 if {[catch
{set value
$stats($name)}]} continue
4232 if {[llength
$s] > 2} {
4233 set value
"$value[lindex $s 2]"
4236 label
$w.stat.l_
$name -text "$label:" -anchor w
-font font_ui
4237 label
$w.stat.v_
$name -text $value -anchor w
-font font_ui
4238 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
4240 pack
$w.stat
-pady 10 -padx 10
4242 bind $w <Visibility
> "grab $w; focus $w.buttons.close"
4243 bind $w <Key-Escape
> [list destroy
$w]
4244 bind $w <Key-Return
> [list destroy
$w]
4245 wm title
$w "[appname] ([reponame]): Database Statistics"
4250 set w
[new_console
{gc
} {Compressing the object database
}]
4252 {console_exec
{git pack-refs
--prune}}
4253 {console_exec
{git reflog expire
--all}}
4254 {console_exec
{git repack
-a -d -l}}
4255 {console_exec
{git rerere gc
}}
4259 proc do_fsck_objects
{} {
4260 set w
[new_console
{fsck-objects
} \
4261 {Verifying the object database with fsck-objects
}]
4262 set cmd
[list git fsck-objects
]
4265 lappend cmd
--strict
4266 console_exec
$w $cmd console_done
4272 global ui_comm is_quitting repo_config commit_type
4274 if {$is_quitting} return
4277 if {[winfo exists
$ui_comm]} {
4278 # -- Stash our current commit buffer.
4280 set save
[gitdir GITGUI_MSG
]
4281 set msg
[string trim
[$ui_comm get
0.0 end
]]
4282 regsub
-all -line {[ \r\t]+$
} $msg {} msg
4283 if {(![string match amend
* $commit_type]
4284 ||
[$ui_comm edit modified
])
4287 set fd
[open
$save w
]
4288 puts
-nonewline $fd $msg
4292 catch
{file delete
$save}
4295 # -- Stash our current window geometry into this repository.
4297 set cfg_geometry
[list
]
4298 lappend cfg_geometry
[wm geometry .
]
4299 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
4300 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
4301 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
4304 if {$cfg_geometry ne
$rc_geometry} {
4305 catch
{git config gui.geometry
$cfg_geometry}
4313 rescan
{set ui_status_value
{Ready.
}}
4316 proc unstage_helper
{txt paths
} {
4317 global file_states current_diff_path
4319 if {![lock_index begin-update
]} return
4323 foreach path
$paths {
4324 switch
-glob -- [lindex
$file_states($path) 0] {
4328 lappend pathList
$path
4329 if {$path eq
$current_diff_path} {
4330 set after
{reshow_diff
;}
4335 if {$pathList eq
{}} {
4341 [concat
$after {set ui_status_value
{Ready.
}}]
4345 proc do_unstage_selection
{} {
4346 global current_diff_path selected_paths
4348 if {[array size selected_paths
] > 0} {
4350 {Unstaging selected files from commit
} \
4351 [array names selected_paths
]
4352 } elseif
{$current_diff_path ne
{}} {
4354 "Unstaging [short_path $current_diff_path] from commit" \
4355 [list
$current_diff_path]
4359 proc add_helper
{txt paths
} {
4360 global file_states current_diff_path
4362 if {![lock_index begin-update
]} return
4366 foreach path
$paths {
4367 switch
-glob -- [lindex
$file_states($path) 0] {
4372 lappend pathList
$path
4373 if {$path eq
$current_diff_path} {
4374 set after
{reshow_diff
;}
4379 if {$pathList eq
{}} {
4385 [concat
$after {set ui_status_value
{Ready to commit.
}}]
4389 proc do_add_selection
{} {
4390 global current_diff_path selected_paths
4392 if {[array size selected_paths
] > 0} {
4394 {Adding selected files
} \
4395 [array names selected_paths
]
4396 } elseif
{$current_diff_path ne
{}} {
4398 "Adding [short_path $current_diff_path]" \
4399 [list
$current_diff_path]
4403 proc do_add_all
{} {
4407 foreach path
[array names file_states
] {
4408 switch
-glob -- [lindex
$file_states($path) 0] {
4411 ?D
{lappend paths
$path}
4414 add_helper
{Adding all changed files
} $paths
4417 proc revert_helper
{txt paths
} {
4418 global file_states current_diff_path
4420 if {![lock_index begin-update
]} return
4424 foreach path
$paths {
4425 switch
-glob -- [lindex
$file_states($path) 0] {
4429 lappend pathList
$path
4430 if {$path eq
$current_diff_path} {
4431 set after
{reshow_diff
;}
4437 set n
[llength
$pathList]
4441 } elseif
{$n == 1} {
4442 set s
"[short_path [lindex $pathList]]"
4444 set s
"these $n files"
4447 set reply
[tk_dialog \
4449 "[appname] ([reponame])" \
4450 "Revert changes in $s?
4452 Any unadded changes will be permanently lost by the revert." \
4462 [concat
$after {set ui_status_value
{Ready.
}}]
4468 proc do_revert_selection
{} {
4469 global current_diff_path selected_paths
4471 if {[array size selected_paths
] > 0} {
4473 {Reverting selected files
} \
4474 [array names selected_paths
]
4475 } elseif
{$current_diff_path ne
{}} {
4477 "Reverting [short_path $current_diff_path]" \
4478 [list
$current_diff_path]
4482 proc do_signoff
{} {
4485 set me
[committer_ident
]
4486 if {$me eq
{}} return
4488 set sob
"Signed-off-by: $me"
4489 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
4490 if {$last ne
$sob} {
4491 $ui_comm edit separator
4493 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
4494 $ui_comm insert end
"\n"
4496 $ui_comm insert end
"\n$sob"
4497 $ui_comm edit separator
4502 proc do_select_commit_type
{} {
4503 global commit_type selected_commit_type
4505 if {$selected_commit_type eq
{new
}
4506 && [string match amend
* $commit_type]} {
4508 } elseif
{$selected_commit_type eq
{amend
}
4509 && ![string match amend
* $commit_type]} {
4512 # The amend request was rejected...
4514 if {![string match amend
* $commit_type]} {
4515 set selected_commit_type new
4525 global appvers copyright
4526 global tcl_patchLevel tk_patchLevel
4530 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4532 label
$w.header
-text "About [appname]" \
4534 pack
$w.header
-side top
-fill x
4537 button
$w.buttons.close
-text {Close
} \
4540 -command [list destroy
$w]
4541 pack
$w.buttons.close
-side right
4542 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4545 -text "git-gui - a graphical user interface for Git.
4553 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
4556 append v
"git-gui version $appvers\n"
4557 append v
"[git version]\n"
4559 if {$tcl_patchLevel eq
$tk_patchLevel} {
4560 append v
"Tcl/Tk version $tcl_patchLevel"
4562 append v
"Tcl version $tcl_patchLevel"
4563 append v
", Tk version $tk_patchLevel"
4574 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
4576 menu
$w.ctxm
-tearoff 0
4577 $w.ctxm add
command \
4582 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
4585 bind $w <Visibility
> "grab $w; focus $w.buttons.close"
4586 bind $w <Key-Escape
> "destroy $w"
4587 bind $w <Key-Return
> "destroy $w"
4588 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
4589 wm title
$w "About [appname]"
4593 proc do_options
{} {
4594 global repo_config global_config font_descs
4595 global repo_config_new global_config_new
4597 array
unset repo_config_new
4598 array
unset global_config_new
4599 foreach name
[array names repo_config
] {
4600 set repo_config_new
($name) $repo_config($name)
4603 foreach name
[array names repo_config
] {
4605 gui.diffcontext
{continue}
4607 set repo_config_new
($name) $repo_config($name)
4609 foreach name
[array names global_config
] {
4610 set global_config_new
($name) $global_config($name)
4613 set w .options_editor
4615 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4617 label
$w.header
-text "Options" \
4619 pack
$w.header
-side top
-fill x
4622 button
$w.buttons.restore
-text {Restore Defaults
} \
4625 -command do_restore_defaults
4626 pack
$w.buttons.restore
-side left
4627 button
$w.buttons.save
-text Save \
4630 -command [list do_save_config
$w]
4631 pack
$w.buttons.save
-side right
4632 button
$w.buttons.cancel
-text {Cancel
} \
4635 -command [list destroy
$w]
4636 pack
$w.buttons.cancel
-side right
-padx 5
4637 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4639 labelframe
$w.repo
-text "[reponame] Repository" \
4641 labelframe
$w.global
-text {Global
(All Repositories
)} \
4643 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
4644 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
4648 {t user.name
{User Name
}}
4649 {t user.email
{Email Address
}}
4651 {b merge.summary
{Summarize Merge Commits
}}
4652 {i-1.
.5 merge.verbosity
{Merge Verbosity
}}
4654 {b gui.trustmtime
{Trust File Modification Timestamps
}}
4655 {i-1.
.99 gui.diffcontext
{Number of Diff Context Lines
}}
4656 {t gui.newbranchtemplate
{New Branch Name Template
}}
4658 set type [lindex
$option 0]
4659 set name
[lindex
$option 1]
4660 set text
[lindex
$option 2]
4662 foreach f
{repo global
} {
4663 switch
-glob -- $type {
4665 checkbutton
$w.
$f.
$optid -text $text \
4666 -variable ${f}_config_new
($name) \
4670 pack
$w.
$f.
$optid -side top
-anchor w
4673 regexp
-- {-(\d
+)\.\.
(\d
+)$
} $type _junk min max
4675 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4676 pack
$w.
$f.
$optid.l
-side left
-anchor w
-fill x
4677 spinbox
$w.
$f.
$optid.v \
4678 -textvariable ${f}_config_new
($name) \
4682 -width [expr {1 + [string length
$max]}] \
4684 bind $w.
$f.
$optid.v
<FocusIn
> {%W selection range
0 end
}
4685 pack
$w.
$f.
$optid.v
-side right
-anchor e
-padx 5
4686 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4690 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4691 entry
$w.
$f.
$optid.v \
4695 -textvariable ${f}_config_new
($name) \
4697 pack
$w.
$f.
$optid.l
-side left
-anchor w
4698 pack
$w.
$f.
$optid.v
-side left
-anchor w \
4701 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4707 set all_fonts
[lsort
[font families
]]
4708 foreach option
$font_descs {
4709 set name
[lindex
$option 0]
4710 set font
[lindex
$option 1]
4711 set text
[lindex
$option 2]
4713 set global_config_new
(gui.
$font^^family
) \
4714 [font configure
$font -family]
4715 set global_config_new
(gui.
$font^^size
) \
4716 [font configure
$font -size]
4718 frame
$w.global.
$name
4719 label
$w.global.
$name.l
-text "$text:" -font font_ui
4720 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
4721 set fontmenu
[eval tk_optionMenu
$w.global.
$name.family \
4722 global_config_new
(gui.
$font^^family
) \
4724 $w.global.
$name.family configure
-font font_ui
4725 $fontmenu configure
-font font_ui
4726 spinbox
$w.global.
$name.size \
4727 -textvariable global_config_new
(gui.
$font^^size
) \
4728 -from 2 -to 80 -increment 1 \
4731 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
4732 pack
$w.global.
$name.size
-side right
-anchor e
4733 pack
$w.global.
$name.family
-side right
-anchor e
4734 pack
$w.global.
$name -side top
-anchor w
-fill x
4737 bind $w <Visibility
> "grab $w; focus $w.buttons.save"
4738 bind $w <Key-Escape
> "destroy $w"
4739 bind $w <Key-Return
> [list do_save_config
$w]
4740 wm title
$w "[appname] ([reponame]): Options"
4744 proc do_restore_defaults
{} {
4745 global font_descs default_config repo_config
4746 global repo_config_new global_config_new
4748 foreach name
[array names default_config
] {
4749 set repo_config_new
($name) $default_config($name)
4750 set global_config_new
($name) $default_config($name)
4753 foreach option
$font_descs {
4754 set name
[lindex
$option 0]
4755 set repo_config
(gui.
$name) $default_config(gui.
$name)
4759 foreach option
$font_descs {
4760 set name
[lindex
$option 0]
4761 set font
[lindex
$option 1]
4762 set global_config_new
(gui.
$font^^family
) \
4763 [font configure
$font -family]
4764 set global_config_new
(gui.
$font^^size
) \
4765 [font configure
$font -size]
4769 proc do_save_config
{w
} {
4770 if {[catch
{save_config
} err
]} {
4771 error_popup
"Failed to completely save options:\n\n$err"
4777 proc do_windows_shortcut
{} {
4780 set fn
[tk_getSaveFile \
4782 -title "[appname] ([reponame]): Create Desktop Icon" \
4783 -initialfile "Git [reponame].bat"]
4787 puts
$fd "@ECHO Entering [reponame]"
4788 puts
$fd "@ECHO Starting git-gui... please wait..."
4789 puts
$fd "@SET PATH=[file normalize [gitexec]];%PATH%"
4790 puts
$fd "@SET GIT_DIR=[file normalize [gitdir]]"
4791 puts
-nonewline $fd "@\"[info nameofexecutable]\""
4792 puts
$fd " \"[file normalize $argv0]\""
4795 error_popup
"Cannot write script:\n\n$err"
4800 proc do_cygwin_shortcut
{} {
4804 set desktop
[exec cygpath \
4812 set fn
[tk_getSaveFile \
4814 -title "[appname] ([reponame]): Create Desktop Icon" \
4815 -initialdir $desktop \
4816 -initialfile "Git [reponame].bat"]
4820 set sh
[exec cygpath \
4824 set me
[exec cygpath \
4828 set gd
[exec cygpath \
4832 set gw
[exec cygpath \
4835 [file dirname [gitdir
]]]
4836 regsub
-all ' $me "'\\''" me
4837 regsub -all ' $gd "'\\''" gd
4838 puts $fd "@ECHO Entering $gw"
4839 puts $fd "@ECHO Starting git-gui... please wait..."
4840 puts -nonewline $fd "@\"$sh\" --login -c \""
4841 puts -nonewline $fd "GIT_DIR='$gd'"
4842 puts -nonewline $fd " '$me'"
4846 error_popup "Cannot write script:\n\n$err"
4851 proc do_macosx_app {} {
4854 set fn [tk_getSaveFile \
4856 -title "[appname] ([reponame]): Create Desktop Icon" \
4857 -initialdir [file join $env(HOME) Desktop] \
4858 -initialfile "Git [reponame].app"]
4861 set Contents [file join $fn Contents]
4862 set MacOS [file join $Contents MacOS]
4863 set exe [file join $MacOS git-gui]
4867 set fd [open [file join $Contents Info.plist] w]
4868 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
4869 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4870 <plist version="1.0">
4872 <key>CFBundleDevelopmentRegion</key>
4873 <string>English</string>
4874 <key>CFBundleExecutable</key>
4875 <string>git-gui</string>
4876 <key>CFBundleIdentifier</key>
4877 <string>org.spearce.git-gui</string>
4878 <key>CFBundleInfoDictionaryVersion</key>
4879 <string>6.0</string>
4880 <key>CFBundlePackageType</key>
4881 <string>APPL</string>
4882 <key>CFBundleSignature</key>
4883 <string>????</string>
4884 <key>CFBundleVersion</key>
4885 <string>1.0</string>
4886 <key>NSPrincipalClass</key>
4887 <string>NSApplication</string>
4892 set fd [open $exe w]
4893 set gd [file normalize [gitdir]]
4894 set ep [file normalize [gitexec]]
4895 regsub -all ' $gd "'\\''" gd
4896 regsub
-all ' $ep "'\\''" ep
4897 puts $fd "#!/bin/sh"
4898 foreach name
[array names env
] {
4899 if {[string match GIT_
* $name]} {
4900 regsub
-all ' $env($name) "'\\''" v
4901 puts $fd "export $name='$v'"
4904 puts $fd "export PATH
='$ep':\
$PATH"
4905 puts $fd "export GIT_DIR
='$gd'"
4906 puts $fd "exec [file normalize
$argv0]"
4909 file attributes $exe -permissions u+x,g+x,o+x
4911 error_popup "Cannot
write icon
:\n\n$err"
4916 proc toggle_or_diff {w x y} {
4917 global file_states file_lists current_diff_path ui_index ui_workdir
4918 global last_clicked selected_paths
4920 set pos [split [$w index @$x,$y] .]
4921 set lno [lindex $pos 0]
4922 set col [lindex $pos 1]
4923 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4929 set last_clicked [list $w $lno]
4930 array unset selected_paths
4931 $ui_index tag remove in_sel 0.0 end
4932 $ui_workdir tag remove in_sel 0.0 end
4935 if {$current_diff_path eq $path} {
4936 set after {reshow_diff;}
4940 if {$w eq $ui_index} {
4942 "Unstaging
[short_path
$path] from commit
" \
4944 [concat $after {set ui_status_value {Ready.}}]
4945 } elseif {$w eq $ui_workdir} {
4947 "Adding
[short_path
$path]" \
4949 [concat $after {set ui_status_value {Ready.}}]
4952 show_diff $path $w $lno
4956 proc add_one_to_selection {w x y} {
4957 global file_lists last_clicked selected_paths
4959 set lno [lindex [split [$w index @$x,$y] .] 0]
4960 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4966 if {$last_clicked ne {}
4967 && [lindex $last_clicked 0] ne $w} {
4968 array unset selected_paths
4969 [lindex $last_clicked 0] tag remove in_sel 0.0 end
4972 set last_clicked [list $w $lno]
4973 if {[catch {set in_sel $selected_paths($path)}]} {
4977 unset selected_paths($path)
4978 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
4980 set selected_paths($path) 1
4981 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
4985 proc add_range_to_selection {w x y} {
4986 global file_lists last_clicked selected_paths
4988 if {[lindex $last_clicked 0] ne $w} {
4989 toggle_or_diff $w $x $y
4993 set lno [lindex [split [$w index @$x,$y] .] 0]
4994 set lc [lindex $last_clicked 1]
5003 foreach path [lrange $file_lists($w) \
5004 [expr {$begin - 1}] \
5005 [expr {$end - 1}]] {
5006 set selected_paths($path) 1
5008 $w tag add in_sel $begin.0 [expr {$end + 1}].0
5011 ######################################################################
5015 set cursor_ptr arrow
5016 font create font_diff -family Courier -size 10
5020 eval font configure font_ui [font actual [.dummy cget -font]]
5024 font create font_uibold
5025 font create font_diffbold
5030 } elseif {[is_MacOSX]} {
5038 proc apply_config {} {
5039 global repo_config font_descs
5041 foreach option $font_descs {
5042 set name [lindex $option 0]
5043 set font [lindex $option 1]
5045 foreach {cn cv} $repo_config(gui.$name) {
5046 font configure $font $cn $cv
5049 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
5051 foreach {cn cv} [font configure $font] {
5052 font configure ${font}bold $cn $cv
5054 font configure ${font}bold -weight bold
5058 set default_config(merge.summary) false
5059 set default_config(merge.verbosity) 2
5060 set default_config(user.name) {}
5061 set default_config(user.email) {}
5063 set default_config(gui.trustmtime) false
5064 set default_config(gui.diffcontext) 5
5065 set default_config(gui.newbranchtemplate) {}
5066 set default_config(gui.fontui) [font configure font_ui]
5067 set default_config(gui.fontdiff) [font configure font_diff]
5069 {fontui font_ui {Main Font}}
5070 {fontdiff font_diff {Diff/Console Font}}
5075 ######################################################################
5077 ## feature option selection
5079 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
5084 if {$subcommand eq {gui.sh}} {
5087 if {$subcommand eq {gui} && [llength $argv] > 0} {
5088 set subcommand [lindex $argv 0]
5089 set argv [lrange $argv 1 end]
5092 enable_option multicommit
5093 enable_option branch
5094 enable_option transport
5096 switch -- $subcommand {
5099 disable_option multicommit
5100 disable_option branch
5101 disable_option transport
5104 enable_option singlecommit
5106 disable_option multicommit
5107 disable_option branch
5108 disable_option transport
5112 ######################################################################
5120 menu .mbar -tearoff 0
5121 .mbar add cascade -label Repository -menu .mbar.repository -font font_ui
5122 .mbar add cascade -label Edit -menu .mbar.edit -font font_ui
5123 if {[is_enabled branch]} {
5124 .mbar add cascade -label Branch -menu .mbar.branch -font font_ui
5126 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
5127 .mbar add cascade -label Commit -menu .mbar.commit -font font_ui
5129 if {[is_enabled transport]} {
5130 .mbar add cascade -label Merge -menu .mbar.merge -font font_ui
5131 .mbar add cascade -label Fetch -menu .mbar.fetch -font font_ui
5132 .mbar add cascade -label Push -menu .mbar.push -font font_ui
5134 . configure -menu .mbar
5136 # -- Repository Menu
5138 menu .mbar.repository
5140 .mbar.repository add command \
5141 -label {Browse Current Branch} \
5142 -command {new_browser $current_branch} \
5144 trace add variable current_branch write ".mbar.repository entryconf
[.mbar.repository index last
] -label \"Browse \
$current_branch\" ;#"
5145 .mbar.repository add separator
5147 .mbar.repository add
command \
5148 -label {Visualize Current Branch
} \
5149 -command {do_gitk
$current_branch} \
5151 trace add variable current_branch
write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#"
5152 .mbar.repository add
command \
5153 -label {Visualize All Branches
} \
5154 -command {do_gitk
--all} \
5156 .mbar.repository add separator
5158 if {[is_enabled multicommit
]} {
5159 .mbar.repository add
command -label {Database Statistics
} \
5163 .mbar.repository add
command -label {Compress Database
} \
5167 .mbar.repository add
command -label {Verify Database
} \
5168 -command do_fsck_objects \
5171 .mbar.repository add separator
5174 .mbar.repository add
command \
5175 -label {Create Desktop Icon
} \
5176 -command do_cygwin_shortcut \
5178 } elseif
{[is_Windows
]} {
5179 .mbar.repository add
command \
5180 -label {Create Desktop Icon
} \
5181 -command do_windows_shortcut \
5183 } elseif
{[is_MacOSX
]} {
5184 .mbar.repository add
command \
5185 -label {Create Desktop Icon
} \
5186 -command do_macosx_app \
5191 .mbar.repository add
command -label Quit \
5193 -accelerator $M1T-Q \
5199 .mbar.edit add
command -label Undo \
5200 -command {catch
{[focus
] edit undo
}} \
5201 -accelerator $M1T-Z \
5203 .mbar.edit add
command -label Redo \
5204 -command {catch
{[focus
] edit redo
}} \
5205 -accelerator $M1T-Y \
5207 .mbar.edit add separator
5208 .mbar.edit add
command -label Cut \
5209 -command {catch
{tk_textCut
[focus
]}} \
5210 -accelerator $M1T-X \
5212 .mbar.edit add
command -label Copy \
5213 -command {catch
{tk_textCopy
[focus
]}} \
5214 -accelerator $M1T-C \
5216 .mbar.edit add
command -label Paste \
5217 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
5218 -accelerator $M1T-V \
5220 .mbar.edit add
command -label Delete \
5221 -command {catch
{[focus
] delete sel.first sel.last
}} \
5224 .mbar.edit add separator
5225 .mbar.edit add
command -label {Select All
} \
5226 -command {catch
{[focus
] tag add sel
0.0 end
}} \
5227 -accelerator $M1T-A \
5232 if {[is_enabled branch
]} {
5235 .mbar.branch add
command -label {Create...
} \
5236 -command do_create_branch \
5237 -accelerator $M1T-N \
5239 lappend disable_on_lock
[list .mbar.branch entryconf \
5240 [.mbar.branch index last
] -state]
5242 .mbar.branch add
command -label {Delete...
} \
5243 -command do_delete_branch \
5245 lappend disable_on_lock
[list .mbar.branch entryconf \
5246 [.mbar.branch index last
] -state]
5248 .mbar.branch add
command -label {Reset...
} \
5249 -command do_reset_hard \
5251 lappend disable_on_lock
[list .mbar.branch entryconf \
5252 [.mbar.branch index last
] -state]
5257 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
5260 .mbar.commit add radiobutton \
5261 -label {New Commit
} \
5262 -command do_select_commit_type \
5263 -variable selected_commit_type \
5266 lappend disable_on_lock \
5267 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5269 .mbar.commit add radiobutton \
5270 -label {Amend Last Commit
} \
5271 -command do_select_commit_type \
5272 -variable selected_commit_type \
5275 lappend disable_on_lock \
5276 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5278 .mbar.commit add separator
5280 .mbar.commit add
command -label Rescan \
5281 -command do_rescan \
5284 lappend disable_on_lock \
5285 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5287 .mbar.commit add
command -label {Add To Commit
} \
5288 -command do_add_selection \
5290 lappend disable_on_lock \
5291 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5293 .mbar.commit add
command -label {Add Existing To Commit
} \
5294 -command do_add_all \
5295 -accelerator $M1T-I \
5297 lappend disable_on_lock \
5298 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5300 .mbar.commit add
command -label {Unstage From Commit
} \
5301 -command do_unstage_selection \
5303 lappend disable_on_lock \
5304 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5306 .mbar.commit add
command -label {Revert Changes
} \
5307 -command do_revert_selection \
5309 lappend disable_on_lock \
5310 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5312 .mbar.commit add separator
5314 .mbar.commit add
command -label {Sign Off
} \
5315 -command do_signoff \
5316 -accelerator $M1T-S \
5319 .mbar.commit add
command -label Commit \
5320 -command do_commit \
5321 -accelerator $M1T-Return \
5323 lappend disable_on_lock \
5324 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5329 if {[is_enabled branch
]} {
5331 .mbar.merge add
command -label {Local Merge...
} \
5332 -command do_local_merge \
5334 lappend disable_on_lock \
5335 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5336 .mbar.merge add
command -label {Abort Merge...
} \
5337 -command do_reset_hard \
5339 lappend disable_on_lock \
5340 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5346 if {[is_enabled transport
]} {
5350 .mbar.push add
command -label {Push...
} \
5351 -command do_push_anywhere \
5356 # -- Apple Menu (Mac OS X only)
5358 .mbar add cascade
-label Apple
-menu .mbar.apple
5361 .mbar.apple add
command -label "About [appname]" \
5364 .mbar.apple add
command -label "Options..." \
5365 -command do_options \
5370 .mbar.edit add separator
5371 .mbar.edit add
command -label {Options...
} \
5372 -command do_options \
5377 if {[file exists
/usr
/local
/miga
/lib
/gui-miga
]
5378 && [file exists .pvcsrc
]} {
5380 global ui_status_value
5381 if {![lock_index update
]} return
5382 set cmd
[list sh
--login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
5383 set miga_fd
[open
"|$cmd" r
]
5384 fconfigure
$miga_fd -blocking 0
5385 fileevent
$miga_fd readable
[list miga_done
$miga_fd]
5386 set ui_status_value
{Running miga...
}
5388 proc miga_done
{fd
} {
5393 rescan
[list
set ui_status_value
{Ready.
}]
5396 .mbar add cascade
-label Tools
-menu .mbar.tools
5398 .mbar.tools add
command -label "Migrate" \
5401 lappend disable_on_lock \
5402 [list .mbar.tools entryconf
[.mbar.tools index last
] -state]
5408 .mbar add cascade
-label Help
-menu .mbar.
help -font font_ui
5412 .mbar.
help add
command -label "About [appname]" \
5418 catch
{set browser
$repo_config(instaweb.browser
)}
5419 set doc_path
[file dirname [gitexec
]]
5420 set doc_path
[file join $doc_path Documentation index.html
]
5423 set doc_path
[exec cygpath
--mixed $doc_path]
5426 if {$browser eq
{}} {
5429 } elseif
{[is_Cygwin
]} {
5430 set program_files
[file dirname [exec cygpath
--windir]]
5431 set program_files
[file join $program_files {Program Files
}]
5432 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
5433 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
5434 if {[file exists
$firefox]} {
5435 set browser
$firefox
5436 } elseif
{[file exists
$ie]} {
5439 unset program_files firefox ie
5443 if {[file isfile
$doc_path]} {
5444 set doc_url
"file:$doc_path"
5446 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
5449 if {$browser ne
{}} {
5450 .mbar.
help add
command -label {Online Documentation
} \
5451 -command [list
exec $browser $doc_url &] \
5454 unset browser doc_path doc_url
5456 # -- Standard bindings
5458 bind .
<Destroy
> do_quit
5459 bind all
<$M1B-Key-q> do_quit
5460 bind all
<$M1B-Key-Q> do_quit
5461 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
5462 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
5464 # -- Not a normal commit type invocation? Do that instead!
5466 switch
-- $subcommand {
5468 if {[llength
$argv] != 1} {
5469 puts stderr
"usage: $argv0 browser commit"
5472 set current_branch
[lindex
$argv 0]
5473 new_browser
$current_branch
5477 if {[llength
$argv] != 2} {
5478 puts stderr
"usage: $argv0 blame commit path"
5481 set current_branch
[lindex
$argv 0]
5482 show_blame
$current_branch [lindex
$argv 1]
5487 if {[llength
$argv] != 0} {
5488 puts
-nonewline stderr
"usage: $argv0"
5489 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
5490 puts
-nonewline stderr
" $subcommand"
5495 # fall through to setup UI for commits
5498 puts stderr
"usage: $argv0 \[{blame|browser|citool}\]"
5509 -text {Current Branch
:} \
5514 -textvariable current_branch \
5518 pack .branch.l1
-side left
5519 pack .branch.cb
-side left
-fill x
5520 pack .branch
-side top
-fill x
5522 # -- Main Window Layout
5524 panedwindow .vpane
-orient vertical
5525 panedwindow .vpane.files
-orient horizontal
5526 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
5527 pack .vpane
-anchor n
-side top
-fill both
-expand 1
5529 # -- Index File List
5531 frame .vpane.files.index
-height 100 -width 200
5532 label .vpane.files.index.title
-text {Changes To Be Committed
} \
5535 text
$ui_index -background white
-borderwidth 0 \
5536 -width 20 -height 10 \
5539 -cursor $cursor_ptr \
5540 -xscrollcommand {.vpane.files.index.sx
set} \
5541 -yscrollcommand {.vpane.files.index.sy
set} \
5543 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
5544 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
5545 pack .vpane.files.index.title
-side top
-fill x
5546 pack .vpane.files.index.sx
-side bottom
-fill x
5547 pack .vpane.files.index.sy
-side right
-fill y
5548 pack
$ui_index -side left
-fill both
-expand 1
5549 .vpane.files add .vpane.files.index
-sticky nsew
5551 # -- Working Directory File List
5553 frame .vpane.files.workdir
-height 100 -width 200
5554 label .vpane.files.workdir.title
-text {Changed But Not Updated
} \
5557 text
$ui_workdir -background white
-borderwidth 0 \
5558 -width 20 -height 10 \
5561 -cursor $cursor_ptr \
5562 -xscrollcommand {.vpane.files.workdir.sx
set} \
5563 -yscrollcommand {.vpane.files.workdir.sy
set} \
5565 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
5566 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
5567 pack .vpane.files.workdir.title
-side top
-fill x
5568 pack .vpane.files.workdir.sx
-side bottom
-fill x
5569 pack .vpane.files.workdir.sy
-side right
-fill y
5570 pack
$ui_workdir -side left
-fill both
-expand 1
5571 .vpane.files add .vpane.files.workdir
-sticky nsew
5573 foreach i
[list
$ui_index $ui_workdir] {
5574 $i tag conf in_diff
-font font_uibold
5575 $i tag conf in_sel \
5576 -background [$i cget
-foreground] \
5577 -foreground [$i cget
-background]
5581 # -- Diff and Commit Area
5583 frame .vpane.lower
-height 300 -width 400
5584 frame .vpane.lower.commarea
5585 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
5586 pack .vpane.lower.commarea
-side top
-fill x
5587 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
5588 .vpane add .vpane.lower
-sticky nsew
5590 # -- Commit Area Buttons
5592 frame .vpane.lower.commarea.buttons
5593 label .vpane.lower.commarea.buttons.l
-text {} \
5597 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
5598 pack .vpane.lower.commarea.buttons
-side left
-fill y
5600 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
5601 -command do_rescan \
5603 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
5604 lappend disable_on_lock \
5605 {.vpane.lower.commarea.buttons.rescan conf
-state}
5607 button .vpane.lower.commarea.buttons.incall
-text {Add Existing
} \
5608 -command do_add_all \
5610 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
5611 lappend disable_on_lock \
5612 {.vpane.lower.commarea.buttons.incall conf
-state}
5614 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
5615 -command do_signoff \
5617 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
5619 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
5620 -command do_commit \
5622 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
5623 lappend disable_on_lock \
5624 {.vpane.lower.commarea.buttons.commit conf
-state}
5626 # -- Commit Message Buffer
5628 frame .vpane.lower.commarea.buffer
5629 frame .vpane.lower.commarea.buffer.header
5630 set ui_comm .vpane.lower.commarea.buffer.t
5631 set ui_coml .vpane.lower.commarea.buffer.header.l
5632 radiobutton .vpane.lower.commarea.buffer.header.new \
5633 -text {New Commit
} \
5634 -command do_select_commit_type \
5635 -variable selected_commit_type \
5638 lappend disable_on_lock \
5639 [list .vpane.lower.commarea.buffer.header.new conf
-state]
5640 radiobutton .vpane.lower.commarea.buffer.header.amend \
5641 -text {Amend Last Commit
} \
5642 -command do_select_commit_type \
5643 -variable selected_commit_type \
5646 lappend disable_on_lock \
5647 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
5652 proc trace_commit_type
{varname args
} {
5653 global ui_coml commit_type
5654 switch
-glob -- $commit_type {
5655 initial
{set txt
{Initial Commit Message
:}}
5656 amend
{set txt
{Amended Commit Message
:}}
5657 amend-initial
{set txt
{Amended Initial Commit Message
:}}
5658 amend-merge
{set txt
{Amended Merge Commit Message
:}}
5659 merge
{set txt
{Merge Commit Message
:}}
5660 * {set txt
{Commit Message
:}}
5662 $ui_coml conf
-text $txt
5664 trace add variable commit_type
write trace_commit_type
5665 pack
$ui_coml -side left
-fill x
5666 pack .vpane.lower.commarea.buffer.header.amend
-side right
5667 pack .vpane.lower.commarea.buffer.header.new
-side right
5669 text
$ui_comm -background white
-borderwidth 1 \
5672 -autoseparators true \
5674 -width 75 -height 9 -wrap none \
5676 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
5677 scrollbar .vpane.lower.commarea.buffer.sby \
5678 -command [list
$ui_comm yview
]
5679 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
5680 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
5681 pack
$ui_comm -side left
-fill y
5682 pack .vpane.lower.commarea.buffer
-side left
-fill y
5684 # -- Commit Message Buffer Context Menu
5686 set ctxm .vpane.lower.commarea.buffer.ctxm
5687 menu
$ctxm -tearoff 0
5691 -command {tk_textCut
$ui_comm}
5695 -command {tk_textCopy
$ui_comm}
5699 -command {tk_textPaste
$ui_comm}
5703 -command {$ui_comm delete sel.first sel.last
}
5706 -label {Select All
} \
5708 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
5713 $ui_comm tag add sel
0.0 end
5714 tk_textCopy
$ui_comm
5715 $ui_comm tag remove sel
0.0 end
5722 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
5726 proc trace_current_diff_path
{varname args
} {
5727 global current_diff_path diff_actions file_states
5728 if {$current_diff_path eq
{}} {
5734 set p
$current_diff_path
5735 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
5737 set p
[escape_path
$p]
5741 .vpane.lower.
diff.header.status configure
-text $s
5742 .vpane.lower.
diff.header.
file configure
-text $f
5743 .vpane.lower.
diff.header.path configure
-text $p
5744 foreach w
$diff_actions {
5748 trace add variable current_diff_path
write trace_current_diff_path
5750 frame .vpane.lower.
diff.header
-background orange
5751 label .vpane.lower.
diff.header.status \
5752 -background orange \
5753 -width $max_status_desc \
5757 label .vpane.lower.
diff.header.
file \
5758 -background orange \
5762 label .vpane.lower.
diff.header.path \
5763 -background orange \
5767 pack .vpane.lower.
diff.header.status
-side left
5768 pack .vpane.lower.
diff.header.
file -side left
5769 pack .vpane.lower.
diff.header.path
-fill x
5770 set ctxm .vpane.lower.
diff.header.ctxm
5771 menu
$ctxm -tearoff 0
5780 -- $current_diff_path
5782 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5783 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
5787 frame .vpane.lower.
diff.body
5788 set ui_diff .vpane.lower.
diff.body.t
5789 text
$ui_diff -background white
-borderwidth 0 \
5790 -width 80 -height 15 -wrap none \
5792 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
5793 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
5795 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
5796 -command [list
$ui_diff xview
]
5797 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
5798 -command [list
$ui_diff yview
]
5799 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
5800 pack .vpane.lower.
diff.body.sby
-side right
-fill y
5801 pack
$ui_diff -side left
-fill both
-expand 1
5802 pack .vpane.lower.
diff.header
-side top
-fill x
5803 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
5805 $ui_diff tag conf d_cr
-elide true
5806 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
5807 $ui_diff tag conf d_
+ -foreground {#00a000}
5808 $ui_diff tag conf d_-
-foreground red
5810 $ui_diff tag conf d_
++ -foreground {#00a000}
5811 $ui_diff tag conf d_--
-foreground red
5812 $ui_diff tag conf d_
+s \
5813 -foreground {#00a000} \
5814 -background {#e2effa}
5815 $ui_diff tag conf d_-s \
5817 -background {#e2effa}
5818 $ui_diff tag conf d_s
+ \
5819 -foreground {#00a000} \
5821 $ui_diff tag conf d_s- \
5825 $ui_diff tag conf d
<<<<<<< \
5826 -foreground orange \
5828 $ui_diff tag conf d
======= \
5829 -foreground orange \
5831 $ui_diff tag conf d
>>>>>>> \
5832 -foreground orange \
5835 $ui_diff tag raise sel
5837 # -- Diff Body Context Menu
5839 set ctxm .vpane.lower.
diff.body.ctxm
5840 menu
$ctxm -tearoff 0
5844 -command reshow_diff
5845 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5849 -command {tk_textCopy
$ui_diff}
5850 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5852 -label {Select All
} \
5854 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
5855 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5860 $ui_diff tag add sel
0.0 end
5861 tk_textCopy
$ui_diff
5862 $ui_diff tag remove sel
0.0 end
5864 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5867 -label {Apply
/Reverse Hunk
} \
5869 -command {apply_hunk
$cursorX $cursorY}
5870 set ui_diff_applyhunk
[$ctxm index last
]
5871 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
5874 -label {Decrease Font Size
} \
5876 -command {incr_font_size font_diff
-1}
5877 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5879 -label {Increase Font Size
} \
5881 -command {incr_font_size font_diff
1}
5882 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5885 -label {Show Less Context
} \
5887 -command {if {$repo_config(gui.diffcontext
) >= 2} {
5888 incr repo_config
(gui.diffcontext
) -1
5891 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5893 -label {Show More Context
} \
5896 incr repo_config
(gui.diffcontext
)
5899 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5901 $ctxm add
command -label {Options...
} \
5904 bind_button3
$ui_diff "
5907 if {\$ui_index eq \$current_diff_side} {
5908 $ctxm entryconf $ui_diff_applyhunk -label {Unstage Hunk From Commit}
5910 $ctxm entryconf $ui_diff_applyhunk -label {Stage Hunk For Commit}
5912 tk_popup $ctxm %X %Y
5914 unset ui_diff_applyhunk
5918 label .status
-textvariable ui_status_value \
5924 pack .status
-anchor w
-side bottom
-fill x
5929 set gm
$repo_config(gui.geometry
)
5930 wm geometry .
[lindex
$gm 0]
5931 .vpane sash place
0 \
5932 [lindex
[.vpane sash coord
0] 0] \
5934 .vpane.files sash place
0 \
5936 [lindex
[.vpane.files sash coord
0] 1]
5942 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
5943 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
5944 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
5945 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
5946 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
5947 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
5948 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
5949 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
5950 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
5951 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5952 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5954 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
5955 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
5956 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
5957 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
5958 bind $ui_diff <$M1B-Key-v> {break}
5959 bind $ui_diff <$M1B-Key-V> {break}
5960 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5961 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5962 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
5963 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
5964 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
5965 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
5966 bind $ui_diff <Button-1
> {focus
%W
}
5968 if {[is_enabled branch
]} {
5969 bind .
<$M1B-Key-n> do_create_branch
5970 bind .
<$M1B-Key-N> do_create_branch
5973 bind all
<Key-F5
> do_rescan
5974 bind all
<$M1B-Key-r> do_rescan
5975 bind all
<$M1B-Key-R> do_rescan
5976 bind .
<$M1B-Key-s> do_signoff
5977 bind .
<$M1B-Key-S> do_signoff
5978 bind .
<$M1B-Key-i> do_add_all
5979 bind .
<$M1B-Key-I> do_add_all
5980 bind .
<$M1B-Key-Return> do_commit
5981 foreach i
[list
$ui_index $ui_workdir] {
5982 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
5983 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
5984 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
5988 set file_lists
($ui_index) [list
]
5989 set file_lists
($ui_workdir) [list
]
5991 wm title .
"[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"
5992 focus
-force $ui_comm
5994 # -- Warn the user about environmental problems. Cygwin's Tcl
5995 # does *not* pass its env array onto any processes it spawns.
5996 # This means that git processes get none of our environment.
6001 set msg
"Possible environment issues exist.
6003 The following environment variables are probably
6004 going to be ignored by any Git subprocess run
6008 foreach name
[array names env
] {
6009 switch
-regexp -- $name {
6010 {^GIT_INDEX_FILE$
} -
6011 {^GIT_OBJECT_DIRECTORY$
} -
6012 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
6014 {^GIT_EXTERNAL_DIFF$
} -
6018 {^GIT_CONFIG_LOCAL$
} -
6019 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
6020 append msg
" - $name\n"
6023 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
6024 append msg
" - $name\n"
6026 set suggest_user
$name
6030 if {$ignored_env > 0} {
6032 This is due to a known issue with the
6033 Tcl binary distributed by Cygwin."
6035 if {$suggest_user ne
{}} {
6038 A good replacement for $suggest_user
6039 is placing values for the user.name and
6040 user.email settings into your personal
6046 unset ignored_env msg suggest_user name
6049 # -- Only initialize complex UI if we are going to stay running.
6051 if {[is_enabled transport
]} {
6055 populate_branch_menu
6060 # -- Only suggest a gc run if we are going to stay running.
6062 if {[is_enabled multicommit
]} {
6063 set object_limit
2000
6064 if {[is_Windows
]} {set object_limit
200}
6065 regexp
{^
([0-9]+) objects
,} [git count-objects
] _junk objects_current
6066 if {$objects_current >= $object_limit} {
6068 "This repository currently has $objects_current loose objects.
6070 To maintain optimal performance it is strongly recommended that you compress the database when more than $object_limit loose objects exist.
6072 Compress the database now?"] eq
yes} {
6076 unset object_limit _junk objects_current
6079 lock_index begin-read