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} {
2893 -title [wm title
$w] \
2895 -message "Too many branches selected.
2897 You have requested to merge $revcnt branches
2898 in an octopus merge. This exceeds Git's
2899 internal limit of 15 branches per merge.
2901 Please select fewer branches. To merge more
2902 than 15 branches, merge the branches in batches.
2907 set msg
"Merging $current_branch, [join $names {, }]"
2908 set ui_status_value
"$msg..."
2909 set cons
[new_console
"Merge" $msg]
2910 console_exec
$cons $cmd [list finish_merge
$revcnt]
2911 bind $w <Destroy
> {}
2915 proc finish_merge
{revcnt w ok
} {
2918 set msg
{Merge completed successfully.
}
2921 info_popup
"Octopus merge failed.
2923 Your merge of $revcnt branches has failed.
2925 There are file-level conflicts between the branches which must be resolved manually.
2927 The working directory will now be reset.
2929 You can attempt this merge again by merging only one branch at a time." $w
2931 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2932 fconfigure
$fd -blocking 0 -translation binary
2933 fileevent
$fd readable
[list reset_hard_wait
$fd]
2934 set ui_status_value
{Aborting... please
wait...
}
2938 set msg
{Merge failed. Conflict resolution is required.
}
2941 rescan
[list
set ui_status_value
$msg]
2944 proc do_local_merge
{} {
2945 global current_branch
2947 if {![can_merge
]} return
2951 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2954 -text "Merge Into $current_branch" \
2956 pack
$w.header
-side top
-fill x
2959 button
$w.buttons.visualize
-text Visualize \
2961 -command [list visualize_local_merge
$w]
2962 pack
$w.buttons.visualize
-side left
2963 button
$w.buttons.create
-text Merge \
2965 -command [list start_local_merge_action
$w]
2966 pack
$w.buttons.create
-side right
2967 button
$w.buttons.cancel
-text {Cancel
} \
2969 -command [list destroy
$w]
2970 pack
$w.buttons.cancel
-side right
-padx 5
2971 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2973 labelframe
$w.
source \
2974 -text {Source Branches
} \
2976 listbox
$w.
source.l \
2979 -selectmode extended \
2980 -yscrollcommand [list
$w.
source.sby
set] \
2982 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2983 pack
$w.
source.sby
-side right
-fill y
2984 pack
$w.
source.l
-side left
-fill both
-expand 1
2985 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2987 set cmd
[list git for-each-ref
]
2988 lappend cmd
{--format=%(objectname
) %(*objectname
) %(refname
)}
2989 lappend cmd refs
/heads
2990 lappend cmd refs
/remotes
2991 lappend cmd refs
/tags
2992 set fr_fd
[open
"| $cmd" r
]
2993 fconfigure
$fr_fd -translation binary
2994 while {[gets
$fr_fd line
] > 0} {
2995 set line
[split $line { }]
2996 set sha1
([lindex
$line 0]) [lindex
$line 2]
2997 set sha1
([lindex
$line 1]) [lindex
$line 2]
3002 set fr_fd
[open
"| git rev-list --all --not HEAD"]
3003 while {[gets
$fr_fd line
] > 0} {
3004 if {[catch
{set ref
$sha1($line)}]} continue
3005 regsub ^refs
/(heads|remotes|tags
)/ $ref {} ref
3006 lappend to_show
$ref
3010 foreach ref
[lsort
-unique $to_show] {
3011 $w.
source.l insert end
$ref
3014 bind $w <Visibility
> "grab $w"
3015 bind $w <Key-Escape
> "unlock_index;destroy $w"
3016 bind $w <Destroy
> unlock_index
3017 wm title
$w "[appname] ([reponame]): Merge"
3021 proc do_reset_hard
{} {
3022 global HEAD commit_type file_states
3024 if {[string match amend
* $commit_type]} {
3025 info_popup
{Cannot abort
while amending.
3027 You must finish amending this commit.
3032 if {![lock_index abort
]} return
3034 if {[string match
*merge
* $commit_type]} {
3040 if {[ask_popup
"Abort $op?
3042 Aborting the current $op will cause *ALL* uncommitted changes to be lost.
3044 Continue with aborting the current $op?"] eq
{yes}} {
3045 set fd
[open
"| git read-tree --reset -u HEAD" r
]
3046 fconfigure
$fd -blocking 0 -translation binary
3047 fileevent
$fd readable
[list reset_hard_wait
$fd]
3048 set ui_status_value
{Aborting... please
wait...
}
3054 proc reset_hard_wait
{fd
} {
3062 $ui_comm delete
0.0 end
3063 $ui_comm edit modified false
3065 catch
{file delete
[gitdir MERGE_HEAD
]}
3066 catch
{file delete
[gitdir rr-cache MERGE_RR
]}
3067 catch
{file delete
[gitdir SQUASH_MSG
]}
3068 catch
{file delete
[gitdir MERGE_MSG
]}
3069 catch
{file delete
[gitdir GITGUI_MSG
]}
3071 rescan
{set ui_status_value
{Abort completed. Ready.
}}
3075 ######################################################################
3079 set next_browser_id
0
3081 proc new_browser
{commit
} {
3082 global next_browser_id cursor_ptr M1B
3083 global browser_commit browser_status browser_stack browser_path browser_busy
3085 if {[winfo ismapped .
]} {
3086 set w .browser
[incr next_browser_id
]
3093 set w_list
$w.list.l
3094 set browser_commit
($w_list) $commit
3095 set browser_status
($w_list) {Starting...
}
3096 set browser_stack
($w_list) {}
3097 set browser_path
($w_list) $browser_commit($w_list):
3098 set browser_busy
($w_list) 1
3100 label
$w.path
-textvariable browser_path
($w_list) \
3106 pack
$w.path
-anchor w
-side top
-fill x
3109 text
$w_list -background white
-borderwidth 0 \
3110 -cursor $cursor_ptr \
3115 -xscrollcommand [list
$w.list.sbx
set] \
3116 -yscrollcommand [list
$w.list.sby
set] \
3118 $w_list tag conf in_sel \
3119 -background [$w_list cget
-foreground] \
3120 -foreground [$w_list cget
-background]
3121 scrollbar
$w.list.sbx
-orient h
-command [list
$w_list xview
]
3122 scrollbar
$w.list.sby
-orient v
-command [list
$w_list yview
]
3123 pack
$w.list.sbx
-side bottom
-fill x
3124 pack
$w.list.sby
-side right
-fill y
3125 pack
$w_list -side left
-fill both
-expand 1
3126 pack
$w.list
-side top
-fill both
-expand 1
3128 label
$w.status
-textvariable browser_status
($w_list) \
3134 pack
$w.status
-anchor w
-side bottom
-fill x
3136 bind $w_list <Button-1
> "browser_click 0 $w_list @%x,%y;break"
3137 bind $w_list <Double-Button-1
> "browser_click 1 $w_list @%x,%y;break"
3138 bind $w_list <$M1B-Up> "browser_parent $w_list;break"
3139 bind $w_list <$M1B-Left> "browser_parent $w_list;break"
3140 bind $w_list <Up
> "browser_move -1 $w_list;break"
3141 bind $w_list <Down
> "browser_move 1 $w_list;break"
3142 bind $w_list <$M1B-Right> "browser_enter $w_list;break"
3143 bind $w_list <Return
> "browser_enter $w_list;break"
3144 bind $w_list <Prior
> "browser_page -1 $w_list;break"
3145 bind $w_list <Next
> "browser_page 1 $w_list;break"
3146 bind $w_list <Left
> break
3147 bind $w_list <Right
> break
3149 bind $tl <Visibility
> "focus $w"
3150 bind $tl <Destroy
> "
3151 array unset browser_buffer $w_list
3152 array unset browser_files $w_list
3153 array unset browser_status $w_list
3154 array unset browser_stack $w_list
3155 array unset browser_path $w_list
3156 array unset browser_commit $w_list
3157 array unset browser_busy $w_list
3159 wm title
$tl "[appname] ([reponame]): File Browser"
3160 ls_tree
$w_list $browser_commit($w_list) {}
3163 proc browser_move
{dir w
} {
3164 global browser_files browser_busy
3166 if {$browser_busy($w)} return
3167 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3169 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3170 $w tag remove in_sel
0.0 end
3171 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3176 proc browser_page
{dir w
} {
3177 global browser_files browser_busy
3179 if {$browser_busy($w)} return
3180 $w yview scroll
$dir pages
3182 [lindex
[$w yview
] 0]
3183 * [llength
$browser_files($w)]
3185 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3186 $w tag remove in_sel
0.0 end
3187 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3192 proc browser_parent
{w
} {
3193 global browser_files browser_status browser_path
3194 global browser_stack browser_busy
3196 if {$browser_busy($w)} return
3197 set info
[lindex
$browser_files($w) 0]
3198 if {[lindex
$info 0] eq
{parent
}} {
3199 set parent
[lindex
$browser_stack($w) end-1
]
3200 set browser_stack
($w) [lrange
$browser_stack($w) 0 end-2
]
3201 if {$browser_stack($w) eq
{}} {
3202 regsub
{:.
*$
} $browser_path($w) {:} browser_path
($w)
3204 regsub
{/[^
/]+$
} $browser_path($w) {} browser_path
($w)
3206 set browser_status
($w) "Loading $browser_path($w)..."
3207 ls_tree
$w [lindex
$parent 0] [lindex
$parent 1]
3211 proc browser_enter
{w
} {
3212 global browser_files browser_status browser_path
3213 global browser_commit browser_stack browser_busy
3215 if {$browser_busy($w)} return
3216 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3217 set info
[lindex
$browser_files($w) [expr {$lno - 1}]]
3219 switch
-- [lindex
$info 0] {
3224 set name
[lindex
$info 2]
3225 set escn
[escape_path
$name]
3226 set browser_status
($w) "Loading $escn..."
3227 append browser_path
($w) $escn
3228 ls_tree
$w [lindex
$info 1] $name
3231 set name
[lindex
$info 2]
3233 foreach n
$browser_stack($w) {
3234 append p
[lindex
$n 1]
3237 show_blame
$browser_commit($w) $p
3243 proc browser_click
{was_double_click w pos
} {
3244 global browser_files browser_busy
3246 if {$browser_busy($w)} return
3247 set lno
[lindex
[split [$w index
$pos] .
] 0]
3250 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3251 $w tag remove in_sel
0.0 end
3252 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3253 if {$was_double_click} {
3259 proc ls_tree
{w tree_id name
} {
3260 global browser_buffer browser_files browser_stack browser_busy
3262 set browser_buffer
($w) {}
3263 set browser_files
($w) {}
3264 set browser_busy
($w) 1
3266 $w conf
-state normal
3267 $w tag remove in_sel
0.0 end
3269 if {$browser_stack($w) ne
{}} {
3270 $w image create end \
3271 -align center
-padx 5 -pady 1 \
3274 $w insert end
{[Up To Parent
]}
3275 lappend browser_files
($w) parent
3277 lappend browser_stack
($w) [list
$tree_id $name]
3278 $w conf
-state disabled
3280 set cmd
[list git ls-tree
-z $tree_id]
3281 set fd
[open
"| $cmd" r
]
3282 fconfigure
$fd -blocking 0 -translation binary
-encoding binary
3283 fileevent
$fd readable
[list read_ls_tree
$fd $w]
3286 proc read_ls_tree
{fd w
} {
3287 global browser_buffer browser_files browser_status browser_busy
3289 if {![winfo exists
$w]} {
3294 append browser_buffer
($w) [read $fd]
3295 set pck
[split $browser_buffer($w) "\0"]
3296 set browser_buffer
($w) [lindex
$pck end
]
3298 set n
[llength
$browser_files($w)]
3299 $w conf
-state normal
3300 foreach p
[lrange
$pck 0 end-1
] {
3301 set info
[split $p "\t"]
3302 set path
[lindex
$info 1]
3303 set info
[split [lindex
$info 0] { }]
3304 set type [lindex
$info 1]
3305 set object
[lindex
$info 2]
3316 set image file_question
3320 if {$n > 0} {$w insert end
"\n"}
3321 $w image create end \
3322 -align center
-padx 5 -pady 1 \
3323 -name icon
[incr n
] \
3325 $w insert end
[escape_path
$path]
3326 lappend browser_files
($w) [list
$type $object $path]
3328 $w conf
-state disabled
3332 set browser_status
($w) Ready.
3333 set browser_busy
($w) 0
3334 array
unset browser_buffer
$w
3336 $w tag add in_sel
1.0 2.0
3342 proc show_blame
{commit path
} {
3343 global next_browser_id blame_status blame_data
3345 if {[winfo ismapped .
]} {
3346 set w .browser
[incr next_browser_id
]
3353 set blame_status
($w) {Loading current
file content...
}
3355 label
$w.path
-text "$commit:$path" \
3361 pack
$w.path
-side top
-fill x
3364 text
$w.out.loaded_t \
3365 -background white
-borderwidth 0 \
3371 $w.out.loaded_t tag conf annotated
-background grey
3373 text
$w.out.linenumber_t \
3374 -background white
-borderwidth 0 \
3380 $w.out.linenumber_t tag conf linenumber
-justify right
3382 text
$w.out.file_t \
3383 -background white
-borderwidth 0 \
3388 -xscrollcommand [list
$w.out.sbx
set] \
3391 scrollbar
$w.out.sbx
-orient h
-command [list
$w.out.file_t xview
]
3392 scrollbar
$w.out.sby
-orient v \
3393 -command [list scrollbar2many
[list \
3395 $w.out.linenumber_t \
3399 $w.out.linenumber_t \
3404 grid conf
$w.out.sbx
-column 2 -sticky we
3405 grid columnconfigure
$w.out
2 -weight 1
3406 grid rowconfigure
$w.out
0 -weight 1
3407 pack
$w.out
-fill both
-expand 1
3409 label
$w.status
-textvariable blame_status
($w) \
3415 pack
$w.status
-side bottom
-fill x
3419 -background white
-borderwidth 0 \
3424 -xscrollcommand [list
$w.cm.sbx
set] \
3425 -yscrollcommand [list
$w.cm.sby
set] \
3427 scrollbar
$w.cm.sbx
-orient h
-command [list
$w.cm.t xview
]
3428 scrollbar
$w.cm.sby
-orient v
-command [list
$w.cm.t yview
]
3429 pack
$w.cm.sby
-side right
-fill y
3430 pack
$w.cm.sbx
-side bottom
-fill x
3431 pack
$w.cm.t
-expand 1 -fill both
3432 pack
$w.cm
-side bottom
-fill x
3434 menu
$w.ctxm
-tearoff 0
3435 $w.ctxm add
command -label "Copy Commit" \
3437 -command "blame_copycommit $w \$cursorW @\$cursorX,\$cursorY"
3441 $w.out.linenumber_t \
3443 $i tag conf in_sel \
3444 -background [$i cget
-foreground] \
3445 -foreground [$i cget
-background]
3446 $i conf
-yscrollcommand \
3447 [list many2scrollbar
[list \
3449 $w.out.linenumber_t \
3452 bind $i <Button-1
> "
3455 $w.out.linenumber_t \\
3464 tk_popup $w.ctxm %X %Y
3468 bind $w.cm.t
<Button-1
> "focus $w.cm.t"
3469 bind $tl <Visibility
> "focus $tl"
3470 bind $tl <Destroy
> "
3471 array unset blame_status {$w}
3472 array unset blame_data $w,*
3474 wm title
$tl "[appname] ([reponame]): File Viewer"
3476 set blame_data
($w,commit_count
) 0
3477 set blame_data
($w,commit_list
) {}
3478 set blame_data
($w,total_lines
) 0
3479 set blame_data
($w,blame_lines
) 0
3480 set blame_data
($w,highlight_commit
) {}
3481 set blame_data
($w,highlight_line
) -1
3483 set cmd
[list git cat-file blob
"$commit:$path"]
3484 set fd
[open
"| $cmd" r
]
3485 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3486 fileevent
$fd readable
[list read_blame_catfile \
3487 $fd $w $commit $path \
3488 $w.cm.t
$w.out.loaded_t
$w.out.linenumber_t
$w.out.file_t
]
3491 proc read_blame_catfile
{fd w commit path w_cmit w_load w_line w_file
} {
3492 global blame_status blame_data
3494 if {![winfo exists
$w_file]} {
3499 set n
$blame_data($w,total_lines
)
3500 $w_load conf
-state normal
3501 $w_line conf
-state normal
3502 $w_file conf
-state normal
3503 while {[gets
$fd line
] >= 0} {
3504 regsub
"\r\$" $line {} line
3506 $w_load insert end
"\n"
3507 $w_line insert end
"$n\n" linenumber
3508 $w_file insert end
"$line\n"
3510 $w_load conf
-state disabled
3511 $w_line conf
-state disabled
3512 $w_file conf
-state disabled
3513 set blame_data
($w,total_lines
) $n
3517 blame_incremental_status
$w
3518 set cmd
[list git blame
-M -C --incremental]
3519 lappend cmd
$commit -- $path
3520 set fd
[open
"| $cmd" r
]
3521 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3522 fileevent
$fd readable
[list read_blame_incremental
$fd $w \
3523 $w_load $w_cmit $w_line $w_file]
3527 proc read_blame_incremental
{fd w w_load w_cmit w_line w_file
} {
3528 global blame_status blame_data
3530 if {![winfo exists
$w_file]} {
3535 while {[gets
$fd line
] >= 0} {
3536 if {[regexp
{^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$
} $line line \
3537 cmit original_line final_line line_count
]} {
3538 set blame_data
($w,commit
) $cmit
3539 set blame_data
($w,original_line
) $original_line
3540 set blame_data
($w,final_line
) $final_line
3541 set blame_data
($w,line_count
) $line_count
3543 if {[catch
{set g
$blame_data($w,$cmit,order
)}]} {
3544 $w_line tag conf g
$cmit
3545 $w_file tag conf g
$cmit
3546 $w_line tag raise in_sel
3547 $w_file tag raise in_sel
3548 $w_file tag raise sel
3549 set blame_data
($w,$cmit,order
) $blame_data($w,commit_count
)
3550 incr blame_data
($w,commit_count
)
3551 lappend blame_data
($w,commit_list
) $cmit
3553 } elseif
{[string match
{filename
*} $line]} {
3554 set file [string range
$line 9 end
]
3555 set n
$blame_data($w,line_count
)
3556 set lno
$blame_data($w,final_line
)
3557 set cmit
$blame_data($w,commit
)
3560 if {[catch
{set g g
$blame_data($w,line
$lno,commit
)}]} {
3561 $w_load tag add annotated
$lno.0 "$lno.0 lineend + 1c"
3563 $w_line tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3564 $w_file tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3567 set blame_data
($w,line
$lno,commit
) $cmit
3568 set blame_data
($w,line
$lno,file) $file
3569 $w_line tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3570 $w_file tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3572 if {$blame_data($w,highlight_line
) == -1} {
3573 if {[lindex
[$w_file yview
] 0] == 0} {
3575 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3577 } elseif
{$blame_data($w,highlight_line
) == $lno} {
3578 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3583 incr blame_data
($w,blame_lines
)
3586 set hc
$blame_data($w,highlight_commit
)
3588 && [expr {$blame_data($w,$hc,order
) + 1}]
3589 == $blame_data($w,$cmit,order
)} {
3590 blame_showcommit
$w $w_cmit $w_line $w_file \
3591 $blame_data($w,highlight_line
)
3593 } elseif
{[regexp
{^
([a-z-
]+) (.
*)$
} $line line header data
]} {
3594 set blame_data
($w,$blame_data($w,commit
),$header) $data
3600 set blame_status
($w) {Annotation complete.
}
3602 blame_incremental_status
$w
3606 proc blame_incremental_status
{w
} {
3607 global blame_status blame_data
3609 set have
$blame_data($w,blame_lines
)
3610 set total
$blame_data($w,total_lines
)
3612 if {$total} {set pdone
[expr {100 * $have / $total}]}
3614 set blame_status
($w) [format \
3615 "Loading annotations... %i of %i lines annotated (%2i%%)" \
3616 $have $total $pdone]
3619 proc blame_click
{w w_cmit w_line w_file cur_w pos
} {
3620 set lno
[lindex
[split [$cur_w index
$pos] .
] 0]
3621 if {$lno eq
{}} return
3623 $w_line tag remove in_sel
0.0 end
3624 $w_file tag remove in_sel
0.0 end
3625 $w_line tag add in_sel
$lno.0 "$lno.0 + 1 line"
3626 $w_file tag add in_sel
$lno.0 "$lno.0 + 1 line"
3628 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3637 proc blame_showcommit
{w w_cmit w_line w_file lno
} {
3638 global blame_colors blame_data repo_config
3640 set cmit
$blame_data($w,highlight_commit
)
3642 set idx
$blame_data($w,$cmit,order
)
3644 foreach c
$blame_colors {
3645 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3646 $w_line tag conf g
$h -background white
3647 $w_file tag conf g
$h -background white
3652 $w_cmit conf
-state normal
3653 $w_cmit delete
0.0 end
3654 if {[catch
{set cmit
$blame_data($w,line
$lno,commit
)}]} {
3656 $w_cmit insert end
"Loading annotation..."
3658 set idx
$blame_data($w,$cmit,order
)
3660 foreach c
$blame_colors {
3661 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3662 $w_line tag conf g
$h -background $c
3663 $w_file tag conf g
$h -background $c
3670 catch
{set author_name
$blame_data($w,$cmit,author
)}
3671 catch
{set author_email
$blame_data($w,$cmit,author-mail
)}
3672 catch
{set author_time
[clock format
$blame_data($w,$cmit,author-time
)]}
3674 set committer_name
{}
3675 set committer_email
{}
3676 set committer_time
{}
3677 catch
{set committer_name
$blame_data($w,$cmit,committer
)}
3678 catch
{set committer_email
$blame_data($w,$cmit,committer-mail
)}
3679 catch
{set committer_time
[clock format
$blame_data($w,$cmit,committer-time
)]}
3681 if {[catch
{set msg
$blame_data($w,$cmit,message
)}]} {
3684 set fd
[open
"| git cat-file commit $cmit" r
]
3685 fconfigure
$fd -encoding binary
-translation lf
3686 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
3689 while {[gets
$fd line
] > 0} {
3690 if {[string match
{encoding
*} $line]} {
3691 set enc
[string tolower
[string range
$line 9 end
]]
3694 set msg
[encoding convertfrom
$enc [read $fd]]
3695 set msg
[string trim
$msg]
3698 set author_name
[encoding convertfrom
$enc $author_name]
3699 set committer_name
[encoding convertfrom
$enc $committer_name]
3701 set blame_data
($w,$cmit,author
) $author_name
3702 set blame_data
($w,$cmit,committer
) $committer_name
3704 set blame_data
($w,$cmit,message
) $msg
3707 $w_cmit insert end
"commit $cmit\n"
3708 $w_cmit insert end
"Author: $author_name $author_email $author_time\n"
3709 $w_cmit insert end
"Committer: $committer_name $committer_email $committer_time\n"
3710 $w_cmit insert end
"Original File: [escape_path $blame_data($w,line$lno,file)]\n"
3711 $w_cmit insert end
"\n"
3712 $w_cmit insert end
$msg
3714 $w_cmit conf
-state disabled
3716 set blame_data
($w,highlight_line
) $lno
3717 set blame_data
($w,highlight_commit
) $cmit
3720 proc blame_copycommit
{w i pos
} {
3722 set lno
[lindex
[split [$i index
$pos] .
] 0]
3723 if {![catch
{set commit
$blame_data($w,line
$lno,commit
)}]} {
3732 ######################################################################
3737 #define mask_width 14
3738 #define mask_height 15
3739 static unsigned char mask_bits
[] = {
3740 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3741 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3742 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
3745 image create bitmap file_plain
-background white
-foreground black
-data {
3746 #define plain_width 14
3747 #define plain_height 15
3748 static unsigned char plain_bits
[] = {
3749 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3750 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
3751 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3752 } -maskdata $filemask
3754 image create bitmap file_mod
-background white
-foreground blue
-data {
3755 #define mod_width 14
3756 #define mod_height 15
3757 static unsigned char mod_bits
[] = {
3758 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3759 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3760 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3761 } -maskdata $filemask
3763 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
3764 #define file_fulltick_width 14
3765 #define file_fulltick_height 15
3766 static unsigned char file_fulltick_bits
[] = {
3767 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
3768 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
3769 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3770 } -maskdata $filemask
3772 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
3773 #define parttick_width 14
3774 #define parttick_height 15
3775 static unsigned char parttick_bits
[] = {
3776 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3777 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
3778 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3779 } -maskdata $filemask
3781 image create bitmap file_question
-background white
-foreground black
-data {
3782 #define file_question_width 14
3783 #define file_question_height 15
3784 static unsigned char file_question_bits
[] = {
3785 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
3786 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
3787 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3788 } -maskdata $filemask
3790 image create bitmap file_removed
-background white
-foreground red
-data {
3791 #define file_removed_width 14
3792 #define file_removed_height 15
3793 static unsigned char file_removed_bits
[] = {
3794 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3795 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
3796 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
3797 } -maskdata $filemask
3799 image create bitmap file_merge
-background white
-foreground blue
-data {
3800 #define file_merge_width 14
3801 #define file_merge_height 15
3802 static unsigned char file_merge_bits
[] = {
3803 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
3804 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3805 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3806 } -maskdata $filemask
3809 #define file_width 18
3810 #define file_height 18
3811 static unsigned char file_bits
[] = {
3812 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00,
3813 0x0c, 0x03, 0x00, 0x04, 0xfe, 0x00, 0x06, 0x80, 0x00, 0xff, 0x9f, 0x00,
3814 0x03, 0x98, 0x00, 0x02, 0x90, 0x00, 0x06, 0xb0, 0x00, 0x04, 0xa0, 0x00,
3815 0x0c, 0xe0, 0x00, 0x08, 0xc0, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
3816 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3818 image create bitmap file_dir
-background white
-foreground blue \
3819 -data $file_dir_data -maskdata $file_dir_data
3822 set file_uplevel_data
{
3824 #define up_height 15
3825 static unsigned char up_bits
[] = {
3826 0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f,
3827 0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
3828 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
3830 image create bitmap file_uplevel
-background white
-foreground red \
3831 -data $file_uplevel_data -maskdata $file_uplevel_data
3832 unset file_uplevel_data
3834 set ui_index .vpane.files.index.list
3835 set ui_workdir .vpane.files.workdir.list
3837 set all_icons
(_
$ui_index) file_plain
3838 set all_icons
(A
$ui_index) file_fulltick
3839 set all_icons
(M
$ui_index) file_fulltick
3840 set all_icons
(D
$ui_index) file_removed
3841 set all_icons
(U
$ui_index) file_merge
3843 set all_icons
(_
$ui_workdir) file_plain
3844 set all_icons
(M
$ui_workdir) file_mod
3845 set all_icons
(D
$ui_workdir) file_question
3846 set all_icons
(U
$ui_workdir) file_merge
3847 set all_icons
(O
$ui_workdir) file_plain
3849 set max_status_desc
0
3853 {_M
"Modified, not staged"}
3854 {M_
"Staged for commit"}
3855 {MM
"Portions staged for commit"}
3856 {MD
"Staged for commit, missing"}
3858 {_O
"Untracked, not staged"}
3859 {A_
"Staged for commit"}
3860 {AM
"Portions staged for commit"}
3861 {AD
"Staged for commit, missing"}
3864 {D_
"Staged for removal"}
3865 {DO
"Staged for removal, still present"}
3867 {U_
"Requires merge resolution"}
3868 {UU
"Requires merge resolution"}
3869 {UM
"Requires merge resolution"}
3870 {UD
"Requires merge resolution"}
3872 if {$max_status_desc < [string length
[lindex
$i 1]]} {
3873 set max_status_desc
[string length
[lindex
$i 1]]
3875 set all_descs
([lindex
$i 0]) [lindex
$i 1]
3879 ######################################################################
3883 proc bind_button3
{w cmd
} {
3884 bind $w <Any-Button-3
> $cmd
3886 bind $w <Control-Button-1
> $cmd
3890 proc scrollbar2many
{list mode args
} {
3891 foreach w
$list {eval $w $mode $args}
3894 proc many2scrollbar
{list mode sb top bottom
} {
3895 $sb set $top $bottom
3896 foreach w
$list {$w $mode moveto
$top}
3899 proc incr_font_size
{font
{amt
1}} {
3900 set sz
[font configure
$font -size]
3902 font configure
$font -size $sz
3903 font configure
${font}bold
-size $sz
3906 proc hook_failed_popup
{hook msg
} {
3911 label
$w.m.l1
-text "$hook hook failed:" \
3916 -background white
-borderwidth 1 \
3918 -width 80 -height 10 \
3920 -yscrollcommand [list
$w.m.sby
set]
3922 -text {You must correct the above errors before committing.
} \
3926 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3927 pack
$w.m.l1
-side top
-fill x
3928 pack
$w.m.l2
-side bottom
-fill x
3929 pack
$w.m.sby
-side right
-fill y
3930 pack
$w.m.t
-side left
-fill both
-expand 1
3931 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3933 $w.m.t insert
1.0 $msg
3934 $w.m.t conf
-state disabled
3936 button
$w.ok
-text OK \
3939 -command "destroy $w"
3940 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3942 bind $w <Visibility
> "grab $w; focus $w"
3943 bind $w <Key-Return
> "destroy $w"
3944 wm title
$w "[appname] ([reponame]): error"
3948 set next_console_id
0
3950 proc new_console
{short_title long_title
} {
3951 global next_console_id console_data
3952 set w .console
[incr next_console_id
]
3953 set console_data
($w) [list
$short_title $long_title]
3954 return [console_init
$w]
3957 proc console_init
{w
} {
3958 global console_cr console_data M1B
3960 set console_cr
($w) 1.0
3963 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
3968 -background white
-borderwidth 1 \
3970 -width 80 -height 10 \
3973 -yscrollcommand [list
$w.m.sby
set]
3974 label
$w.m.s
-text {Working... please
wait...
} \
3978 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3979 pack
$w.m.l1
-side top
-fill x
3980 pack
$w.m.s
-side bottom
-fill x
3981 pack
$w.m.sby
-side right
-fill y
3982 pack
$w.m.t
-side left
-fill both
-expand 1
3983 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3985 menu
$w.ctxm
-tearoff 0
3986 $w.ctxm add
command -label "Copy" \
3988 -command "tk_textCopy $w.m.t"
3989 $w.ctxm add
command -label "Select All" \
3991 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
3992 $w.ctxm add
command -label "Copy All" \
3995 $w.m.t tag add sel 0.0 end
3997 $w.m.t tag remove sel 0.0 end
4000 button
$w.ok
-text {Close
} \
4003 -command "destroy $w"
4004 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
4006 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
4007 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
4008 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
4009 bind $w <Visibility
> "focus $w"
4010 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
4014 proc console_exec
{w cmd after
} {
4015 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
4016 # But most users need that so we have to relogin. :-(
4019 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
4022 # -- Tcl won't let us redirect both stdout and stderr to
4023 # the same pipe. So pass it through cat...
4025 set cmd
[concat |
$cmd |
& cat]
4027 set fd_f
[open
$cmd r
]
4028 fconfigure
$fd_f -blocking 0 -translation binary
4029 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
4032 proc console_read
{w fd after
} {
4037 if {![winfo exists
$w]} {console_init
$w}
4038 $w.m.t conf
-state normal
4040 set n
[string length
$buf]
4042 set cr
[string first
"\r" $buf $c]
4043 set lf
[string first
"\n" $buf $c]
4044 if {$cr < 0} {set cr
[expr {$n + 1}]}
4045 if {$lf < 0} {set lf
[expr {$n + 1}]}
4048 $w.m.t insert end
[string range
$buf $c $lf]
4049 set console_cr
($w) [$w.m.t index
{end
-1c}]
4053 $w.m.t delete
$console_cr($w) end
4054 $w.m.t insert end
"\n"
4055 $w.m.t insert end
[string range
$buf $c $cr]
4060 $w.m.t conf
-state disabled
4064 fconfigure
$fd -blocking 1
4066 if {[catch
{close
$fd}]} {
4071 uplevel
#0 $after $w $ok
4074 fconfigure
$fd -blocking 0
4077 proc console_chain
{cmdlist w
{ok
1}} {
4079 if {[llength
$cmdlist] == 0} {
4084 set cmd
[lindex
$cmdlist 0]
4085 set cmdlist
[lrange
$cmdlist 1 end
]
4087 if {[lindex
$cmd 0] eq
{console_exec
}} {
4090 [list console_chain
$cmdlist]
4092 uplevel
#0 $cmd $cmdlist $w $ok
4099 proc console_done
{args
} {
4100 global console_cr console_data
4102 switch
-- [llength
$args] {
4104 set w
[lindex
$args 0]
4105 set ok
[lindex
$args 1]
4108 set w
[lindex
$args 1]
4109 set ok
[lindex
$args 2]
4112 error
"wrong number of args: console_done ?ignored? w ok"
4117 if {[winfo exists
$w]} {
4118 $w.m.s conf
-background green
-text {Success
}
4119 $w.ok conf
-state normal
4123 if {![winfo exists
$w]} {
4126 $w.m.s conf
-background red
-text {Error
: Command Failed
}
4127 $w.ok conf
-state normal
4131 array
unset console_cr
$w
4132 array
unset console_data
$w
4135 ######################################################################
4139 set starting_gitk_msg
{Starting gitk... please
wait...
}
4141 proc do_gitk
{revs
} {
4142 global env ui_status_value starting_gitk_msg
4144 # -- Always start gitk through whatever we were loaded with. This
4145 # lets us bypass using shell process on Windows systems.
4147 set cmd
[list
[info nameofexecutable
]]
4148 lappend cmd
[gitexec gitk
]
4154 if {[catch
{eval exec $cmd &} err
]} {
4155 error_popup
"Failed to start gitk:\n\n$err"
4157 set ui_status_value
$starting_gitk_msg
4159 if {$ui_status_value eq
$starting_gitk_msg} {
4160 set ui_status_value
{Ready.
}
4167 set fd
[open
"| git count-objects -v" r
]
4168 while {[gets
$fd line
] > 0} {
4169 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
4170 set stats
($name) $value
4176 foreach p
[glob
-directory [gitdir objects pack
] \
4179 incr packed_sz
[file size
$p]
4181 if {$packed_sz > 0} {
4182 set stats
(size-pack
) [expr {$packed_sz / 1024}]
4187 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4189 label
$w.header
-text {Database Statistics
} \
4191 pack
$w.header
-side top
-fill x
4193 frame
$w.buttons
-border 1
4194 button
$w.buttons.close
-text Close \
4197 -command [list destroy
$w]
4198 button
$w.buttons.gc
-text {Compress Database
} \
4201 -command "destroy $w;do_gc"
4202 pack
$w.buttons.close
-side right
4203 pack
$w.buttons.gc
-side left
4204 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4206 frame
$w.stat
-borderwidth 1 -relief solid
4208 {count
{Number of loose objects
}}
4209 {size
{Disk space used by loose objects
} { KiB
}}
4210 {in-pack
{Number of packed objects
}}
4211 {packs
{Number of packs
}}
4212 {size-pack
{Disk space used by packed objects
} { KiB
}}
4213 {prune-packable
{Packed objects waiting
for pruning
}}
4214 {garbage
{Garbage files
}}
4216 set name
[lindex
$s 0]
4217 set label
[lindex
$s 1]
4218 if {[catch
{set value
$stats($name)}]} continue
4219 if {[llength
$s] > 2} {
4220 set value
"$value[lindex $s 2]"
4223 label
$w.stat.l_
$name -text "$label:" -anchor w
-font font_ui
4224 label
$w.stat.v_
$name -text $value -anchor w
-font font_ui
4225 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
4227 pack
$w.stat
-pady 10 -padx 10
4229 bind $w <Visibility
> "grab $w; focus $w.buttons.close"
4230 bind $w <Key-Escape
> [list destroy
$w]
4231 bind $w <Key-Return
> [list destroy
$w]
4232 wm title
$w "[appname] ([reponame]): Database Statistics"
4237 set w
[new_console
{gc
} {Compressing the object database
}]
4239 {console_exec
{git pack-refs
--prune}}
4240 {console_exec
{git reflog expire
--all}}
4241 {console_exec
{git repack
-a -d -l}}
4242 {console_exec
{git rerere gc
}}
4246 proc do_fsck_objects
{} {
4247 set w
[new_console
{fsck-objects
} \
4248 {Verifying the object database with fsck-objects
}]
4249 set cmd
[list git fsck-objects
]
4252 lappend cmd
--strict
4253 console_exec
$w $cmd console_done
4259 global ui_comm is_quitting repo_config commit_type
4261 if {$is_quitting} return
4264 if {[winfo exists
$ui_comm]} {
4265 # -- Stash our current commit buffer.
4267 set save
[gitdir GITGUI_MSG
]
4268 set msg
[string trim
[$ui_comm get
0.0 end
]]
4269 regsub
-all -line {[ \r\t]+$
} $msg {} msg
4270 if {(![string match amend
* $commit_type]
4271 ||
[$ui_comm edit modified
])
4274 set fd
[open
$save w
]
4275 puts
-nonewline $fd $msg
4279 catch
{file delete
$save}
4282 # -- Stash our current window geometry into this repository.
4284 set cfg_geometry
[list
]
4285 lappend cfg_geometry
[wm geometry .
]
4286 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
4287 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
4288 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
4291 if {$cfg_geometry ne
$rc_geometry} {
4292 catch
{git config gui.geometry
$cfg_geometry}
4300 rescan
{set ui_status_value
{Ready.
}}
4303 proc unstage_helper
{txt paths
} {
4304 global file_states current_diff_path
4306 if {![lock_index begin-update
]} return
4310 foreach path
$paths {
4311 switch
-glob -- [lindex
$file_states($path) 0] {
4315 lappend pathList
$path
4316 if {$path eq
$current_diff_path} {
4317 set after
{reshow_diff
;}
4322 if {$pathList eq
{}} {
4328 [concat
$after {set ui_status_value
{Ready.
}}]
4332 proc do_unstage_selection
{} {
4333 global current_diff_path selected_paths
4335 if {[array size selected_paths
] > 0} {
4337 {Unstaging selected files from commit
} \
4338 [array names selected_paths
]
4339 } elseif
{$current_diff_path ne
{}} {
4341 "Unstaging [short_path $current_diff_path] from commit" \
4342 [list
$current_diff_path]
4346 proc add_helper
{txt paths
} {
4347 global file_states current_diff_path
4349 if {![lock_index begin-update
]} return
4353 foreach path
$paths {
4354 switch
-glob -- [lindex
$file_states($path) 0] {
4359 lappend pathList
$path
4360 if {$path eq
$current_diff_path} {
4361 set after
{reshow_diff
;}
4366 if {$pathList eq
{}} {
4372 [concat
$after {set ui_status_value
{Ready to commit.
}}]
4376 proc do_add_selection
{} {
4377 global current_diff_path selected_paths
4379 if {[array size selected_paths
] > 0} {
4381 {Adding selected files
} \
4382 [array names selected_paths
]
4383 } elseif
{$current_diff_path ne
{}} {
4385 "Adding [short_path $current_diff_path]" \
4386 [list
$current_diff_path]
4390 proc do_add_all
{} {
4394 foreach path
[array names file_states
] {
4395 switch
-glob -- [lindex
$file_states($path) 0] {
4398 ?D
{lappend paths
$path}
4401 add_helper
{Adding all changed files
} $paths
4404 proc revert_helper
{txt paths
} {
4405 global file_states current_diff_path
4407 if {![lock_index begin-update
]} return
4411 foreach path
$paths {
4412 switch
-glob -- [lindex
$file_states($path) 0] {
4416 lappend pathList
$path
4417 if {$path eq
$current_diff_path} {
4418 set after
{reshow_diff
;}
4424 set n
[llength
$pathList]
4428 } elseif
{$n == 1} {
4429 set s
"[short_path [lindex $pathList]]"
4431 set s
"these $n files"
4434 set reply
[tk_dialog \
4436 "[appname] ([reponame])" \
4437 "Revert changes in $s?
4439 Any unadded changes will be permanently lost by the revert." \
4449 [concat
$after {set ui_status_value
{Ready.
}}]
4455 proc do_revert_selection
{} {
4456 global current_diff_path selected_paths
4458 if {[array size selected_paths
] > 0} {
4460 {Reverting selected files
} \
4461 [array names selected_paths
]
4462 } elseif
{$current_diff_path ne
{}} {
4464 "Reverting [short_path $current_diff_path]" \
4465 [list
$current_diff_path]
4469 proc do_signoff
{} {
4472 set me
[committer_ident
]
4473 if {$me eq
{}} return
4475 set sob
"Signed-off-by: $me"
4476 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
4477 if {$last ne
$sob} {
4478 $ui_comm edit separator
4480 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
4481 $ui_comm insert end
"\n"
4483 $ui_comm insert end
"\n$sob"
4484 $ui_comm edit separator
4489 proc do_select_commit_type
{} {
4490 global commit_type selected_commit_type
4492 if {$selected_commit_type eq
{new
}
4493 && [string match amend
* $commit_type]} {
4495 } elseif
{$selected_commit_type eq
{amend
}
4496 && ![string match amend
* $commit_type]} {
4499 # The amend request was rejected...
4501 if {![string match amend
* $commit_type]} {
4502 set selected_commit_type new
4512 global appvers copyright
4513 global tcl_patchLevel tk_patchLevel
4517 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4519 label
$w.header
-text "About [appname]" \
4521 pack
$w.header
-side top
-fill x
4524 button
$w.buttons.close
-text {Close
} \
4527 -command [list destroy
$w]
4528 pack
$w.buttons.close
-side right
4529 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4532 -text "git-gui - a graphical user interface for Git.
4540 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
4543 append v
"git-gui version $appvers\n"
4544 append v
"[git version]\n"
4546 if {$tcl_patchLevel eq
$tk_patchLevel} {
4547 append v
"Tcl/Tk version $tcl_patchLevel"
4549 append v
"Tcl version $tcl_patchLevel"
4550 append v
", Tk version $tk_patchLevel"
4561 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
4563 menu
$w.ctxm
-tearoff 0
4564 $w.ctxm add
command \
4569 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
4572 bind $w <Visibility
> "grab $w; focus $w.buttons.close"
4573 bind $w <Key-Escape
> "destroy $w"
4574 bind $w <Key-Return
> "destroy $w"
4575 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
4576 wm title
$w "About [appname]"
4580 proc do_options
{} {
4581 global repo_config global_config font_descs
4582 global repo_config_new global_config_new
4584 array
unset repo_config_new
4585 array
unset global_config_new
4586 foreach name
[array names repo_config
] {
4587 set repo_config_new
($name) $repo_config($name)
4590 foreach name
[array names repo_config
] {
4592 gui.diffcontext
{continue}
4594 set repo_config_new
($name) $repo_config($name)
4596 foreach name
[array names global_config
] {
4597 set global_config_new
($name) $global_config($name)
4600 set w .options_editor
4602 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4604 label
$w.header
-text "Options" \
4606 pack
$w.header
-side top
-fill x
4609 button
$w.buttons.restore
-text {Restore Defaults
} \
4612 -command do_restore_defaults
4613 pack
$w.buttons.restore
-side left
4614 button
$w.buttons.save
-text Save \
4617 -command [list do_save_config
$w]
4618 pack
$w.buttons.save
-side right
4619 button
$w.buttons.cancel
-text {Cancel
} \
4622 -command [list destroy
$w]
4623 pack
$w.buttons.cancel
-side right
-padx 5
4624 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4626 labelframe
$w.repo
-text "[reponame] Repository" \
4628 labelframe
$w.global
-text {Global
(All Repositories
)} \
4630 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
4631 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
4635 {t user.name
{User Name
}}
4636 {t user.email
{Email Address
}}
4638 {b merge.summary
{Summarize Merge Commits
}}
4639 {i-1.
.5 merge.verbosity
{Merge Verbosity
}}
4641 {b gui.trustmtime
{Trust File Modification Timestamps
}}
4642 {i-1.
.99 gui.diffcontext
{Number of Diff Context Lines
}}
4643 {t gui.newbranchtemplate
{New Branch Name Template
}}
4645 set type [lindex
$option 0]
4646 set name
[lindex
$option 1]
4647 set text
[lindex
$option 2]
4649 foreach f
{repo global
} {
4650 switch
-glob -- $type {
4652 checkbutton
$w.
$f.
$optid -text $text \
4653 -variable ${f}_config_new
($name) \
4657 pack
$w.
$f.
$optid -side top
-anchor w
4660 regexp
-- {-(\d
+)\.\.
(\d
+)$
} $type _junk min max
4662 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4663 pack
$w.
$f.
$optid.l
-side left
-anchor w
-fill x
4664 spinbox
$w.
$f.
$optid.v \
4665 -textvariable ${f}_config_new
($name) \
4669 -width [expr {1 + [string length
$max]}] \
4671 bind $w.
$f.
$optid.v
<FocusIn
> {%W selection range
0 end
}
4672 pack
$w.
$f.
$optid.v
-side right
-anchor e
-padx 5
4673 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4677 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4678 entry
$w.
$f.
$optid.v \
4682 -textvariable ${f}_config_new
($name) \
4684 pack
$w.
$f.
$optid.l
-side left
-anchor w
4685 pack
$w.
$f.
$optid.v
-side left
-anchor w \
4688 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4694 set all_fonts
[lsort
[font families
]]
4695 foreach option
$font_descs {
4696 set name
[lindex
$option 0]
4697 set font
[lindex
$option 1]
4698 set text
[lindex
$option 2]
4700 set global_config_new
(gui.
$font^^family
) \
4701 [font configure
$font -family]
4702 set global_config_new
(gui.
$font^^size
) \
4703 [font configure
$font -size]
4705 frame
$w.global.
$name
4706 label
$w.global.
$name.l
-text "$text:" -font font_ui
4707 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
4708 set fontmenu
[eval tk_optionMenu
$w.global.
$name.family \
4709 global_config_new
(gui.
$font^^family
) \
4711 $w.global.
$name.family configure
-font font_ui
4712 $fontmenu configure
-font font_ui
4713 spinbox
$w.global.
$name.size \
4714 -textvariable global_config_new
(gui.
$font^^size
) \
4715 -from 2 -to 80 -increment 1 \
4718 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
4719 pack
$w.global.
$name.size
-side right
-anchor e
4720 pack
$w.global.
$name.family
-side right
-anchor e
4721 pack
$w.global.
$name -side top
-anchor w
-fill x
4724 bind $w <Visibility
> "grab $w; focus $w.buttons.save"
4725 bind $w <Key-Escape
> "destroy $w"
4726 bind $w <Key-Return
> [list do_save_config
$w]
4727 wm title
$w "[appname] ([reponame]): Options"
4731 proc do_restore_defaults
{} {
4732 global font_descs default_config repo_config
4733 global repo_config_new global_config_new
4735 foreach name
[array names default_config
] {
4736 set repo_config_new
($name) $default_config($name)
4737 set global_config_new
($name) $default_config($name)
4740 foreach option
$font_descs {
4741 set name
[lindex
$option 0]
4742 set repo_config
(gui.
$name) $default_config(gui.
$name)
4746 foreach option
$font_descs {
4747 set name
[lindex
$option 0]
4748 set font
[lindex
$option 1]
4749 set global_config_new
(gui.
$font^^family
) \
4750 [font configure
$font -family]
4751 set global_config_new
(gui.
$font^^size
) \
4752 [font configure
$font -size]
4756 proc do_save_config
{w
} {
4757 if {[catch
{save_config
} err
]} {
4758 error_popup
"Failed to completely save options:\n\n$err"
4764 proc do_windows_shortcut
{} {
4767 set fn
[tk_getSaveFile \
4769 -title "[appname] ([reponame]): Create Desktop Icon" \
4770 -initialfile "Git [reponame].bat"]
4774 puts
$fd "@ECHO Entering [reponame]"
4775 puts
$fd "@ECHO Starting git-gui... please wait..."
4776 puts
$fd "@SET PATH=[file normalize [gitexec]];%PATH%"
4777 puts
$fd "@SET GIT_DIR=[file normalize [gitdir]]"
4778 puts
-nonewline $fd "@\"[info nameofexecutable]\""
4779 puts
$fd " \"[file normalize $argv0]\""
4782 error_popup
"Cannot write script:\n\n$err"
4787 proc do_cygwin_shortcut
{} {
4791 set desktop
[exec cygpath \
4799 set fn
[tk_getSaveFile \
4801 -title "[appname] ([reponame]): Create Desktop Icon" \
4802 -initialdir $desktop \
4803 -initialfile "Git [reponame].bat"]
4807 set sh
[exec cygpath \
4811 set me
[exec cygpath \
4815 set gd
[exec cygpath \
4819 set gw
[exec cygpath \
4822 [file dirname [gitdir
]]]
4823 regsub
-all ' $me "'\\''" me
4824 regsub -all ' $gd "'\\''" gd
4825 puts $fd "@ECHO Entering $gw"
4826 puts $fd "@ECHO Starting git-gui... please wait..."
4827 puts -nonewline $fd "@\"$sh\" --login -c \""
4828 puts -nonewline $fd "GIT_DIR='$gd'"
4829 puts -nonewline $fd " '$me'"
4833 error_popup "Cannot write script:\n\n$err"
4838 proc do_macosx_app {} {
4841 set fn [tk_getSaveFile \
4843 -title "[appname] ([reponame]): Create Desktop Icon" \
4844 -initialdir [file join $env(HOME) Desktop] \
4845 -initialfile "Git [reponame].app"]
4848 set Contents [file join $fn Contents]
4849 set MacOS [file join $Contents MacOS]
4850 set exe [file join $MacOS git-gui]
4854 set fd [open [file join $Contents Info.plist] w]
4855 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
4856 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4857 <plist version="1.0">
4859 <key>CFBundleDevelopmentRegion</key>
4860 <string>English</string>
4861 <key>CFBundleExecutable</key>
4862 <string>git-gui</string>
4863 <key>CFBundleIdentifier</key>
4864 <string>org.spearce.git-gui</string>
4865 <key>CFBundleInfoDictionaryVersion</key>
4866 <string>6.0</string>
4867 <key>CFBundlePackageType</key>
4868 <string>APPL</string>
4869 <key>CFBundleSignature</key>
4870 <string>????</string>
4871 <key>CFBundleVersion</key>
4872 <string>1.0</string>
4873 <key>NSPrincipalClass</key>
4874 <string>NSApplication</string>
4879 set fd [open $exe w]
4880 set gd [file normalize [gitdir]]
4881 set ep [file normalize [gitexec]]
4882 regsub -all ' $gd "'\\''" gd
4883 regsub
-all ' $ep "'\\''" ep
4884 puts $fd "#!/bin/sh"
4885 foreach name
[array names env
] {
4886 if {[string match GIT_
* $name]} {
4887 regsub
-all ' $env($name) "'\\''" v
4888 puts $fd "export $name='$v'"
4891 puts $fd "export PATH
='$ep':\
$PATH"
4892 puts $fd "export GIT_DIR
='$gd'"
4893 puts $fd "exec [file normalize
$argv0]"
4896 file attributes $exe -permissions u+x,g+x,o+x
4898 error_popup "Cannot
write icon
:\n\n$err"
4903 proc toggle_or_diff {w x y} {
4904 global file_states file_lists current_diff_path ui_index ui_workdir
4905 global last_clicked selected_paths
4907 set pos [split [$w index @$x,$y] .]
4908 set lno [lindex $pos 0]
4909 set col [lindex $pos 1]
4910 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4916 set last_clicked [list $w $lno]
4917 array unset selected_paths
4918 $ui_index tag remove in_sel 0.0 end
4919 $ui_workdir tag remove in_sel 0.0 end
4922 if {$current_diff_path eq $path} {
4923 set after {reshow_diff;}
4927 if {$w eq $ui_index} {
4929 "Unstaging
[short_path
$path] from commit
" \
4931 [concat $after {set ui_status_value {Ready.}}]
4932 } elseif {$w eq $ui_workdir} {
4934 "Adding
[short_path
$path]" \
4936 [concat $after {set ui_status_value {Ready.}}]
4939 show_diff $path $w $lno
4943 proc add_one_to_selection {w x y} {
4944 global file_lists last_clicked selected_paths
4946 set lno [lindex [split [$w index @$x,$y] .] 0]
4947 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4953 if {$last_clicked ne {}
4954 && [lindex $last_clicked 0] ne $w} {
4955 array unset selected_paths
4956 [lindex $last_clicked 0] tag remove in_sel 0.0 end
4959 set last_clicked [list $w $lno]
4960 if {[catch {set in_sel $selected_paths($path)}]} {
4964 unset selected_paths($path)
4965 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
4967 set selected_paths($path) 1
4968 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
4972 proc add_range_to_selection {w x y} {
4973 global file_lists last_clicked selected_paths
4975 if {[lindex $last_clicked 0] ne $w} {
4976 toggle_or_diff $w $x $y
4980 set lno [lindex [split [$w index @$x,$y] .] 0]
4981 set lc [lindex $last_clicked 1]
4990 foreach path [lrange $file_lists($w) \
4991 [expr {$begin - 1}] \
4992 [expr {$end - 1}]] {
4993 set selected_paths($path) 1
4995 $w tag add in_sel $begin.0 [expr {$end + 1}].0
4998 ######################################################################
5002 set cursor_ptr arrow
5003 font create font_diff -family Courier -size 10
5007 eval font configure font_ui [font actual [.dummy cget -font]]
5011 font create font_uibold
5012 font create font_diffbold
5017 } elseif {[is_MacOSX]} {
5025 proc apply_config {} {
5026 global repo_config font_descs
5028 foreach option $font_descs {
5029 set name [lindex $option 0]
5030 set font [lindex $option 1]
5032 foreach {cn cv} $repo_config(gui.$name) {
5033 font configure $font $cn $cv
5036 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
5038 foreach {cn cv} [font configure $font] {
5039 font configure ${font}bold $cn $cv
5041 font configure ${font}bold -weight bold
5045 set default_config(merge.summary) false
5046 set default_config(merge.verbosity) 2
5047 set default_config(user.name) {}
5048 set default_config(user.email) {}
5050 set default_config(gui.trustmtime) false
5051 set default_config(gui.diffcontext) 5
5052 set default_config(gui.newbranchtemplate) {}
5053 set default_config(gui.fontui) [font configure font_ui]
5054 set default_config(gui.fontdiff) [font configure font_diff]
5056 {fontui font_ui {Main Font}}
5057 {fontdiff font_diff {Diff/Console Font}}
5062 ######################################################################
5064 ## feature option selection
5066 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
5071 if {$subcommand eq {gui.sh}} {
5074 if {$subcommand eq {gui} && [llength $argv] > 0} {
5075 set subcommand [lindex $argv 0]
5076 set argv [lrange $argv 1 end]
5079 enable_option multicommit
5080 enable_option branch
5081 enable_option transport
5083 switch -- $subcommand {
5086 disable_option multicommit
5087 disable_option branch
5088 disable_option transport
5091 enable_option singlecommit
5093 disable_option multicommit
5094 disable_option branch
5095 disable_option transport
5099 ######################################################################
5107 menu .mbar -tearoff 0
5108 .mbar add cascade -label Repository -menu .mbar.repository -font font_ui
5109 .mbar add cascade -label Edit -menu .mbar.edit -font font_ui
5110 if {[is_enabled branch]} {
5111 .mbar add cascade -label Branch -menu .mbar.branch -font font_ui
5113 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
5114 .mbar add cascade -label Commit -menu .mbar.commit -font font_ui
5116 if {[is_enabled transport]} {
5117 .mbar add cascade -label Merge -menu .mbar.merge -font font_ui
5118 .mbar add cascade -label Fetch -menu .mbar.fetch -font font_ui
5119 .mbar add cascade -label Push -menu .mbar.push -font font_ui
5121 . configure -menu .mbar
5123 # -- Repository Menu
5125 menu .mbar.repository
5127 .mbar.repository add command \
5128 -label {Browse Current Branch} \
5129 -command {new_browser $current_branch} \
5131 trace add variable current_branch write ".mbar.repository entryconf
[.mbar.repository index last
] -label \"Browse \
$current_branch\" ;#"
5132 .mbar.repository add separator
5134 .mbar.repository add
command \
5135 -label {Visualize Current Branch
} \
5136 -command {do_gitk
$current_branch} \
5138 trace add variable current_branch
write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#"
5139 .mbar.repository add
command \
5140 -label {Visualize All Branches
} \
5141 -command {do_gitk
--all} \
5143 .mbar.repository add separator
5145 if {[is_enabled multicommit
]} {
5146 .mbar.repository add
command -label {Database Statistics
} \
5150 .mbar.repository add
command -label {Compress Database
} \
5154 .mbar.repository add
command -label {Verify Database
} \
5155 -command do_fsck_objects \
5158 .mbar.repository add separator
5161 .mbar.repository add
command \
5162 -label {Create Desktop Icon
} \
5163 -command do_cygwin_shortcut \
5165 } elseif
{[is_Windows
]} {
5166 .mbar.repository add
command \
5167 -label {Create Desktop Icon
} \
5168 -command do_windows_shortcut \
5170 } elseif
{[is_MacOSX
]} {
5171 .mbar.repository add
command \
5172 -label {Create Desktop Icon
} \
5173 -command do_macosx_app \
5178 .mbar.repository add
command -label Quit \
5180 -accelerator $M1T-Q \
5186 .mbar.edit add
command -label Undo \
5187 -command {catch
{[focus
] edit undo
}} \
5188 -accelerator $M1T-Z \
5190 .mbar.edit add
command -label Redo \
5191 -command {catch
{[focus
] edit redo
}} \
5192 -accelerator $M1T-Y \
5194 .mbar.edit add separator
5195 .mbar.edit add
command -label Cut \
5196 -command {catch
{tk_textCut
[focus
]}} \
5197 -accelerator $M1T-X \
5199 .mbar.edit add
command -label Copy \
5200 -command {catch
{tk_textCopy
[focus
]}} \
5201 -accelerator $M1T-C \
5203 .mbar.edit add
command -label Paste \
5204 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
5205 -accelerator $M1T-V \
5207 .mbar.edit add
command -label Delete \
5208 -command {catch
{[focus
] delete sel.first sel.last
}} \
5211 .mbar.edit add separator
5212 .mbar.edit add
command -label {Select All
} \
5213 -command {catch
{[focus
] tag add sel
0.0 end
}} \
5214 -accelerator $M1T-A \
5219 if {[is_enabled branch
]} {
5222 .mbar.branch add
command -label {Create...
} \
5223 -command do_create_branch \
5224 -accelerator $M1T-N \
5226 lappend disable_on_lock
[list .mbar.branch entryconf \
5227 [.mbar.branch index last
] -state]
5229 .mbar.branch add
command -label {Delete...
} \
5230 -command do_delete_branch \
5232 lappend disable_on_lock
[list .mbar.branch entryconf \
5233 [.mbar.branch index last
] -state]
5235 .mbar.branch add
command -label {Reset...
} \
5236 -command do_reset_hard \
5238 lappend disable_on_lock
[list .mbar.branch entryconf \
5239 [.mbar.branch index last
] -state]
5244 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
5247 .mbar.commit add radiobutton \
5248 -label {New Commit
} \
5249 -command do_select_commit_type \
5250 -variable selected_commit_type \
5253 lappend disable_on_lock \
5254 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5256 .mbar.commit add radiobutton \
5257 -label {Amend Last Commit
} \
5258 -command do_select_commit_type \
5259 -variable selected_commit_type \
5262 lappend disable_on_lock \
5263 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5265 .mbar.commit add separator
5267 .mbar.commit add
command -label Rescan \
5268 -command do_rescan \
5271 lappend disable_on_lock \
5272 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5274 .mbar.commit add
command -label {Add To Commit
} \
5275 -command do_add_selection \
5277 lappend disable_on_lock \
5278 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5280 .mbar.commit add
command -label {Add Existing To Commit
} \
5281 -command do_add_all \
5282 -accelerator $M1T-I \
5284 lappend disable_on_lock \
5285 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5287 .mbar.commit add
command -label {Unstage From Commit
} \
5288 -command do_unstage_selection \
5290 lappend disable_on_lock \
5291 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5293 .mbar.commit add
command -label {Revert Changes
} \
5294 -command do_revert_selection \
5296 lappend disable_on_lock \
5297 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5299 .mbar.commit add separator
5301 .mbar.commit add
command -label {Sign Off
} \
5302 -command do_signoff \
5303 -accelerator $M1T-S \
5306 .mbar.commit add
command -label Commit \
5307 -command do_commit \
5308 -accelerator $M1T-Return \
5310 lappend disable_on_lock \
5311 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5316 if {[is_enabled branch
]} {
5318 .mbar.merge add
command -label {Local Merge...
} \
5319 -command do_local_merge \
5321 lappend disable_on_lock \
5322 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5323 .mbar.merge add
command -label {Abort Merge...
} \
5324 -command do_reset_hard \
5326 lappend disable_on_lock \
5327 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5333 if {[is_enabled transport
]} {
5337 .mbar.push add
command -label {Push...
} \
5338 -command do_push_anywhere \
5343 # -- Apple Menu (Mac OS X only)
5345 .mbar add cascade
-label Apple
-menu .mbar.apple
5348 .mbar.apple add
command -label "About [appname]" \
5351 .mbar.apple add
command -label "Options..." \
5352 -command do_options \
5357 .mbar.edit add separator
5358 .mbar.edit add
command -label {Options...
} \
5359 -command do_options \
5364 if {[file exists
/usr
/local
/miga
/lib
/gui-miga
]
5365 && [file exists .pvcsrc
]} {
5367 global ui_status_value
5368 if {![lock_index update
]} return
5369 set cmd
[list sh
--login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
5370 set miga_fd
[open
"|$cmd" r
]
5371 fconfigure
$miga_fd -blocking 0
5372 fileevent
$miga_fd readable
[list miga_done
$miga_fd]
5373 set ui_status_value
{Running miga...
}
5375 proc miga_done
{fd
} {
5380 rescan
[list
set ui_status_value
{Ready.
}]
5383 .mbar add cascade
-label Tools
-menu .mbar.tools
5385 .mbar.tools add
command -label "Migrate" \
5388 lappend disable_on_lock \
5389 [list .mbar.tools entryconf
[.mbar.tools index last
] -state]
5395 .mbar add cascade
-label Help
-menu .mbar.
help -font font_ui
5399 .mbar.
help add
command -label "About [appname]" \
5405 catch
{set browser
$repo_config(instaweb.browser
)}
5406 set doc_path
[file dirname [gitexec
]]
5407 set doc_path
[file join $doc_path Documentation index.html
]
5410 set doc_path
[exec cygpath
--mixed $doc_path]
5413 if {$browser eq
{}} {
5416 } elseif
{[is_Cygwin
]} {
5417 set program_files
[file dirname [exec cygpath
--windir]]
5418 set program_files
[file join $program_files {Program Files
}]
5419 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
5420 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
5421 if {[file exists
$firefox]} {
5422 set browser
$firefox
5423 } elseif
{[file exists
$ie]} {
5426 unset program_files firefox ie
5430 if {[file isfile
$doc_path]} {
5431 set doc_url
"file:$doc_path"
5433 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
5436 if {$browser ne
{}} {
5437 .mbar.
help add
command -label {Online Documentation
} \
5438 -command [list
exec $browser $doc_url &] \
5441 unset browser doc_path doc_url
5443 # -- Standard bindings
5445 bind .
<Destroy
> do_quit
5446 bind all
<$M1B-Key-q> do_quit
5447 bind all
<$M1B-Key-Q> do_quit
5448 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
5449 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
5451 # -- Not a normal commit type invocation? Do that instead!
5453 switch
-- $subcommand {
5455 if {[llength
$argv] != 1} {
5456 puts stderr
"usage: $argv0 browser commit"
5459 set current_branch
[lindex
$argv 0]
5460 new_browser
$current_branch
5464 if {[llength
$argv] != 2} {
5465 puts stderr
"usage: $argv0 blame commit path"
5468 set current_branch
[lindex
$argv 0]
5469 show_blame
$current_branch [lindex
$argv 1]
5474 if {[llength
$argv] != 0} {
5475 puts
-nonewline stderr
"usage: $argv0"
5476 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
5477 puts
-nonewline stderr
" $subcommand"
5482 # fall through to setup UI for commits
5485 puts stderr
"usage: $argv0 \[{blame|browser|citool}\]"
5496 -text {Current Branch
:} \
5501 -textvariable current_branch \
5505 pack .branch.l1
-side left
5506 pack .branch.cb
-side left
-fill x
5507 pack .branch
-side top
-fill x
5509 # -- Main Window Layout
5511 panedwindow .vpane
-orient vertical
5512 panedwindow .vpane.files
-orient horizontal
5513 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
5514 pack .vpane
-anchor n
-side top
-fill both
-expand 1
5516 # -- Index File List
5518 frame .vpane.files.index
-height 100 -width 200
5519 label .vpane.files.index.title
-text {Changes To Be Committed
} \
5522 text
$ui_index -background white
-borderwidth 0 \
5523 -width 20 -height 10 \
5526 -cursor $cursor_ptr \
5527 -xscrollcommand {.vpane.files.index.sx
set} \
5528 -yscrollcommand {.vpane.files.index.sy
set} \
5530 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
5531 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
5532 pack .vpane.files.index.title
-side top
-fill x
5533 pack .vpane.files.index.sx
-side bottom
-fill x
5534 pack .vpane.files.index.sy
-side right
-fill y
5535 pack
$ui_index -side left
-fill both
-expand 1
5536 .vpane.files add .vpane.files.index
-sticky nsew
5538 # -- Working Directory File List
5540 frame .vpane.files.workdir
-height 100 -width 200
5541 label .vpane.files.workdir.title
-text {Changed But Not Updated
} \
5544 text
$ui_workdir -background white
-borderwidth 0 \
5545 -width 20 -height 10 \
5548 -cursor $cursor_ptr \
5549 -xscrollcommand {.vpane.files.workdir.sx
set} \
5550 -yscrollcommand {.vpane.files.workdir.sy
set} \
5552 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
5553 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
5554 pack .vpane.files.workdir.title
-side top
-fill x
5555 pack .vpane.files.workdir.sx
-side bottom
-fill x
5556 pack .vpane.files.workdir.sy
-side right
-fill y
5557 pack
$ui_workdir -side left
-fill both
-expand 1
5558 .vpane.files add .vpane.files.workdir
-sticky nsew
5560 foreach i
[list
$ui_index $ui_workdir] {
5561 $i tag conf in_diff
-font font_uibold
5562 $i tag conf in_sel \
5563 -background [$i cget
-foreground] \
5564 -foreground [$i cget
-background]
5568 # -- Diff and Commit Area
5570 frame .vpane.lower
-height 300 -width 400
5571 frame .vpane.lower.commarea
5572 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
5573 pack .vpane.lower.commarea
-side top
-fill x
5574 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
5575 .vpane add .vpane.lower
-sticky nsew
5577 # -- Commit Area Buttons
5579 frame .vpane.lower.commarea.buttons
5580 label .vpane.lower.commarea.buttons.l
-text {} \
5584 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
5585 pack .vpane.lower.commarea.buttons
-side left
-fill y
5587 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
5588 -command do_rescan \
5590 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
5591 lappend disable_on_lock \
5592 {.vpane.lower.commarea.buttons.rescan conf
-state}
5594 button .vpane.lower.commarea.buttons.incall
-text {Add Existing
} \
5595 -command do_add_all \
5597 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
5598 lappend disable_on_lock \
5599 {.vpane.lower.commarea.buttons.incall conf
-state}
5601 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
5602 -command do_signoff \
5604 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
5606 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
5607 -command do_commit \
5609 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
5610 lappend disable_on_lock \
5611 {.vpane.lower.commarea.buttons.commit conf
-state}
5613 # -- Commit Message Buffer
5615 frame .vpane.lower.commarea.buffer
5616 frame .vpane.lower.commarea.buffer.header
5617 set ui_comm .vpane.lower.commarea.buffer.t
5618 set ui_coml .vpane.lower.commarea.buffer.header.l
5619 radiobutton .vpane.lower.commarea.buffer.header.new \
5620 -text {New Commit
} \
5621 -command do_select_commit_type \
5622 -variable selected_commit_type \
5625 lappend disable_on_lock \
5626 [list .vpane.lower.commarea.buffer.header.new conf
-state]
5627 radiobutton .vpane.lower.commarea.buffer.header.amend \
5628 -text {Amend Last Commit
} \
5629 -command do_select_commit_type \
5630 -variable selected_commit_type \
5633 lappend disable_on_lock \
5634 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
5639 proc trace_commit_type
{varname args
} {
5640 global ui_coml commit_type
5641 switch
-glob -- $commit_type {
5642 initial
{set txt
{Initial Commit Message
:}}
5643 amend
{set txt
{Amended Commit Message
:}}
5644 amend-initial
{set txt
{Amended Initial Commit Message
:}}
5645 amend-merge
{set txt
{Amended Merge Commit Message
:}}
5646 merge
{set txt
{Merge Commit Message
:}}
5647 * {set txt
{Commit Message
:}}
5649 $ui_coml conf
-text $txt
5651 trace add variable commit_type
write trace_commit_type
5652 pack
$ui_coml -side left
-fill x
5653 pack .vpane.lower.commarea.buffer.header.amend
-side right
5654 pack .vpane.lower.commarea.buffer.header.new
-side right
5656 text
$ui_comm -background white
-borderwidth 1 \
5659 -autoseparators true \
5661 -width 75 -height 9 -wrap none \
5663 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
5664 scrollbar .vpane.lower.commarea.buffer.sby \
5665 -command [list
$ui_comm yview
]
5666 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
5667 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
5668 pack
$ui_comm -side left
-fill y
5669 pack .vpane.lower.commarea.buffer
-side left
-fill y
5671 # -- Commit Message Buffer Context Menu
5673 set ctxm .vpane.lower.commarea.buffer.ctxm
5674 menu
$ctxm -tearoff 0
5678 -command {tk_textCut
$ui_comm}
5682 -command {tk_textCopy
$ui_comm}
5686 -command {tk_textPaste
$ui_comm}
5690 -command {$ui_comm delete sel.first sel.last
}
5693 -label {Select All
} \
5695 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
5700 $ui_comm tag add sel
0.0 end
5701 tk_textCopy
$ui_comm
5702 $ui_comm tag remove sel
0.0 end
5709 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
5713 proc trace_current_diff_path
{varname args
} {
5714 global current_diff_path diff_actions file_states
5715 if {$current_diff_path eq
{}} {
5721 set p
$current_diff_path
5722 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
5724 set p
[escape_path
$p]
5728 .vpane.lower.
diff.header.status configure
-text $s
5729 .vpane.lower.
diff.header.
file configure
-text $f
5730 .vpane.lower.
diff.header.path configure
-text $p
5731 foreach w
$diff_actions {
5735 trace add variable current_diff_path
write trace_current_diff_path
5737 frame .vpane.lower.
diff.header
-background orange
5738 label .vpane.lower.
diff.header.status \
5739 -background orange \
5740 -width $max_status_desc \
5744 label .vpane.lower.
diff.header.
file \
5745 -background orange \
5749 label .vpane.lower.
diff.header.path \
5750 -background orange \
5754 pack .vpane.lower.
diff.header.status
-side left
5755 pack .vpane.lower.
diff.header.
file -side left
5756 pack .vpane.lower.
diff.header.path
-fill x
5757 set ctxm .vpane.lower.
diff.header.ctxm
5758 menu
$ctxm -tearoff 0
5767 -- $current_diff_path
5769 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5770 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
5774 frame .vpane.lower.
diff.body
5775 set ui_diff .vpane.lower.
diff.body.t
5776 text
$ui_diff -background white
-borderwidth 0 \
5777 -width 80 -height 15 -wrap none \
5779 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
5780 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
5782 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
5783 -command [list
$ui_diff xview
]
5784 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
5785 -command [list
$ui_diff yview
]
5786 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
5787 pack .vpane.lower.
diff.body.sby
-side right
-fill y
5788 pack
$ui_diff -side left
-fill both
-expand 1
5789 pack .vpane.lower.
diff.header
-side top
-fill x
5790 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
5792 $ui_diff tag conf d_cr
-elide true
5793 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
5794 $ui_diff tag conf d_
+ -foreground {#00a000}
5795 $ui_diff tag conf d_-
-foreground red
5797 $ui_diff tag conf d_
++ -foreground {#00a000}
5798 $ui_diff tag conf d_--
-foreground red
5799 $ui_diff tag conf d_
+s \
5800 -foreground {#00a000} \
5801 -background {#e2effa}
5802 $ui_diff tag conf d_-s \
5804 -background {#e2effa}
5805 $ui_diff tag conf d_s
+ \
5806 -foreground {#00a000} \
5808 $ui_diff tag conf d_s- \
5812 $ui_diff tag conf d
<<<<<<< \
5813 -foreground orange \
5815 $ui_diff tag conf d
======= \
5816 -foreground orange \
5818 $ui_diff tag conf d
>>>>>>> \
5819 -foreground orange \
5822 $ui_diff tag raise sel
5824 # -- Diff Body Context Menu
5826 set ctxm .vpane.lower.
diff.body.ctxm
5827 menu
$ctxm -tearoff 0
5831 -command reshow_diff
5832 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5836 -command {tk_textCopy
$ui_diff}
5837 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5839 -label {Select All
} \
5841 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
5842 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5847 $ui_diff tag add sel
0.0 end
5848 tk_textCopy
$ui_diff
5849 $ui_diff tag remove sel
0.0 end
5851 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5854 -label {Apply
/Reverse Hunk
} \
5856 -command {apply_hunk
$cursorX $cursorY}
5857 set ui_diff_applyhunk
[$ctxm index last
]
5858 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
5861 -label {Decrease Font Size
} \
5863 -command {incr_font_size font_diff
-1}
5864 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5866 -label {Increase Font Size
} \
5868 -command {incr_font_size font_diff
1}
5869 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5872 -label {Show Less Context
} \
5874 -command {if {$repo_config(gui.diffcontext
) >= 2} {
5875 incr repo_config
(gui.diffcontext
) -1
5878 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5880 -label {Show More Context
} \
5883 incr repo_config
(gui.diffcontext
)
5886 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5888 $ctxm add
command -label {Options...
} \
5891 bind_button3
$ui_diff "
5894 if {\$ui_index eq \$current_diff_side} {
5895 $ctxm entryconf $ui_diff_applyhunk -label {Unstage Hunk From Commit}
5897 $ctxm entryconf $ui_diff_applyhunk -label {Stage Hunk For Commit}
5899 tk_popup $ctxm %X %Y
5901 unset ui_diff_applyhunk
5905 label .status
-textvariable ui_status_value \
5911 pack .status
-anchor w
-side bottom
-fill x
5916 set gm
$repo_config(gui.geometry
)
5917 wm geometry .
[lindex
$gm 0]
5918 .vpane sash place
0 \
5919 [lindex
[.vpane sash coord
0] 0] \
5921 .vpane.files sash place
0 \
5923 [lindex
[.vpane.files sash coord
0] 1]
5929 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
5930 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
5931 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
5932 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
5933 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
5934 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
5935 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
5936 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
5937 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
5938 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5939 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5941 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
5942 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
5943 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
5944 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
5945 bind $ui_diff <$M1B-Key-v> {break}
5946 bind $ui_diff <$M1B-Key-V> {break}
5947 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5948 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5949 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
5950 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
5951 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
5952 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
5953 bind $ui_diff <Button-1
> {focus
%W
}
5955 if {[is_enabled branch
]} {
5956 bind .
<$M1B-Key-n> do_create_branch
5957 bind .
<$M1B-Key-N> do_create_branch
5960 bind all
<Key-F5
> do_rescan
5961 bind all
<$M1B-Key-r> do_rescan
5962 bind all
<$M1B-Key-R> do_rescan
5963 bind .
<$M1B-Key-s> do_signoff
5964 bind .
<$M1B-Key-S> do_signoff
5965 bind .
<$M1B-Key-i> do_add_all
5966 bind .
<$M1B-Key-I> do_add_all
5967 bind .
<$M1B-Key-Return> do_commit
5968 foreach i
[list
$ui_index $ui_workdir] {
5969 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
5970 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
5971 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
5975 set file_lists
($ui_index) [list
]
5976 set file_lists
($ui_workdir) [list
]
5978 wm title .
"[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"
5979 focus
-force $ui_comm
5981 # -- Warn the user about environmental problems. Cygwin's Tcl
5982 # does *not* pass its env array onto any processes it spawns.
5983 # This means that git processes get none of our environment.
5988 set msg
"Possible environment issues exist.
5990 The following environment variables are probably
5991 going to be ignored by any Git subprocess run
5995 foreach name
[array names env
] {
5996 switch
-regexp -- $name {
5997 {^GIT_INDEX_FILE$
} -
5998 {^GIT_OBJECT_DIRECTORY$
} -
5999 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
6001 {^GIT_EXTERNAL_DIFF$
} -
6005 {^GIT_CONFIG_LOCAL$
} -
6006 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
6007 append msg
" - $name\n"
6010 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
6011 append msg
" - $name\n"
6013 set suggest_user
$name
6017 if {$ignored_env > 0} {
6019 This is due to a known issue with the
6020 Tcl binary distributed by Cygwin."
6022 if {$suggest_user ne
{}} {
6025 A good replacement for $suggest_user
6026 is placing values for the user.name and
6027 user.email settings into your personal
6033 unset ignored_env msg suggest_user name
6036 # -- Only initialize complex UI if we are going to stay running.
6038 if {[is_enabled transport
]} {
6042 populate_branch_menu
6047 # -- Only suggest a gc run if we are going to stay running.
6049 if {[is_enabled multicommit
]} {
6050 set object_limit
2000
6051 if {[is_Windows
]} {set object_limit
200}
6052 regexp
{^
([0-9]+) objects
,} [git count-objects
] _junk objects_current
6053 if {$objects_current >= $object_limit} {
6055 "This repository currently has $objects_current loose objects.
6057 To maintain optimal performance it is strongly recommended that you compress the database when more than $object_limit loose objects exist.
6059 Compress the database now?"] eq
yes} {
6063 unset object_limit _junk objects_current
6066 lock_index begin-read