2 # Tcl ignores the next line -*- tcl -*- \
5 set appvers
{@@GITGUI_VERSION@@
}
7 Copyright ©
2006, 2007 Shawn Pearce
, Paul Mackerras.
9 This program is free software
; you can redistribute it and
/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation
; either version
2 of the License
, or
12 (at your option
) any later version.
14 This program is distributed
in the hope that it will be useful
,
15 but WITHOUT ANY WARRANTY
; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License
for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program
; if not
, write to the Free Software
21 Foundation
, Inc.
, 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
}
23 ######################################################################
27 set _appname
[lindex
[file split $argv0] end
]
43 return [eval [concat
[list
file join $_gitdir] $args]]
48 if {$_gitexec eq
{}} {
49 if {[catch
{set _gitexec
[git
--exec-path]} err
]} {
50 error
"Git not installed?\n\n$err"
56 return [eval [concat
[list
file join $_gitexec] $args]]
65 global tcl_platform tk_library
66 if {[tk windowingsystem
] eq
{aqua
}} {
74 if {$tcl_platform(platform
) eq
{windows
}} {
81 global tcl_platform _iscygwin
82 if {$_iscygwin eq
{}} {
83 if {$tcl_platform(platform
) eq
{windows
}} {
84 if {[catch
{set p
[exec cygpath
--windir]} err
]} {
96 proc is_enabled
{option
} {
97 global enabled_options
98 if {[catch
{set on
$enabled_options($option)}]} {return 0}
102 proc enable_option
{option
} {
103 global enabled_options
104 set enabled_options
($option) 1
107 proc disable_option
{option
} {
108 global enabled_options
109 set enabled_options
($option) 0
112 ######################################################################
116 proc is_many_config
{name
} {
117 switch
-glob -- $name {
126 proc is_config_true
{name
} {
128 if {[catch
{set v
$repo_config($name)}]} {
130 } elseif
{$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes}} {
137 proc load_config
{include_global
} {
138 global repo_config global_config default_config
140 array
unset global_config
141 if {$include_global} {
143 set fd_rc
[open
"| git config --global --list" r
]
144 while {[gets
$fd_rc line
] >= 0} {
145 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
146 if {[is_many_config
$name]} {
147 lappend global_config
($name) $value
149 set global_config
($name) $value
157 array
unset repo_config
159 set fd_rc
[open
"| git config --list" r
]
160 while {[gets
$fd_rc line
] >= 0} {
161 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
162 if {[is_many_config
$name]} {
163 lappend repo_config
($name) $value
165 set repo_config
($name) $value
172 foreach name
[array names default_config
] {
173 if {[catch
{set v
$global_config($name)}]} {
174 set global_config
($name) $default_config($name)
176 if {[catch
{set v
$repo_config($name)}]} {
177 set repo_config
($name) $default_config($name)
182 proc save_config
{} {
183 global default_config font_descs
184 global repo_config global_config
185 global repo_config_new global_config_new
187 foreach option
$font_descs {
188 set name
[lindex
$option 0]
189 set font
[lindex
$option 1]
190 font configure
$font \
191 -family $global_config_new(gui.
$font^^family
) \
192 -size $global_config_new(gui.
$font^^size
)
193 font configure
${font}bold \
194 -family $global_config_new(gui.
$font^^family
) \
195 -size $global_config_new(gui.
$font^^size
)
196 set global_config_new
(gui.
$name) [font configure
$font]
197 unset global_config_new
(gui.
$font^^family
)
198 unset global_config_new
(gui.
$font^^size
)
201 foreach name
[array names default_config
] {
202 set value
$global_config_new($name)
203 if {$value ne
$global_config($name)} {
204 if {$value eq
$default_config($name)} {
205 catch
{git config
--global --unset $name}
207 regsub
-all "\[{}\]" $value {"} value
208 git config --global $name $value
210 set global_config($name) $value
211 if {$value eq $repo_config($name)} {
212 catch {git config --unset $name}
213 set repo_config($name) $value
218 foreach name [array names default_config] {
219 set value $repo_config_new($name)
220 if {$value ne $repo_config($name)} {
221 if {$value eq $global_config($name)} {
222 catch {git config --unset $name}
224 regsub -all "\
[{}\
]" $value {"} value
225 git config
$name $value
227 set repo_config
($name) $value
232 ######################################################################
237 return [eval exec git
$args]
240 proc error_popup
{msg
} {
242 if {[reponame
] ne
{}} {
243 append title
" ([reponame])"
245 set cmd
[list tk_messageBox \
248 -title "$title: error" \
250 if {[winfo ismapped .
]} {
251 lappend cmd
-parent .
256 proc warn_popup
{msg
} {
258 if {[reponame
] ne
{}} {
259 append title
" ([reponame])"
261 set cmd
[list tk_messageBox \
264 -title "$title: warning" \
266 if {[winfo ismapped .
]} {
267 lappend cmd
-parent .
272 proc info_popup
{msg
{parent .
}} {
274 if {[reponame
] ne
{}} {
275 append title
" ([reponame])"
285 proc ask_popup
{msg
} {
287 if {[reponame
] ne
{}} {
288 append title
" ([reponame])"
290 return [tk_messageBox \
298 ######################################################################
305 if {[catch
{set v
[git
--version]} err
]} {
306 catch
{wm withdraw .
}
307 error_popup
"Cannot determine Git version:
311 [appname] requires Git $req_maj.$req_min or later."
314 if {[regexp
{^git version
(\d
+)\.
(\d
+)} $v _junk act_maj act_min
]} {
315 if {$act_maj < $req_maj
316 ||
($act_maj == $req_maj && $act_min < $req_min)} {
317 catch
{wm withdraw .
}
318 error_popup
"[appname] requires Git $req_maj.$req_min or later.
324 catch
{wm withdraw .
}
325 error_popup
"Cannot parse Git version string:\n\n$v"
328 unset -nocomplain v _junk act_maj act_min req_maj req_min
330 ######################################################################
334 if { [catch
{set _gitdir
$env(GIT_DIR
)}]
335 && [catch
{set _gitdir
[git rev-parse
--git-dir]} err
]} {
336 catch
{wm withdraw .
}
337 error_popup
"Cannot find the git directory:\n\n$err"
340 if {![file isdirectory
$_gitdir] && [is_Cygwin
]} {
341 catch
{set _gitdir
[exec cygpath
--unix $_gitdir]}
343 if {![file isdirectory
$_gitdir]} {
344 catch
{wm withdraw .
}
345 error_popup
"Git directory not found:\n\n$_gitdir"
348 if {[lindex
[file split $_gitdir] end
] ne
{.git
}} {
349 catch
{wm withdraw .
}
350 error_popup
"Cannot use funny .git directory:\n\n$_gitdir"
353 if {[catch
{cd [file dirname $_gitdir]} err
]} {
354 catch
{wm withdraw .
}
355 error_popup
"No working directory [file dirname $_gitdir]:\n\n$err"
358 set _reponame
[lindex
[file split \
359 [file normalize
[file dirname $_gitdir]]] \
362 ######################################################################
370 set disable_on_lock
[list
]
371 set index_lock_type none
373 proc lock_index
{type} {
374 global index_lock_type disable_on_lock
376 if {$index_lock_type eq
{none
}} {
377 set index_lock_type
$type
378 foreach w
$disable_on_lock {
379 uplevel
#0 $w disabled
382 } elseif
{$index_lock_type eq
"begin-$type"} {
383 set index_lock_type
$type
389 proc unlock_index
{} {
390 global index_lock_type disable_on_lock
392 set index_lock_type none
393 foreach w
$disable_on_lock {
398 ######################################################################
402 proc repository_state
{ctvar hdvar mhvar
} {
403 global current_branch
404 upvar
$ctvar ct
$hdvar hd
$mhvar mh
408 if {[catch
{set current_branch
[git symbolic-ref HEAD
]}]} {
409 set current_branch
{}
411 regsub ^refs
/((heads|tags|remotes
)/)? \
417 if {[catch
{set hd
[git rev-parse
--verify HEAD
]}]} {
423 set merge_head
[gitdir MERGE_HEAD
]
424 if {[file exists
$merge_head]} {
426 set fd_mh
[open
$merge_head r
]
427 while {[gets
$fd_mh line
] >= 0} {
438 global PARENT empty_tree
440 set p
[lindex
$PARENT 0]
444 if {$empty_tree eq
{}} {
445 set empty_tree
[git mktree
<< {}]
450 proc rescan
{after
{honor_trustmtime
1}} {
451 global HEAD PARENT MERGE_HEAD commit_type
452 global ui_index ui_workdir ui_status_value ui_comm
453 global rescan_active file_states
456 if {$rescan_active > 0 ||
![lock_index
read]} return
458 repository_state newType newHEAD newMERGE_HEAD
459 if {[string match amend
* $commit_type]
460 && $newType eq
{normal
}
461 && $newHEAD eq
$HEAD} {
465 set MERGE_HEAD
$newMERGE_HEAD
466 set commit_type
$newType
469 array
unset file_states
471 if {![$ui_comm edit modified
]
472 ||
[string trim
[$ui_comm get
0.0 end
]] eq
{}} {
473 if {[load_message GITGUI_MSG
]} {
474 } elseif
{[load_message MERGE_MSG
]} {
475 } elseif
{[load_message SQUASH_MSG
]} {
478 $ui_comm edit modified false
481 if {[is_enabled branch
]} {
486 if {$honor_trustmtime && $repo_config(gui.trustmtime
) eq
{true
}} {
487 rescan_stage2
{} $after
490 set ui_status_value
{Refreshing
file status...
}
491 set cmd
[list git update-index
]
493 lappend cmd
--unmerged
494 lappend cmd
--ignore-missing
495 lappend cmd
--refresh
496 set fd_rf
[open
"| $cmd" r
]
497 fconfigure
$fd_rf -blocking 0 -translation binary
498 fileevent
$fd_rf readable \
499 [list rescan_stage2
$fd_rf $after]
503 proc rescan_stage2
{fd after
} {
504 global ui_status_value
505 global rescan_active buf_rdi buf_rdf buf_rlo
509 if {![eof
$fd]} return
513 set ls_others
[list | git ls-files
--others -z \
514 --exclude-per-directory=.gitignore
]
515 set info_exclude
[gitdir info exclude
]
516 if {[file readable
$info_exclude]} {
517 lappend ls_others
"--exclude-from=$info_exclude"
525 set ui_status_value
{Scanning
for modified files ...
}
526 set fd_di
[open
"| git diff-index --cached -z [PARENT]" r
]
527 set fd_df
[open
"| git diff-files -z" r
]
528 set fd_lo
[open
$ls_others r
]
530 fconfigure
$fd_di -blocking 0 -translation binary
-encoding binary
531 fconfigure
$fd_df -blocking 0 -translation binary
-encoding binary
532 fconfigure
$fd_lo -blocking 0 -translation binary
-encoding binary
533 fileevent
$fd_di readable
[list read_diff_index
$fd_di $after]
534 fileevent
$fd_df readable
[list read_diff_files
$fd_df $after]
535 fileevent
$fd_lo readable
[list read_ls_others
$fd_lo $after]
538 proc load_message
{file} {
542 if {[file isfile
$f]} {
543 if {[catch
{set fd
[open
$f r
]}]} {
546 set content
[string trim
[read $fd]]
548 regsub
-all -line {[ \r\t]+$
} $content {} content
549 $ui_comm delete
0.0 end
550 $ui_comm insert end
$content
556 proc read_diff_index
{fd after
} {
559 append buf_rdi
[read $fd]
561 set n
[string length
$buf_rdi]
563 set z1
[string first
"\0" $buf_rdi $c]
566 set z2
[string first
"\0" $buf_rdi $z1]
570 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
571 set p
[string range
$buf_rdi $z1 [expr {$z2 - 1}]]
573 [encoding convertfrom
$p] \
575 [list
[lindex
$i 0] [lindex
$i 2]] \
581 set buf_rdi
[string range
$buf_rdi $c end
]
586 rescan_done
$fd buf_rdi
$after
589 proc read_diff_files
{fd after
} {
592 append buf_rdf
[read $fd]
594 set n
[string length
$buf_rdf]
596 set z1
[string first
"\0" $buf_rdf $c]
599 set z2
[string first
"\0" $buf_rdf $z1]
603 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
604 set p
[string range
$buf_rdf $z1 [expr {$z2 - 1}]]
606 [encoding convertfrom
$p] \
609 [list
[lindex
$i 0] [lindex
$i 2]]
614 set buf_rdf
[string range
$buf_rdf $c end
]
619 rescan_done
$fd buf_rdf
$after
622 proc read_ls_others
{fd after
} {
625 append buf_rlo
[read $fd]
626 set pck
[split $buf_rlo "\0"]
627 set buf_rlo
[lindex
$pck end
]
628 foreach p
[lrange
$pck 0 end-1
] {
629 merge_state
[encoding convertfrom
$p] ?O
631 rescan_done
$fd buf_rlo
$after
634 proc rescan_done
{fd buf after
} {
636 global file_states repo_config
639 if {![eof
$fd]} return
642 if {[incr rescan_active
-1] > 0} return
651 proc prune_selection
{} {
652 global file_states selected_paths
654 foreach path
[array names selected_paths
] {
655 if {[catch
{set still_here
$file_states($path)}]} {
656 unset selected_paths
($path)
661 ######################################################################
666 global ui_diff current_diff_path current_diff_header
667 global ui_index ui_workdir
669 $ui_diff conf
-state normal
670 $ui_diff delete
0.0 end
671 $ui_diff conf
-state disabled
673 set current_diff_path
{}
674 set current_diff_header
{}
676 $ui_index tag remove in_diff
0.0 end
677 $ui_workdir tag remove in_diff
0.0 end
680 proc reshow_diff
{} {
681 global ui_status_value file_states file_lists
682 global current_diff_path current_diff_side
684 set p
$current_diff_path
686 ||
$current_diff_side eq
{}
687 ||
[catch
{set s
$file_states($p)}]
688 ||
[lsearch
-sorted -exact $file_lists($current_diff_side) $p] == -1} {
691 show_diff
$p $current_diff_side
695 proc handle_empty_diff
{} {
696 global current_diff_path file_states file_lists
698 set path
$current_diff_path
699 set s
$file_states($path)
700 if {[lindex
$s 0] ne
{_M
}} return
702 info_popup
"No differences detected.
704 [short_path $path] has no changes.
706 The modification date of this file was updated
707 by another application, but the content within
708 the file was not changed.
710 A rescan will be automatically started to find
711 other files which may have the same state."
714 display_file
$path __
715 rescan
{set ui_status_value
{Ready.
}} 0
718 proc show_diff
{path w
{lno
{}}} {
719 global file_states file_lists
720 global is_3way_diff diff_active repo_config
721 global ui_diff ui_status_value ui_index ui_workdir
722 global current_diff_path current_diff_side current_diff_header
724 if {$diff_active ||
![lock_index
read]} return
728 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
734 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
737 set s
$file_states($path)
741 set current_diff_path
$path
742 set current_diff_side
$w
743 set current_diff_header
{}
744 set ui_status_value
"Loading diff of [escape_path $path]..."
746 # - Git won't give us the diff, there's nothing to compare to!
749 set max_sz
[expr {128 * 1024}]
751 set fd
[open
$path r
]
752 set content
[read $fd $max_sz]
754 set sz
[file size
$path]
758 set ui_status_value
"Unable to display [escape_path $path]"
759 error_popup
"Error loading file:\n\n$err"
762 $ui_diff conf
-state normal
763 if {![catch
{set type [exec file $path]}]} {
764 set n
[string length
$path]
765 if {[string equal
-length $n $path $type]} {
766 set type [string range
$type $n end
]
767 regsub
{^
:?\s
*} $type {} type
769 $ui_diff insert end
"* $type\n" d_@
771 if {[string first
"\0" $content] != -1} {
772 $ui_diff insert end \
773 "* Binary file (not showing content)." \
777 $ui_diff insert end \
778 "* Untracked file is $sz bytes.
779 * Showing only first $max_sz bytes.
782 $ui_diff insert end
$content
784 $ui_diff insert end
"
785 * Untracked file clipped here by [appname].
786 * To see the entire file, use an external editor.
790 $ui_diff conf
-state disabled
793 set ui_status_value
{Ready.
}
798 if {$w eq
$ui_index} {
799 lappend cmd diff-index
801 } elseif
{$w eq
$ui_workdir} {
802 if {[string index
$m 0] eq
{U
}} {
805 lappend cmd diff-files
810 lappend cmd
--no-color
811 if {$repo_config(gui.diffcontext
) > 0} {
812 lappend cmd
"-U$repo_config(gui.diffcontext)"
814 if {$w eq
$ui_index} {
820 if {[catch
{set fd
[open
$cmd r
]} err
]} {
823 set ui_status_value
"Unable to display [escape_path $path]"
824 error_popup
"Error loading diff:\n\n$err"
832 fileevent
$fd readable
[list read_diff
$fd]
835 proc read_diff
{fd
} {
836 global ui_diff ui_status_value diff_active
837 global is_3way_diff current_diff_header
839 $ui_diff conf
-state normal
840 while {[gets
$fd line
] >= 0} {
841 # -- Cleanup uninteresting diff header lines.
843 if { [string match
{diff --git *} $line]
844 ||
[string match
{diff --cc *} $line]
845 ||
[string match
{diff --combined *} $line]
846 ||
[string match
{--- *} $line]
847 ||
[string match
{+++ *} $line]} {
848 append current_diff_header
$line "\n"
851 if {[string match
{index
*} $line]} continue
852 if {$line eq
{deleted
file mode
120000}} {
853 set line
"deleted symlink"
856 # -- Automatically detect if this is a 3 way diff.
858 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
860 if {[string match
{mode
*} $line]
861 ||
[string match
{new
file *} $line]
862 ||
[string match
{deleted
file *} $line]
863 ||
[string match
{Binary files
* and
* differ
} $line]
864 ||
$line eq
{\ No newline
at end of
file}
865 ||
[regexp
{^\
* Unmerged path
} $line]} {
867 } elseif
{$is_3way_diff} {
868 set op
[string range
$line 0 1]
878 if {[regexp
{^\
+\
+([<>]{7} |
={7})} $line _g op
]} {
879 set line
[string replace
$line 0 1 { }]
886 puts
"error: Unhandled 3 way diff marker: {$op}"
891 set op
[string index
$line 0]
897 if {[regexp
{^\
+([<>]{7} |
={7})} $line _g op
]} {
898 set line
[string replace
$line 0 0 { }]
905 puts
"error: Unhandled 2 way diff marker: {$op}"
910 $ui_diff insert end
$line $tags
911 if {[string index
$line end
] eq
"\r"} {
912 $ui_diff tag add d_cr
{end
- 2c
}
914 $ui_diff insert end
"\n" $tags
916 $ui_diff conf
-state disabled
922 set ui_status_value
{Ready.
}
924 if {[$ui_diff index end
] eq
{2.0}} {
930 proc apply_hunk
{x y
} {
931 global current_diff_path current_diff_header current_diff_side
932 global ui_diff ui_index file_states
934 if {$current_diff_path eq
{} ||
$current_diff_header eq
{}} return
935 if {![lock_index apply_hunk
]} return
937 set apply_cmd
{git apply
--cached --whitespace=nowarn
}
938 set mi
[lindex
$file_states($current_diff_path) 0]
939 if {$current_diff_side eq
$ui_index} {
941 lappend apply_cmd
--reverse
942 if {[string index
$mi 0] ne
{M
}} {
948 if {[string index
$mi 1] ne
{M
}} {
954 set s_lno
[lindex
[split [$ui_diff index @
$x,$y] .
] 0]
955 set s_lno
[$ui_diff search
-backwards -regexp ^@@
$s_lno.0 0.0]
961 set e_lno
[$ui_diff search
-forwards -regexp ^@@
"$s_lno + 1 lines" end
]
967 set p
[open
"| $apply_cmd" w
]
968 fconfigure
$p -translation binary
-encoding binary
969 puts
-nonewline $p $current_diff_header
970 puts
-nonewline $p [$ui_diff get
$s_lno $e_lno]
972 error_popup
"Failed to $mode selected hunk.\n\n$err"
977 $ui_diff conf
-state normal
978 $ui_diff delete
$s_lno $e_lno
979 $ui_diff conf
-state disabled
981 if {[$ui_diff get
1.0 end
] eq
"\n"} {
987 if {$current_diff_side eq
$ui_index} {
989 } elseif
{[string index
$mi 0] eq
{_
}} {
995 display_file
$current_diff_path $mi
1001 ######################################################################
1005 proc load_last_commit
{} {
1006 global HEAD PARENT MERGE_HEAD commit_type ui_comm
1009 if {[llength
$PARENT] == 0} {
1010 error_popup
{There is nothing to amend.
1012 You are about to create the initial commit.
1013 There is no commit before this to amend.
1018 repository_state curType curHEAD curMERGE_HEAD
1019 if {$curType eq
{merge
}} {
1020 error_popup
{Cannot amend
while merging.
1022 You are currently
in the middle of a merge that
1023 has not been fully completed. You cannot amend
1024 the prior commit unless you first abort the
1025 current merge activity.
1033 set fd
[open
"| git cat-file commit $curHEAD" r
]
1034 fconfigure
$fd -encoding binary
-translation lf
1035 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1038 while {[gets
$fd line
] > 0} {
1039 if {[string match
{parent
*} $line]} {
1040 lappend parents
[string range
$line 7 end
]
1041 } elseif
{[string match
{encoding
*} $line]} {
1042 set enc
[string tolower
[string range
$line 9 end
]]
1045 fconfigure
$fd -encoding $enc
1046 set msg
[string trim
[read $fd]]
1049 error_popup
"Error loading commit data for amend:\n\n$err"
1055 set MERGE_HEAD
[list
]
1056 switch
-- [llength
$parents] {
1057 0 {set commit_type amend-initial
}
1058 1 {set commit_type amend
}
1059 default
{set commit_type amend-merge
}
1062 $ui_comm delete
0.0 end
1063 $ui_comm insert end
$msg
1065 $ui_comm edit modified false
1066 rescan
{set ui_status_value
{Ready.
}}
1069 proc create_new_commit
{} {
1070 global commit_type ui_comm
1072 set commit_type normal
1073 $ui_comm delete
0.0 end
1075 $ui_comm edit modified false
1076 rescan
{set ui_status_value
{Ready.
}}
1079 set GIT_COMMITTER_IDENT
{}
1081 proc committer_ident
{} {
1082 global GIT_COMMITTER_IDENT
1084 if {$GIT_COMMITTER_IDENT eq
{}} {
1085 if {[catch
{set me
[git var GIT_COMMITTER_IDENT
]} err
]} {
1086 error_popup
"Unable to obtain your identity:\n\n$err"
1089 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
1090 $me me GIT_COMMITTER_IDENT
]} {
1091 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
1096 return $GIT_COMMITTER_IDENT
1099 proc commit_tree
{} {
1100 global HEAD commit_type file_states ui_comm repo_config
1101 global ui_status_value pch_error
1103 if {[committer_ident
] eq
{}} return
1104 if {![lock_index update
]} return
1106 # -- Our in memory state should match the repository.
1108 repository_state curType curHEAD curMERGE_HEAD
1109 if {[string match amend
* $commit_type]
1110 && $curType eq
{normal
}
1111 && $curHEAD eq
$HEAD} {
1112 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1113 info_popup
{Last scanned state does not match repository state.
1115 Another Git program has modified this repository
1116 since the last scan. A rescan must be performed
1117 before another commit can be created.
1119 The rescan will be automatically started now.
1122 rescan
{set ui_status_value
{Ready.
}}
1126 # -- At least one file should differ in the index.
1129 foreach path
[array names file_states
] {
1130 switch
-glob -- [lindex
$file_states($path) 0] {
1134 M?
{set files_ready
1}
1136 error_popup
"Unmerged files cannot be committed.
1138 File [short_path $path] has merge conflicts.
1139 You must resolve them and add the file before committing.
1145 error_popup
"Unknown file state [lindex $s 0] detected.
1147 File [short_path $path] cannot be committed by this program.
1152 if {!$files_ready} {
1153 info_popup
{No changes to commit.
1155 You must add
at least
1 file before you can commit.
1161 # -- A message is required.
1163 set msg
[string trim
[$ui_comm get
1.0 end
]]
1164 regsub
-all -line {[ \t\r]+$
} $msg {} msg
1166 error_popup
{Please supply a commit message.
1168 A good commit message has the following format
:
1170 - First line
: Describe
in one sentance what you did.
1171 - Second line
: Blank
1172 - Remaining lines
: Describe why this change is good.
1178 # -- Run the pre-commit hook.
1180 set pchook
[gitdir hooks pre-commit
]
1182 # On Cygwin [file executable] might lie so we need to ask
1183 # the shell if the hook is executable. Yes that's annoying.
1185 if {[is_Cygwin
] && [file isfile
$pchook]} {
1186 set pchook
[list sh
-c [concat \
1187 "if test -x \"$pchook\";" \
1188 "then exec \"$pchook\" 2>&1;" \
1190 } elseif
{[file executable
$pchook]} {
1191 set pchook
[list
$pchook |
& cat]
1193 commit_writetree
$curHEAD $msg
1197 set ui_status_value
{Calling pre-commit hook...
}
1199 set fd_ph
[open
"| $pchook" r
]
1200 fconfigure
$fd_ph -blocking 0 -translation binary
1201 fileevent
$fd_ph readable \
1202 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
1205 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
1206 global pch_error ui_status_value
1208 append pch_error
[read $fd_ph]
1209 fconfigure
$fd_ph -blocking 1
1211 if {[catch
{close
$fd_ph}]} {
1212 set ui_status_value
{Commit declined by pre-commit hook.
}
1213 hook_failed_popup pre-commit
$pch_error
1216 commit_writetree
$curHEAD $msg
1221 fconfigure
$fd_ph -blocking 0
1224 proc commit_writetree
{curHEAD msg
} {
1225 global ui_status_value
1227 set ui_status_value
{Committing changes...
}
1228 set fd_wt
[open
"| git write-tree" r
]
1229 fileevent
$fd_wt readable \
1230 [list commit_committree
$fd_wt $curHEAD $msg]
1233 proc commit_committree
{fd_wt curHEAD msg
} {
1234 global HEAD PARENT MERGE_HEAD commit_type
1235 global all_heads current_branch
1236 global ui_status_value ui_comm selected_commit_type
1237 global file_states selected_paths rescan_active
1241 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1242 error_popup
"write-tree failed:\n\n$err"
1243 set ui_status_value
{Commit failed.
}
1248 # -- Build the message.
1250 set msg_p
[gitdir COMMIT_EDITMSG
]
1251 set msg_wt
[open
$msg_p w
]
1252 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1255 fconfigure
$msg_wt -encoding $enc -translation binary
1256 puts
-nonewline $msg_wt $msg
1259 # -- Create the commit.
1261 set cmd
[list git commit-tree
$tree_id]
1262 set parents
[concat
$PARENT $MERGE_HEAD]
1263 if {[llength
$parents] > 0} {
1264 foreach p
$parents {
1268 # git commit-tree writes to stderr during initial commit.
1269 lappend cmd
2>/dev
/null
1272 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1273 error_popup
"commit-tree failed:\n\n$err"
1274 set ui_status_value
{Commit failed.
}
1279 # -- Update the HEAD ref.
1282 if {$commit_type ne
{normal
}} {
1283 append reflogm
" ($commit_type)"
1285 set i
[string first
"\n" $msg]
1287 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1289 append reflogm
{: } $msg
1291 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1292 if {[catch
{eval exec $cmd} err
]} {
1293 error_popup
"update-ref failed:\n\n$err"
1294 set ui_status_value
{Commit failed.
}
1299 # -- Make sure our current branch exists.
1301 if {$commit_type eq
{initial
}} {
1302 lappend all_heads
$current_branch
1303 set all_heads
[lsort
-unique $all_heads]
1304 populate_branch_menu
1307 # -- Cleanup after ourselves.
1309 catch
{file delete
$msg_p}
1310 catch
{file delete
[gitdir MERGE_HEAD
]}
1311 catch
{file delete
[gitdir MERGE_MSG
]}
1312 catch
{file delete
[gitdir SQUASH_MSG
]}
1313 catch
{file delete
[gitdir GITGUI_MSG
]}
1315 # -- Let rerere do its thing.
1317 if {[file isdirectory
[gitdir rr-cache
]]} {
1321 # -- Run the post-commit hook.
1323 set pchook
[gitdir hooks post-commit
]
1324 if {[is_Cygwin
] && [file isfile
$pchook]} {
1325 set pchook
[list sh
-c [concat \
1326 "if test -x \"$pchook\";" \
1327 "then exec \"$pchook\";" \
1329 } elseif
{![file executable
$pchook]} {
1332 if {$pchook ne
{}} {
1333 catch
{exec $pchook &}
1336 $ui_comm delete
0.0 end
1338 $ui_comm edit modified false
1340 if {[is_enabled singlecommit
]} do_quit
1342 # -- Update in memory status
1344 set selected_commit_type new
1345 set commit_type normal
1348 set MERGE_HEAD
[list
]
1350 foreach path
[array names file_states
] {
1351 set s
$file_states($path)
1353 switch
-glob -- $m {
1361 unset file_states
($path)
1362 catch
{unset selected_paths
($path)}
1365 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1371 set file_states
($path) [list \
1372 _
[string index
$m 1] \
1383 set ui_status_value \
1384 "Changes committed as [string range $cmt_id 0 7]."
1387 ######################################################################
1391 proc fetch_from
{remote
} {
1392 set w
[new_console \
1394 "Fetching new changes from $remote"]
1395 set cmd
[list git fetch
]
1397 console_exec
$w $cmd console_done
1400 proc push_to
{remote
} {
1401 set w
[new_console \
1403 "Pushing changes to $remote"]
1404 set cmd
[list git push
]
1407 console_exec
$w $cmd console_done
1410 ######################################################################
1414 proc mapicon
{w state path
} {
1417 if {[catch
{set r
$all_icons($state$w)}]} {
1418 puts
"error: no icon for $w state={$state} $path"
1424 proc mapdesc
{state path
} {
1427 if {[catch
{set r
$all_descs($state)}]} {
1428 puts
"error: no desc for state={$state} $path"
1434 proc escape_path
{path
} {
1435 regsub
-all {\\} $path "\\\\" path
1436 regsub
-all "\n" $path "\\n" path
1440 proc short_path
{path
} {
1441 return [escape_path
[lindex
[file split $path] end
]]
1445 set null_sha1
[string repeat
0 40]
1447 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1448 global file_states next_icon_id null_sha1
1450 set s0
[string index
$new_state 0]
1451 set s1
[string index
$new_state 1]
1453 if {[catch
{set info
$file_states($path)}]} {
1455 set icon n
[incr next_icon_id
]
1457 set state
[lindex
$info 0]
1458 set icon
[lindex
$info 1]
1459 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1460 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1463 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1464 elseif
{$s0 eq
{_
}} {set s0 _
}
1466 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1467 elseif
{$s1 eq
{_
}} {set s1 _
}
1469 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1470 set head_info
[list
0 $null_sha1]
1471 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1472 && $head_info eq
{}} {
1473 set head_info
$index_info
1476 set file_states
($path) [list
$s0$s1 $icon \
1477 $head_info $index_info \
1482 proc display_file_helper
{w path icon_name old_m new_m
} {
1485 if {$new_m eq
{_
}} {
1486 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1488 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1490 $w conf
-state normal
1491 $w delete
$lno.0 [expr {$lno + 1}].0
1492 $w conf
-state disabled
1494 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1495 lappend file_lists
($w) $path
1496 set file_lists
($w) [lsort
-unique $file_lists($w)]
1497 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1499 $w conf
-state normal
1500 $w image create
$lno.0 \
1501 -align center
-padx 5 -pady 1 \
1503 -image [mapicon
$w $new_m $path]
1504 $w insert
$lno.1 "[escape_path $path]\n"
1505 $w conf
-state disabled
1506 } elseif
{$old_m ne
$new_m} {
1507 $w conf
-state normal
1508 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1509 $w conf
-state disabled
1513 proc display_file
{path state
} {
1514 global file_states selected_paths
1515 global ui_index ui_workdir
1517 set old_m
[merge_state
$path $state]
1518 set s
$file_states($path)
1519 set new_m
[lindex
$s 0]
1520 set icon_name
[lindex
$s 1]
1522 set o
[string index
$old_m 0]
1523 set n
[string index
$new_m 0]
1530 display_file_helper
$ui_index $path $icon_name $o $n
1532 if {[string index
$old_m 0] eq
{U
}} {
1535 set o
[string index
$old_m 1]
1537 if {[string index
$new_m 0] eq
{U
}} {
1540 set n
[string index
$new_m 1]
1542 display_file_helper
$ui_workdir $path $icon_name $o $n
1544 if {$new_m eq
{__
}} {
1545 unset file_states
($path)
1546 catch
{unset selected_paths
($path)}
1550 proc display_all_files_helper
{w path icon_name m
} {
1553 lappend file_lists
($w) $path
1554 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1555 $w image create end \
1556 -align center
-padx 5 -pady 1 \
1558 -image [mapicon
$w $m $path]
1559 $w insert end
"[escape_path $path]\n"
1562 proc display_all_files
{} {
1563 global ui_index ui_workdir
1564 global file_states file_lists
1567 $ui_index conf
-state normal
1568 $ui_workdir conf
-state normal
1570 $ui_index delete
0.0 end
1571 $ui_workdir delete
0.0 end
1574 set file_lists
($ui_index) [list
]
1575 set file_lists
($ui_workdir) [list
]
1577 foreach path
[lsort
[array names file_states
]] {
1578 set s
$file_states($path)
1580 set icon_name
[lindex
$s 1]
1582 set s
[string index
$m 0]
1583 if {$s ne
{U
} && $s ne
{_
}} {
1584 display_all_files_helper
$ui_index $path \
1588 if {[string index
$m 0] eq
{U
}} {
1591 set s
[string index
$m 1]
1594 display_all_files_helper
$ui_workdir $path \
1599 $ui_index conf
-state disabled
1600 $ui_workdir conf
-state disabled
1603 proc update_indexinfo
{msg pathList after
} {
1604 global update_index_cp ui_status_value
1606 if {![lock_index update
]} return
1608 set update_index_cp
0
1609 set pathList
[lsort
$pathList]
1610 set totalCnt
[llength
$pathList]
1611 set batch [expr {int
($totalCnt * .01) + 1}]
1612 if {$batch > 25} {set batch 25}
1614 set ui_status_value
[format \
1615 "$msg... %i/%i files (%.2f%%)" \
1619 set fd
[open
"| git update-index -z --index-info" w
]
1626 fileevent
$fd writable
[list \
1627 write_update_indexinfo \
1637 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1638 global update_index_cp ui_status_value
1639 global file_states current_diff_path
1641 if {$update_index_cp >= $totalCnt} {
1648 for {set i
$batch} \
1649 {$update_index_cp < $totalCnt && $i > 0} \
1651 set path
[lindex
$pathList $update_index_cp]
1652 incr update_index_cp
1654 set s
$file_states($path)
1655 switch
-glob -- [lindex
$s 0] {
1662 set info
[lindex
$s 2]
1663 if {$info eq
{}} continue
1665 puts
-nonewline $fd "$info\t[encoding convertto $path]\0"
1666 display_file
$path $new
1669 set ui_status_value
[format \
1670 "$msg... %i/%i files (%.2f%%)" \
1673 [expr {100.0 * $update_index_cp / $totalCnt}]]
1676 proc update_index
{msg pathList after
} {
1677 global update_index_cp ui_status_value
1679 if {![lock_index update
]} return
1681 set update_index_cp
0
1682 set pathList
[lsort
$pathList]
1683 set totalCnt
[llength
$pathList]
1684 set batch [expr {int
($totalCnt * .01) + 1}]
1685 if {$batch > 25} {set batch 25}
1687 set ui_status_value
[format \
1688 "$msg... %i/%i files (%.2f%%)" \
1692 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1699 fileevent
$fd writable
[list \
1700 write_update_index \
1710 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1711 global update_index_cp ui_status_value
1712 global file_states current_diff_path
1714 if {$update_index_cp >= $totalCnt} {
1721 for {set i
$batch} \
1722 {$update_index_cp < $totalCnt && $i > 0} \
1724 set path
[lindex
$pathList $update_index_cp]
1725 incr update_index_cp
1727 switch
-glob -- [lindex
$file_states($path) 0] {
1733 if {[file exists
$path]} {
1742 puts
-nonewline $fd "[encoding convertto $path]\0"
1743 display_file
$path $new
1746 set ui_status_value
[format \
1747 "$msg... %i/%i files (%.2f%%)" \
1750 [expr {100.0 * $update_index_cp / $totalCnt}]]
1753 proc checkout_index
{msg pathList after
} {
1754 global update_index_cp ui_status_value
1756 if {![lock_index update
]} return
1758 set update_index_cp
0
1759 set pathList
[lsort
$pathList]
1760 set totalCnt
[llength
$pathList]
1761 set batch [expr {int
($totalCnt * .01) + 1}]
1762 if {$batch > 25} {set batch 25}
1764 set ui_status_value
[format \
1765 "$msg... %i/%i files (%.2f%%)" \
1769 set cmd
[list git checkout-index
]
1775 set fd
[open
"| $cmd " w
]
1782 fileevent
$fd writable
[list \
1783 write_checkout_index \
1793 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1794 global update_index_cp ui_status_value
1795 global file_states current_diff_path
1797 if {$update_index_cp >= $totalCnt} {
1804 for {set i
$batch} \
1805 {$update_index_cp < $totalCnt && $i > 0} \
1807 set path
[lindex
$pathList $update_index_cp]
1808 incr update_index_cp
1809 switch
-glob -- [lindex
$file_states($path) 0] {
1813 puts
-nonewline $fd "[encoding convertto $path]\0"
1814 display_file
$path ?_
1819 set ui_status_value
[format \
1820 "$msg... %i/%i files (%.2f%%)" \
1823 [expr {100.0 * $update_index_cp / $totalCnt}]]
1826 ######################################################################
1828 ## branch management
1830 proc is_tracking_branch
{name
} {
1831 global tracking_branches
1833 if {![catch
{set info
$tracking_branches($name)}]} {
1836 foreach t
[array names tracking_branches
] {
1837 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1844 proc load_all_heads
{} {
1847 set all_heads
[list
]
1848 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1849 while {[gets
$fd line
] > 0} {
1850 if {[is_tracking_branch
$line]} continue
1851 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1852 lappend all_heads
$name
1856 set all_heads
[lsort
$all_heads]
1859 proc populate_branch_menu
{} {
1860 global all_heads disable_on_lock
1863 set last
[$m index last
]
1864 for {set i
0} {$i <= $last} {incr i
} {
1865 if {[$m type $i] eq
{separator
}} {
1868 foreach a
$disable_on_lock {
1869 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1873 set disable_on_lock
$new_dol
1878 if {$all_heads ne
{}} {
1881 foreach b
$all_heads {
1882 $m add radiobutton \
1884 -command [list switch_branch
$b] \
1885 -variable current_branch \
1888 lappend disable_on_lock \
1889 [list
$m entryconf
[$m index last
] -state]
1893 proc all_tracking_branches
{} {
1894 global tracking_branches
1896 set all_trackings
{}
1898 foreach name
[array names tracking_branches
] {
1899 if {[regsub
{/\
*$
} $name {} name
]} {
1902 regsub ^refs
/(heads|remotes
)/ $name {} name
1903 lappend all_trackings
$name
1908 set fd
[open
"| git for-each-ref --format=%(refname) $cmd" r
]
1909 while {[gets
$fd name
] > 0} {
1910 regsub ^refs
/(heads|remotes
)/ $name {} name
1911 lappend all_trackings
$name
1916 return [lsort
-unique $all_trackings]
1919 proc load_all_tags
{} {
1921 set fd
[open
"| git for-each-ref --format=%(refname) refs/tags" r
]
1922 while {[gets
$fd line
] > 0} {
1923 if {![regsub ^refs
/tags
/ $line {} name
]} continue
1924 lappend all_tags
$name
1928 return [lsort
$all_tags]
1931 proc do_create_branch_action
{w
} {
1932 global all_heads null_sha1 repo_config
1933 global create_branch_checkout create_branch_revtype
1934 global create_branch_head create_branch_trackinghead
1935 global create_branch_name create_branch_revexp
1936 global create_branch_tag
1938 set newbranch
$create_branch_name
1939 if {$newbranch eq
{}
1940 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1944 -title [wm title
$w] \
1946 -message "Please supply a branch name."
1947 focus
$w.desc.name_t
1950 if {![catch
{git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1954 -title [wm title
$w] \
1956 -message "Branch '$newbranch' already exists."
1957 focus
$w.desc.name_t
1960 if {[catch
{git check-ref-format
"heads/$newbranch"}]} {
1964 -title [wm title
$w] \
1966 -message "We do not like '$newbranch' as a branch name."
1967 focus
$w.desc.name_t
1972 switch
-- $create_branch_revtype {
1973 head {set rev $create_branch_head}
1974 tracking
{set rev $create_branch_trackinghead}
1975 tag
{set rev $create_branch_tag}
1976 expression
{set rev $create_branch_revexp}
1978 if {[catch
{set cmt
[git rev-parse
--verify "${rev}^0"]}]} {
1982 -title [wm title
$w] \
1984 -message "Invalid starting revision: $rev"
1987 set cmd
[list git update-ref
]
1989 lappend cmd
"branch: Created from $rev"
1990 lappend cmd
"refs/heads/$newbranch"
1992 lappend cmd
$null_sha1
1993 if {[catch
{eval exec $cmd} err
]} {
1997 -title [wm title
$w] \
1999 -message "Failed to create '$newbranch'.\n\n$err"
2003 lappend all_heads
$newbranch
2004 set all_heads
[lsort
$all_heads]
2005 populate_branch_menu
2007 if {$create_branch_checkout} {
2008 switch_branch
$newbranch
2012 proc radio_selector
{varname value args
} {
2013 upvar
#0 $varname var
2017 trace add variable create_branch_head
write \
2018 [list radio_selector create_branch_revtype
head]
2019 trace add variable create_branch_trackinghead
write \
2020 [list radio_selector create_branch_revtype tracking
]
2021 trace add variable create_branch_tag
write \
2022 [list radio_selector create_branch_revtype tag
]
2024 trace add variable delete_branch_head
write \
2025 [list radio_selector delete_branch_checktype
head]
2026 trace add variable delete_branch_trackinghead
write \
2027 [list radio_selector delete_branch_checktype tracking
]
2029 proc do_create_branch
{} {
2030 global all_heads current_branch repo_config
2031 global create_branch_checkout create_branch_revtype
2032 global create_branch_head create_branch_trackinghead
2033 global create_branch_name create_branch_revexp
2034 global create_branch_tag
2036 set w .branch_editor
2038 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2040 label
$w.header
-text {Create New Branch
} \
2042 pack
$w.header
-side top
-fill x
2045 button
$w.buttons.create
-text Create \
2048 -command [list do_create_branch_action
$w]
2049 pack
$w.buttons.create
-side right
2050 button
$w.buttons.cancel
-text {Cancel
} \
2052 -command [list destroy
$w]
2053 pack
$w.buttons.cancel
-side right
-padx 5
2054 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2056 labelframe
$w.desc \
2057 -text {Branch Description
} \
2059 label
$w.desc.name_l
-text {Name
:} -font font_ui
2060 entry
$w.desc.name_t \
2064 -textvariable create_branch_name \
2068 if {%d
== 1 && [regexp
{[~^
:?
*\
[\
0- ]} %S
]} {return 0}
2071 grid
$w.desc.name_l
$w.desc.name_t
-sticky we
-padx {0 5}
2072 grid columnconfigure
$w.desc
1 -weight 1
2073 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
2075 labelframe
$w.from \
2076 -text {Starting Revision
} \
2078 radiobutton
$w.from.head_r \
2079 -text {Local Branch
:} \
2081 -variable create_branch_revtype \
2083 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
2084 grid
$w.from.head_r
$w.from.head_m
-sticky w
2085 set all_trackings
[all_tracking_branches
]
2086 if {$all_trackings ne
{}} {
2087 set create_branch_trackinghead
[lindex
$all_trackings 0]
2088 radiobutton
$w.from.tracking_r \
2089 -text {Tracking Branch
:} \
2091 -variable create_branch_revtype \
2093 eval tk_optionMenu
$w.from.tracking_m \
2094 create_branch_trackinghead \
2096 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
2098 set all_tags
[load_all_tags
]
2099 if {$all_tags ne
{}} {
2100 set create_branch_tag
[lindex
$all_tags 0]
2101 radiobutton
$w.from.tag_r \
2104 -variable create_branch_revtype \
2106 eval tk_optionMenu
$w.from.tag_m \
2109 grid
$w.from.tag_r
$w.from.tag_m
-sticky w
2111 radiobutton
$w.from.exp_r \
2112 -text {Revision Expression
:} \
2114 -variable create_branch_revtype \
2116 entry
$w.from.exp_t \
2120 -textvariable create_branch_revexp \
2124 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2125 if {%d
== 1 && [string length
%S
] > 0} {
2126 set create_branch_revtype expression
2130 grid
$w.from.exp_r
$w.from.exp_t
-sticky we
-padx {0 5}
2131 grid columnconfigure
$w.from
1 -weight 1
2132 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
2134 labelframe
$w.postActions \
2135 -text {Post Creation Actions
} \
2137 checkbutton
$w.postActions.checkout \
2138 -text {Checkout after creation
} \
2139 -variable create_branch_checkout \
2141 pack
$w.postActions.checkout
-anchor nw
2142 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
2144 set create_branch_checkout
1
2145 set create_branch_head
$current_branch
2146 set create_branch_revtype
head
2147 set create_branch_name
$repo_config(gui.newbranchtemplate
)
2148 set create_branch_revexp
{}
2150 bind $w <Visibility
> "
2152 $w.desc.name_t icursor end
2153 focus $w.desc.name_t
2155 bind $w <Key-Escape
> "destroy $w"
2156 bind $w <Key-Return
> "do_create_branch_action $w;break"
2157 wm title
$w "[appname] ([reponame]): Create Branch"
2161 proc do_delete_branch_action
{w
} {
2163 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2166 switch
-- $delete_branch_checktype {
2167 head {set check_rev
$delete_branch_head}
2168 tracking
{set check_rev
$delete_branch_trackinghead}
2169 always
{set check_rev
{:none
}}
2171 if {$check_rev eq
{:none
}} {
2173 } elseif
{[catch
{set check_cmt
[git rev-parse
--verify "${check_rev}^0"]}]} {
2177 -title [wm title
$w] \
2179 -message "Invalid check revision: $check_rev"
2183 set to_delete
[list
]
2184 set not_merged
[list
]
2185 foreach i
[$w.list.l curselection
] {
2186 set b
[$w.list.l get
$i]
2187 if {[catch
{set o
[git rev-parse
--verify $b]}]} continue
2188 if {$check_cmt ne
{}} {
2189 if {$b eq
$check_rev} continue
2190 if {[catch
{set m
[git merge-base
$o $check_cmt]}]} continue
2192 lappend not_merged
$b
2196 lappend to_delete
[list
$b $o]
2198 if {$not_merged ne
{}} {
2199 set msg
"The following branches are not completely merged into $check_rev:
2201 - [join $not_merged "\n - "]"
2205 -title [wm title
$w] \
2209 if {$to_delete eq
{}} return
2210 if {$delete_branch_checktype eq
{always
}} {
2211 set msg
{Recovering deleted branches is difficult.
2213 Delete the selected branches?
}
2214 if {[tk_messageBox \
2217 -title [wm title
$w] \
2219 -message $msg] ne
yes} {
2225 foreach i
$to_delete {
2228 if {[catch
{git update-ref
-d "refs/heads/$b" $o} err
]} {
2229 append failed
" - $b: $err\n"
2231 set x
[lsearch
-sorted -exact $all_heads $b]
2233 set all_heads
[lreplace
$all_heads $x $x]
2238 if {$failed ne
{}} {
2242 -title [wm title
$w] \
2244 -message "Failed to delete branches:\n$failed"
2247 set all_heads
[lsort
$all_heads]
2248 populate_branch_menu
2252 proc do_delete_branch
{} {
2253 global all_heads tracking_branches current_branch
2254 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2256 set w .branch_editor
2258 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2260 label
$w.header
-text {Delete Local Branch
} \
2262 pack
$w.header
-side top
-fill x
2265 button
$w.buttons.create
-text Delete \
2267 -command [list do_delete_branch_action
$w]
2268 pack
$w.buttons.create
-side right
2269 button
$w.buttons.cancel
-text {Cancel
} \
2271 -command [list destroy
$w]
2272 pack
$w.buttons.cancel
-side right
-padx 5
2273 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2275 labelframe
$w.list \
2276 -text {Local Branches
} \
2281 -selectmode extended \
2282 -yscrollcommand [list
$w.list.sby
set] \
2284 foreach h
$all_heads {
2285 if {$h ne
$current_branch} {
2286 $w.list.l insert end
$h
2289 scrollbar
$w.list.sby
-command [list
$w.list.l yview
]
2290 pack
$w.list.sby
-side right
-fill y
2291 pack
$w.list.l
-side left
-fill both
-expand 1
2292 pack
$w.list
-fill both
-expand 1 -pady 5 -padx 5
2294 labelframe
$w.validate \
2295 -text {Delete Only If
} \
2297 radiobutton
$w.validate.head_r \
2298 -text {Merged Into Local Branch
:} \
2300 -variable delete_branch_checktype \
2302 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2303 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2304 set all_trackings
[all_tracking_branches
]
2305 if {$all_trackings ne
{}} {
2306 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2307 radiobutton
$w.validate.tracking_r \
2308 -text {Merged Into Tracking Branch
:} \
2310 -variable delete_branch_checktype \
2312 eval tk_optionMenu
$w.validate.tracking_m \
2313 delete_branch_trackinghead \
2315 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2317 radiobutton
$w.validate.always_r \
2318 -text {Always
(Do not perform merge checks
)} \
2320 -variable delete_branch_checktype \
2322 grid
$w.validate.always_r
-columnspan 2 -sticky w
2323 grid columnconfigure
$w.validate
1 -weight 1
2324 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2326 set delete_branch_head
$current_branch
2327 set delete_branch_checktype
head
2329 bind $w <Visibility
> "grab $w; focus $w"
2330 bind $w <Key-Escape
> "destroy $w"
2331 wm title
$w "[appname] ([reponame]): Delete Branch"
2335 proc switch_branch
{new_branch
} {
2336 global HEAD commit_type current_branch repo_config
2338 if {![lock_index switch
]} return
2340 # -- Our in memory state should match the repository.
2342 repository_state curType curHEAD curMERGE_HEAD
2343 if {[string match amend
* $commit_type]
2344 && $curType eq
{normal
}
2345 && $curHEAD eq
$HEAD} {
2346 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2347 info_popup
{Last scanned state does not match repository state.
2349 Another Git program has modified this repository
2350 since the last scan. A rescan must be performed
2351 before the current branch can be changed.
2353 The rescan will be automatically started now.
2356 rescan
{set ui_status_value
{Ready.
}}
2360 # -- Don't do a pointless switch.
2362 if {$current_branch eq
$new_branch} {
2367 if {$repo_config(gui.trustmtime
) eq
{true
}} {
2368 switch_branch_stage2
{} $new_branch
2370 set ui_status_value
{Refreshing
file status...
}
2371 set cmd
[list git update-index
]
2373 lappend cmd
--unmerged
2374 lappend cmd
--ignore-missing
2375 lappend cmd
--refresh
2376 set fd_rf
[open
"| $cmd" r
]
2377 fconfigure
$fd_rf -blocking 0 -translation binary
2378 fileevent
$fd_rf readable \
2379 [list switch_branch_stage2
$fd_rf $new_branch]
2383 proc switch_branch_stage2
{fd_rf new_branch
} {
2384 global ui_status_value HEAD
2388 if {![eof
$fd_rf]} return
2392 set ui_status_value
"Updating working directory to '$new_branch'..."
2393 set cmd
[list git read-tree
]
2396 lappend cmd
--exclude-per-directory=.gitignore
2398 lappend cmd
$new_branch
2399 set fd_rt
[open
"| $cmd" r
]
2400 fconfigure
$fd_rt -blocking 0 -translation binary
2401 fileevent
$fd_rt readable \
2402 [list switch_branch_readtree_wait
$fd_rt $new_branch]
2405 proc switch_branch_readtree_wait
{fd_rt new_branch
} {
2406 global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
2407 global current_branch
2408 global ui_comm ui_status_value
2410 # -- We never get interesting output on stdout; only stderr.
2413 fconfigure
$fd_rt -blocking 1
2414 if {![eof
$fd_rt]} {
2415 fconfigure
$fd_rt -blocking 0
2419 # -- The working directory wasn't in sync with the index and
2420 # we'd have to overwrite something to make the switch. A
2421 # merge is required.
2423 if {[catch
{close
$fd_rt} err
]} {
2424 regsub
{^fatal
: } $err {} err
2425 warn_popup
"File level merge required.
2429 Staying on branch '$current_branch'."
2430 set ui_status_value
"Aborted checkout of '$new_branch' (file level merging is required)."
2435 # -- Update the symbolic ref. Core git doesn't even check for failure
2436 # here, it Just Works(tm). If it doesn't we are in some really ugly
2437 # state that is difficult to recover from within git-gui.
2439 if {[catch
{git symbolic-ref HEAD
"refs/heads/$new_branch"} err
]} {
2440 error_popup
"Failed to set current branch.
2442 This working directory is only partially switched.
2443 We successfully updated your files, but failed to
2444 update an internal Git file.
2446 This should not have occurred. [appname] will now
2454 # -- Update our repository state. If we were previously in amend mode
2455 # we need to toss the current buffer and do a full rescan to update
2456 # our file lists. If we weren't in amend mode our file lists are
2457 # accurate and we can avoid the rescan.
2460 set selected_commit_type new
2461 if {[string match amend
* $commit_type]} {
2462 $ui_comm delete
0.0 end
2464 $ui_comm edit modified false
2465 rescan
{set ui_status_value
"Checked out branch '$current_branch'."}
2467 repository_state commit_type HEAD MERGE_HEAD
2469 set ui_status_value
"Checked out branch '$current_branch'."
2473 ######################################################################
2475 ## remote management
2477 proc load_all_remotes
{} {
2479 global all_remotes tracking_branches
2481 set all_remotes
[list
]
2482 array
unset tracking_branches
2484 set rm_dir
[gitdir remotes
]
2485 if {[file isdirectory
$rm_dir]} {
2486 set all_remotes
[glob \
2490 -directory $rm_dir *]
2492 foreach name
$all_remotes {
2494 set fd
[open
[file join $rm_dir $name] r
]
2495 while {[gets
$fd line
] >= 0} {
2496 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2497 $line line src dst
]} continue
2498 if {![regexp ^refs
/ $dst]} {
2499 set dst
"refs/heads/$dst"
2501 set tracking_branches
($dst) [list
$name $src]
2508 foreach line
[array names repo_config remote.
*.url
] {
2509 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2510 lappend all_remotes
$name
2512 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2516 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2517 if {![regexp ^refs
/ $dst]} {
2518 set dst
"refs/heads/$dst"
2520 set tracking_branches
($dst) [list
$name $src]
2524 set all_remotes
[lsort
-unique $all_remotes]
2527 proc populate_fetch_menu
{} {
2528 global all_remotes repo_config
2531 foreach r
$all_remotes {
2533 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2534 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2539 set fd
[open
[gitdir remotes
$r] r
]
2540 while {[gets
$fd n
] >= 0} {
2541 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2552 -label "Fetch from $r..." \
2553 -command [list fetch_from
$r] \
2559 proc populate_push_menu
{} {
2560 global all_remotes repo_config
2564 foreach r
$all_remotes {
2566 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2567 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2572 set fd
[open
[gitdir remotes
$r] r
]
2573 while {[gets
$fd n
] >= 0} {
2574 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2588 -label "Push to $r..." \
2589 -command [list push_to
$r] \
2596 proc start_push_anywhere_action
{w
} {
2597 global push_urltype push_remote push_url push_thin push_tags
2600 switch
-- $push_urltype {
2601 remote
{set r_url
$push_remote}
2602 url
{set r_url
$push_url}
2604 if {$r_url eq
{}} return
2606 set cmd
[list git push
]
2616 foreach i
[$w.
source.l curselection
] {
2617 set b
[$w.
source.l get
$i]
2618 lappend cmd
"refs/heads/$b:refs/heads/$b"
2623 } elseif
{$cnt == 1} {
2629 set cons
[new_console
"push $r_url" "Pushing $cnt $unit to $r_url"]
2630 console_exec
$cons $cmd console_done
2634 trace add variable push_remote
write \
2635 [list radio_selector push_urltype remote
]
2637 proc do_push_anywhere
{} {
2638 global all_heads all_remotes current_branch
2639 global push_urltype push_remote push_url push_thin push_tags
2643 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2645 label
$w.header
-text {Push Branches
} -font font_uibold
2646 pack
$w.header
-side top
-fill x
2649 button
$w.buttons.create
-text Push \
2651 -command [list start_push_anywhere_action
$w]
2652 pack
$w.buttons.create
-side right
2653 button
$w.buttons.cancel
-text {Cancel
} \
2655 -command [list destroy
$w]
2656 pack
$w.buttons.cancel
-side right
-padx 5
2657 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2659 labelframe
$w.
source \
2660 -text {Source Branches
} \
2662 listbox
$w.
source.l \
2665 -selectmode extended \
2666 -yscrollcommand [list
$w.
source.sby
set] \
2668 foreach h
$all_heads {
2669 $w.
source.l insert end
$h
2670 if {$h eq
$current_branch} {
2671 $w.
source.l
select set end
2674 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2675 pack
$w.
source.sby
-side right
-fill y
2676 pack
$w.
source.l
-side left
-fill both
-expand 1
2677 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2679 labelframe
$w.dest \
2680 -text {Destination Repository
} \
2682 if {$all_remotes ne
{}} {
2683 radiobutton
$w.dest.remote_r \
2686 -variable push_urltype \
2688 eval tk_optionMenu
$w.dest.remote_m push_remote
$all_remotes
2689 grid
$w.dest.remote_r
$w.dest.remote_m
-sticky w
2690 if {[lsearch
-sorted -exact $all_remotes origin
] != -1} {
2691 set push_remote origin
2693 set push_remote
[lindex
$all_remotes 0]
2695 set push_urltype remote
2697 set push_urltype url
2699 radiobutton
$w.dest.url_r \
2700 -text {Arbitrary URL
:} \
2702 -variable push_urltype \
2704 entry
$w.dest.url_t \
2708 -textvariable push_url \
2712 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2713 if {%d
== 1 && [string length
%S
] > 0} {
2714 set push_urltype url
2718 grid
$w.dest.url_r
$w.dest.url_t
-sticky we
-padx {0 5}
2719 grid columnconfigure
$w.dest
1 -weight 1
2720 pack
$w.dest
-anchor nw
-fill x
-pady 5 -padx 5
2722 labelframe
$w.options \
2723 -text {Transfer Options
} \
2725 checkbutton
$w.options.thin \
2726 -text {Use thin pack
(for slow network connections
)} \
2727 -variable push_thin \
2729 grid
$w.options.thin
-columnspan 2 -sticky w
2730 checkbutton
$w.options.tags \
2731 -text {Include tags
} \
2732 -variable push_tags \
2734 grid
$w.options.tags
-columnspan 2 -sticky w
2735 grid columnconfigure
$w.options
1 -weight 1
2736 pack
$w.options
-anchor nw
-fill x
-pady 5 -padx 5
2742 bind $w <Visibility
> "grab $w"
2743 bind $w <Key-Escape
> "destroy $w"
2744 wm title
$w "[appname] ([reponame]): Push"
2748 ######################################################################
2753 global HEAD commit_type file_states
2755 if {[string match amend
* $commit_type]} {
2756 info_popup
{Cannot merge
while amending.
2758 You must finish amending this commit before
2759 starting any
type of merge.
2764 if {[committer_ident
] eq
{}} {return 0}
2765 if {![lock_index merge
]} {return 0}
2767 # -- Our in memory state should match the repository.
2769 repository_state curType curHEAD curMERGE_HEAD
2770 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2771 info_popup
{Last scanned state does not match repository state.
2773 Another Git program has modified this repository
2774 since the last scan. A rescan must be performed
2775 before a merge can be performed.
2777 The rescan will be automatically started now.
2780 rescan
{set ui_status_value
{Ready.
}}
2784 foreach path
[array names file_states
] {
2785 switch
-glob -- [lindex
$file_states($path) 0] {
2787 continue; # and pray it works!
2790 error_popup
"You are in the middle of a conflicted merge.
2792 File [short_path $path] has merge conflicts.
2794 You must resolve them, add the file, and commit to
2795 complete the current merge. Only then can you
2796 begin another merge.
2802 error_popup
"You are in the middle of a change.
2804 File [short_path $path] is modified.
2806 You should complete the current commit before
2807 starting a merge. Doing so will help you abort
2808 a failed merge, should the need arise.
2819 proc visualize_local_merge
{w
} {
2821 foreach i
[$w.
source.l curselection
] {
2822 lappend revs
[$w.
source.l get
$i]
2824 if {$revs eq
{}} return
2825 lappend revs
--not HEAD
2829 proc start_local_merge_action
{w
} {
2830 global HEAD ui_status_value current_branch
2832 set cmd
[list git merge
]
2835 foreach i
[$w.
source.l curselection
] {
2836 set b
[$w.
source.l get
$i]
2844 } elseif
{$revcnt == 1} {
2846 } elseif
{$revcnt <= 15} {
2852 -title [wm title
$w] \
2854 -message "Too many branches selected.
2856 You have requested to merge $revcnt branches
2857 in an octopus merge. This exceeds Git's
2858 internal limit of 15 branches per merge.
2860 Please select fewer branches. To merge more
2861 than 15 branches, merge the branches in batches.
2866 set msg
"Merging $current_branch, [join $names {, }]"
2867 set ui_status_value
"$msg..."
2868 set cons
[new_console
"Merge" $msg]
2869 console_exec
$cons $cmd [list finish_merge
$revcnt]
2870 bind $w <Destroy
> {}
2874 proc finish_merge
{revcnt w ok
} {
2877 set msg
{Merge completed successfully.
}
2880 info_popup
"Octopus merge failed.
2882 Your merge of $revcnt branches has failed.
2884 There are file-level conflicts between the
2885 branches which must be resolved manually.
2887 The working directory will now be reset.
2889 You can attempt this merge again
2890 by merging only one branch at a time." $w
2892 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2893 fconfigure
$fd -blocking 0 -translation binary
2894 fileevent
$fd readable
[list reset_hard_wait
$fd]
2895 set ui_status_value
{Aborting... please
wait...
}
2899 set msg
{Merge failed. Conflict resolution is required.
}
2902 rescan
[list
set ui_status_value
$msg]
2905 proc do_local_merge
{} {
2906 global current_branch
2908 if {![can_merge
]} return
2912 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2915 -text "Merge Into $current_branch" \
2917 pack
$w.header
-side top
-fill x
2920 button
$w.buttons.visualize
-text Visualize \
2922 -command [list visualize_local_merge
$w]
2923 pack
$w.buttons.visualize
-side left
2924 button
$w.buttons.create
-text Merge \
2926 -command [list start_local_merge_action
$w]
2927 pack
$w.buttons.create
-side right
2928 button
$w.buttons.cancel
-text {Cancel
} \
2930 -command [list destroy
$w]
2931 pack
$w.buttons.cancel
-side right
-padx 5
2932 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2934 labelframe
$w.
source \
2935 -text {Source Branches
} \
2937 listbox
$w.
source.l \
2940 -selectmode extended \
2941 -yscrollcommand [list
$w.
source.sby
set] \
2943 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2944 pack
$w.
source.sby
-side right
-fill y
2945 pack
$w.
source.l
-side left
-fill both
-expand 1
2946 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2948 set cmd
[list git for-each-ref
]
2949 lappend cmd
{--format=%(objectname
) %(*objectname
) %(refname
)}
2950 lappend cmd refs
/heads
2951 lappend cmd refs
/remotes
2952 lappend cmd refs
/tags
2953 set fr_fd
[open
"| $cmd" r
]
2954 fconfigure
$fr_fd -translation binary
2955 while {[gets
$fr_fd line
] > 0} {
2956 set line
[split $line { }]
2957 set sha1
([lindex
$line 0]) [lindex
$line 2]
2958 set sha1
([lindex
$line 1]) [lindex
$line 2]
2963 set fr_fd
[open
"| git rev-list --all --not HEAD"]
2964 while {[gets
$fr_fd line
] > 0} {
2965 if {[catch
{set ref
$sha1($line)}]} continue
2966 regsub ^refs
/(heads|remotes|tags
)/ $ref {} ref
2967 lappend to_show
$ref
2971 foreach ref
[lsort
-unique $to_show] {
2972 $w.
source.l insert end
$ref
2975 bind $w <Visibility
> "grab $w"
2976 bind $w <Key-Escape
> "unlock_index;destroy $w"
2977 bind $w <Destroy
> unlock_index
2978 wm title
$w "[appname] ([reponame]): Merge"
2982 proc do_reset_hard
{} {
2983 global HEAD commit_type file_states
2985 if {[string match amend
* $commit_type]} {
2986 info_popup
{Cannot abort
while amending.
2988 You must finish amending this commit.
2993 if {![lock_index abort
]} return
2995 if {[string match
*merge
* $commit_type]} {
3001 if {[ask_popup
"Abort $op?
3003 Aborting the current $op will cause
3004 *ALL* uncommitted changes to be lost.
3006 Continue with aborting the current $op?"] eq
{yes}} {
3007 set fd
[open
"| git read-tree --reset -u HEAD" r
]
3008 fconfigure
$fd -blocking 0 -translation binary
3009 fileevent
$fd readable
[list reset_hard_wait
$fd]
3010 set ui_status_value
{Aborting... please
wait...
}
3016 proc reset_hard_wait
{fd
} {
3024 $ui_comm delete
0.0 end
3025 $ui_comm edit modified false
3027 catch
{file delete
[gitdir MERGE_HEAD
]}
3028 catch
{file delete
[gitdir rr-cache MERGE_RR
]}
3029 catch
{file delete
[gitdir SQUASH_MSG
]}
3030 catch
{file delete
[gitdir MERGE_MSG
]}
3031 catch
{file delete
[gitdir GITGUI_MSG
]}
3033 rescan
{set ui_status_value
{Abort completed. Ready.
}}
3037 ######################################################################
3041 set next_browser_id
0
3043 proc new_browser
{commit
} {
3044 global next_browser_id cursor_ptr M1B
3045 global browser_commit browser_status browser_stack browser_path browser_busy
3047 if {[winfo ismapped .
]} {
3048 set w .browser
[incr next_browser_id
]
3055 set w_list
$w.list.l
3056 set browser_commit
($w_list) $commit
3057 set browser_status
($w_list) {Starting...
}
3058 set browser_stack
($w_list) {}
3059 set browser_path
($w_list) $browser_commit($w_list):
3060 set browser_busy
($w_list) 1
3062 label
$w.path
-textvariable browser_path
($w_list) \
3068 pack
$w.path
-anchor w
-side top
-fill x
3071 text
$w_list -background white
-borderwidth 0 \
3072 -cursor $cursor_ptr \
3077 -xscrollcommand [list
$w.list.sbx
set] \
3078 -yscrollcommand [list
$w.list.sby
set] \
3080 $w_list tag conf in_sel \
3081 -background [$w_list cget
-foreground] \
3082 -foreground [$w_list cget
-background]
3083 scrollbar
$w.list.sbx
-orient h
-command [list
$w_list xview
]
3084 scrollbar
$w.list.sby
-orient v
-command [list
$w_list yview
]
3085 pack
$w.list.sbx
-side bottom
-fill x
3086 pack
$w.list.sby
-side right
-fill y
3087 pack
$w_list -side left
-fill both
-expand 1
3088 pack
$w.list
-side top
-fill both
-expand 1
3090 label
$w.status
-textvariable browser_status
($w_list) \
3096 pack
$w.status
-anchor w
-side bottom
-fill x
3098 bind $w_list <Button-1
> "browser_click 0 $w_list @%x,%y;break"
3099 bind $w_list <Double-Button-1
> "browser_click 1 $w_list @%x,%y;break"
3100 bind $w_list <$M1B-Up> "browser_parent $w_list;break"
3101 bind $w_list <$M1B-Left> "browser_parent $w_list;break"
3102 bind $w_list <Up
> "browser_move -1 $w_list;break"
3103 bind $w_list <Down
> "browser_move 1 $w_list;break"
3104 bind $w_list <$M1B-Right> "browser_enter $w_list;break"
3105 bind $w_list <Return
> "browser_enter $w_list;break"
3106 bind $w_list <Prior
> "browser_page -1 $w_list;break"
3107 bind $w_list <Next
> "browser_page 1 $w_list;break"
3108 bind $w_list <Left
> break
3109 bind $w_list <Right
> break
3111 bind $tl <Visibility
> "focus $w"
3112 bind $tl <Destroy
> "
3113 array unset browser_buffer $w_list
3114 array unset browser_files $w_list
3115 array unset browser_status $w_list
3116 array unset browser_stack $w_list
3117 array unset browser_path $w_list
3118 array unset browser_commit $w_list
3119 array unset browser_busy $w_list
3121 wm title
$tl "[appname] ([reponame]): File Browser"
3122 ls_tree
$w_list $browser_commit($w_list) {}
3125 proc browser_move
{dir w
} {
3126 global browser_files browser_busy
3128 if {$browser_busy($w)} return
3129 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3131 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3132 $w tag remove in_sel
0.0 end
3133 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3138 proc browser_page
{dir w
} {
3139 global browser_files browser_busy
3141 if {$browser_busy($w)} return
3142 $w yview scroll
$dir pages
3144 [lindex
[$w yview
] 0]
3145 * [llength
$browser_files($w)]
3147 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3148 $w tag remove in_sel
0.0 end
3149 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3154 proc browser_parent
{w
} {
3155 global browser_files browser_status browser_path
3156 global browser_stack browser_busy
3158 if {$browser_busy($w)} return
3159 set info
[lindex
$browser_files($w) 0]
3160 if {[lindex
$info 0] eq
{parent
}} {
3161 set parent
[lindex
$browser_stack($w) end-1
]
3162 set browser_stack
($w) [lrange
$browser_stack($w) 0 end-2
]
3163 if {$browser_stack($w) eq
{}} {
3164 regsub
{:.
*$
} $browser_path($w) {:} browser_path
($w)
3166 regsub
{/[^
/]+$
} $browser_path($w) {} browser_path
($w)
3168 set browser_status
($w) "Loading $browser_path($w)..."
3169 ls_tree
$w [lindex
$parent 0] [lindex
$parent 1]
3173 proc browser_enter
{w
} {
3174 global browser_files browser_status browser_path
3175 global browser_commit browser_stack browser_busy
3177 if {$browser_busy($w)} return
3178 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3179 set info
[lindex
$browser_files($w) [expr {$lno - 1}]]
3181 switch
-- [lindex
$info 0] {
3186 set name
[lindex
$info 2]
3187 set escn
[escape_path
$name]
3188 set browser_status
($w) "Loading $escn..."
3189 append browser_path
($w) $escn
3190 ls_tree
$w [lindex
$info 1] $name
3193 set name
[lindex
$info 2]
3195 foreach n
$browser_stack($w) {
3196 append p
[lindex
$n 1]
3199 show_blame
$browser_commit($w) $p
3205 proc browser_click
{was_double_click w pos
} {
3206 global browser_files browser_busy
3208 if {$browser_busy($w)} return
3209 set lno
[lindex
[split [$w index
$pos] .
] 0]
3212 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3213 $w tag remove in_sel
0.0 end
3214 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3215 if {$was_double_click} {
3221 proc ls_tree
{w tree_id name
} {
3222 global browser_buffer browser_files browser_stack browser_busy
3224 set browser_buffer
($w) {}
3225 set browser_files
($w) {}
3226 set browser_busy
($w) 1
3228 $w conf
-state normal
3229 $w tag remove in_sel
0.0 end
3231 if {$browser_stack($w) ne
{}} {
3232 $w image create end \
3233 -align center
-padx 5 -pady 1 \
3236 $w insert end
{[Up To Parent
]}
3237 lappend browser_files
($w) parent
3239 lappend browser_stack
($w) [list
$tree_id $name]
3240 $w conf
-state disabled
3242 set cmd
[list git ls-tree
-z $tree_id]
3243 set fd
[open
"| $cmd" r
]
3244 fconfigure
$fd -blocking 0 -translation binary
-encoding binary
3245 fileevent
$fd readable
[list read_ls_tree
$fd $w]
3248 proc read_ls_tree
{fd w
} {
3249 global browser_buffer browser_files browser_status browser_busy
3251 if {![winfo exists
$w]} {
3256 append browser_buffer
($w) [read $fd]
3257 set pck
[split $browser_buffer($w) "\0"]
3258 set browser_buffer
($w) [lindex
$pck end
]
3260 set n
[llength
$browser_files($w)]
3261 $w conf
-state normal
3262 foreach p
[lrange
$pck 0 end-1
] {
3263 set info
[split $p "\t"]
3264 set path
[lindex
$info 1]
3265 set info
[split [lindex
$info 0] { }]
3266 set type [lindex
$info 1]
3267 set object
[lindex
$info 2]
3278 set image file_question
3282 if {$n > 0} {$w insert end
"\n"}
3283 $w image create end \
3284 -align center
-padx 5 -pady 1 \
3285 -name icon
[incr n
] \
3287 $w insert end
[escape_path
$path]
3288 lappend browser_files
($w) [list
$type $object $path]
3290 $w conf
-state disabled
3294 set browser_status
($w) Ready.
3295 set browser_busy
($w) 0
3296 array
unset browser_buffer
$w
3298 $w tag add in_sel
1.0 2.0
3304 proc show_blame
{commit path
} {
3305 global next_browser_id blame_status blame_data
3307 if {[winfo ismapped .
]} {
3308 set w .browser
[incr next_browser_id
]
3315 set blame_status
($w) {Loading current
file content...
}
3317 label
$w.path
-text "$commit:$path" \
3323 pack
$w.path
-side top
-fill x
3326 text
$w.out.loaded_t \
3327 -background white
-borderwidth 0 \
3333 $w.out.loaded_t tag conf annotated
-background grey
3335 text
$w.out.linenumber_t \
3336 -background white
-borderwidth 0 \
3342 $w.out.linenumber_t tag conf linenumber
-justify right
3344 text
$w.out.file_t \
3345 -background white
-borderwidth 0 \
3350 -xscrollcommand [list
$w.out.sbx
set] \
3353 scrollbar
$w.out.sbx
-orient h
-command [list
$w.out.file_t xview
]
3354 scrollbar
$w.out.sby
-orient v \
3355 -command [list scrollbar2many
[list \
3357 $w.out.linenumber_t \
3361 $w.out.linenumber_t \
3366 grid conf
$w.out.sbx
-column 2 -sticky we
3367 grid columnconfigure
$w.out
2 -weight 1
3368 grid rowconfigure
$w.out
0 -weight 1
3369 pack
$w.out
-fill both
-expand 1
3371 label
$w.status
-textvariable blame_status
($w) \
3377 pack
$w.status
-side bottom
-fill x
3381 -background white
-borderwidth 0 \
3386 -xscrollcommand [list
$w.cm.sbx
set] \
3387 -yscrollcommand [list
$w.cm.sby
set] \
3389 scrollbar
$w.cm.sbx
-orient h
-command [list
$w.cm.t xview
]
3390 scrollbar
$w.cm.sby
-orient v
-command [list
$w.cm.t yview
]
3391 pack
$w.cm.sby
-side right
-fill y
3392 pack
$w.cm.sbx
-side bottom
-fill x
3393 pack
$w.cm.t
-expand 1 -fill both
3394 pack
$w.cm
-side bottom
-fill x
3396 menu
$w.ctxm
-tearoff 0
3397 $w.ctxm add
command -label "Copy Commit" \
3399 -command "blame_copycommit $w \$cursorW @\$cursorX,\$cursorY"
3403 $w.out.linenumber_t \
3405 $i tag conf in_sel \
3406 -background [$i cget
-foreground] \
3407 -foreground [$i cget
-background]
3408 $i conf
-yscrollcommand \
3409 [list many2scrollbar
[list \
3411 $w.out.linenumber_t \
3414 bind $i <Button-1
> "
3417 $w.out.linenumber_t \\
3426 tk_popup $w.ctxm %X %Y
3430 bind $w.cm.t
<Button-1
> "focus $w.cm.t"
3431 bind $tl <Visibility
> "focus $tl"
3432 bind $tl <Destroy
> "
3433 array unset blame_status {$w}
3434 array unset blame_data $w,*
3436 wm title
$tl "[appname] ([reponame]): File Viewer"
3438 set blame_data
($w,commit_count
) 0
3439 set blame_data
($w,commit_list
) {}
3440 set blame_data
($w,total_lines
) 0
3441 set blame_data
($w,blame_lines
) 0
3442 set blame_data
($w,highlight_commit
) {}
3443 set blame_data
($w,highlight_line
) -1
3445 set cmd
[list git cat-file blob
"$commit:$path"]
3446 set fd
[open
"| $cmd" r
]
3447 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3448 fileevent
$fd readable
[list read_blame_catfile \
3449 $fd $w $commit $path \
3450 $w.cm.t
$w.out.loaded_t
$w.out.linenumber_t
$w.out.file_t
]
3453 proc read_blame_catfile
{fd w commit path w_cmit w_load w_line w_file
} {
3454 global blame_status blame_data
3456 if {![winfo exists
$w_file]} {
3461 set n
$blame_data($w,total_lines
)
3462 $w_load conf
-state normal
3463 $w_line conf
-state normal
3464 $w_file conf
-state normal
3465 while {[gets
$fd line
] >= 0} {
3466 regsub
"\r\$" $line {} line
3468 $w_load insert end
"\n"
3469 $w_line insert end
"$n\n" linenumber
3470 $w_file insert end
"$line\n"
3472 $w_load conf
-state disabled
3473 $w_line conf
-state disabled
3474 $w_file conf
-state disabled
3475 set blame_data
($w,total_lines
) $n
3479 blame_incremental_status
$w
3480 set cmd
[list git blame
-M -C --incremental]
3481 lappend cmd
$commit -- $path
3482 set fd
[open
"| $cmd" r
]
3483 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3484 fileevent
$fd readable
[list read_blame_incremental
$fd $w \
3485 $w_load $w_cmit $w_line $w_file]
3489 proc read_blame_incremental
{fd w w_load w_cmit w_line w_file
} {
3490 global blame_status blame_data
3492 if {![winfo exists
$w_file]} {
3497 while {[gets
$fd line
] >= 0} {
3498 if {[regexp
{^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$
} $line line \
3499 cmit original_line final_line line_count
]} {
3500 set blame_data
($w,commit
) $cmit
3501 set blame_data
($w,original_line
) $original_line
3502 set blame_data
($w,final_line
) $final_line
3503 set blame_data
($w,line_count
) $line_count
3505 if {[catch
{set g
$blame_data($w,$cmit,order
)}]} {
3506 $w_line tag conf g
$cmit
3507 $w_file tag conf g
$cmit
3508 $w_line tag raise in_sel
3509 $w_file tag raise in_sel
3510 $w_file tag raise sel
3511 set blame_data
($w,$cmit,order
) $blame_data($w,commit_count
)
3512 incr blame_data
($w,commit_count
)
3513 lappend blame_data
($w,commit_list
) $cmit
3515 } elseif
{[string match
{filename
*} $line]} {
3516 set file [string range
$line 9 end
]
3517 set n
$blame_data($w,line_count
)
3518 set lno
$blame_data($w,final_line
)
3519 set cmit
$blame_data($w,commit
)
3522 if {[catch
{set g g
$blame_data($w,line
$lno,commit
)}]} {
3523 $w_load tag add annotated
$lno.0 "$lno.0 lineend + 1c"
3525 $w_line tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3526 $w_file tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3529 set blame_data
($w,line
$lno,commit
) $cmit
3530 set blame_data
($w,line
$lno,file) $file
3531 $w_line tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3532 $w_file tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3534 if {$blame_data($w,highlight_line
) == -1} {
3535 if {[lindex
[$w_file yview
] 0] == 0} {
3537 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3539 } elseif
{$blame_data($w,highlight_line
) == $lno} {
3540 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3545 incr blame_data
($w,blame_lines
)
3548 set hc
$blame_data($w,highlight_commit
)
3550 && [expr {$blame_data($w,$hc,order
) + 1}]
3551 == $blame_data($w,$cmit,order
)} {
3552 blame_showcommit
$w $w_cmit $w_line $w_file \
3553 $blame_data($w,highlight_line
)
3555 } elseif
{[regexp
{^
([a-z-
]+) (.
*)$
} $line line header data
]} {
3556 set blame_data
($w,$blame_data($w,commit
),$header) $data
3562 set blame_status
($w) {Annotation complete.
}
3564 blame_incremental_status
$w
3568 proc blame_incremental_status
{w
} {
3569 global blame_status blame_data
3571 set blame_status
($w) [format \
3572 "Loading annotations... %i of %i lines annotated (%2i%%)" \
3573 $blame_data($w,blame_lines
) \
3574 $blame_data($w,total_lines
) \
3575 [expr {100 * $blame_data($w,blame_lines
)
3576 / $blame_data($w,total_lines
)}]]
3579 proc blame_click
{w w_cmit w_line w_file cur_w pos
} {
3580 set lno
[lindex
[split [$cur_w index
$pos] .
] 0]
3581 if {$lno eq
{}} return
3583 $w_line tag remove in_sel
0.0 end
3584 $w_file tag remove in_sel
0.0 end
3585 $w_line tag add in_sel
$lno.0 "$lno.0 + 1 line"
3586 $w_file tag add in_sel
$lno.0 "$lno.0 + 1 line"
3588 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3597 proc blame_showcommit
{w w_cmit w_line w_file lno
} {
3598 global blame_colors blame_data repo_config
3600 set cmit
$blame_data($w,highlight_commit
)
3602 set idx
$blame_data($w,$cmit,order
)
3604 foreach c
$blame_colors {
3605 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3606 $w_line tag conf g
$h -background white
3607 $w_file tag conf g
$h -background white
3612 $w_cmit conf
-state normal
3613 $w_cmit delete
0.0 end
3614 if {[catch
{set cmit
$blame_data($w,line
$lno,commit
)}]} {
3616 $w_cmit insert end
"Loading annotation..."
3618 set idx
$blame_data($w,$cmit,order
)
3620 foreach c
$blame_colors {
3621 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3622 $w_line tag conf g
$h -background $c
3623 $w_file tag conf g
$h -background $c
3627 if {[catch
{set msg
$blame_data($w,$cmit,message
)}]} {
3630 set fd
[open
"| git cat-file commit $cmit" r
]
3631 fconfigure
$fd -encoding binary
-translation lf
3632 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
3635 while {[gets
$fd line
] > 0} {
3636 if {[string match
{encoding
*} $line]} {
3637 set enc
[string tolower
[string range
$line 9 end
]]
3640 fconfigure
$fd -encoding $enc
3641 set msg
[string trim
[read $fd]]
3644 set blame_data
($w,$cmit,message
) $msg
3650 catch
{set author_name
$blame_data($w,$cmit,author
)}
3651 catch
{set author_email
$blame_data($w,$cmit,author-mail
)}
3652 catch
{set author_time
[clock format
$blame_data($w,$cmit,author-time
)]}
3654 set committer_name
{}
3655 set committer_email
{}
3656 set committer_time
{}
3657 catch
{set committer_name
$blame_data($w,$cmit,committer
)}
3658 catch
{set committer_email
$blame_data($w,$cmit,committer-mail
)}
3659 catch
{set committer_time
[clock format
$blame_data($w,$cmit,committer-time
)]}
3661 $w_cmit insert end
"commit $cmit\n"
3662 $w_cmit insert end
"Author: $author_name $author_email $author_time\n"
3663 $w_cmit insert end
"Committer: $committer_name $committer_email $committer_time\n"
3664 $w_cmit insert end
"Original File: [escape_path $blame_data($w,line$lno,file)]\n"
3665 $w_cmit insert end
"\n"
3666 $w_cmit insert end
$msg
3668 $w_cmit conf
-state disabled
3670 set blame_data
($w,highlight_line
) $lno
3671 set blame_data
($w,highlight_commit
) $cmit
3674 proc blame_copycommit
{w i pos
} {
3676 set lno
[lindex
[split [$i index
$pos] .
] 0]
3677 if {![catch
{set commit
$blame_data($w,line
$lno,commit
)}]} {
3686 ######################################################################
3691 #define mask_width 14
3692 #define mask_height 15
3693 static unsigned char mask_bits
[] = {
3694 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3695 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3696 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
3699 image create bitmap file_plain
-background white
-foreground black
-data {
3700 #define plain_width 14
3701 #define plain_height 15
3702 static unsigned char plain_bits
[] = {
3703 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3704 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
3705 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3706 } -maskdata $filemask
3708 image create bitmap file_mod
-background white
-foreground blue
-data {
3709 #define mod_width 14
3710 #define mod_height 15
3711 static unsigned char mod_bits
[] = {
3712 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3713 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3714 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3715 } -maskdata $filemask
3717 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
3718 #define file_fulltick_width 14
3719 #define file_fulltick_height 15
3720 static unsigned char file_fulltick_bits
[] = {
3721 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
3722 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
3723 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3724 } -maskdata $filemask
3726 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
3727 #define parttick_width 14
3728 #define parttick_height 15
3729 static unsigned char parttick_bits
[] = {
3730 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3731 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
3732 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3733 } -maskdata $filemask
3735 image create bitmap file_question
-background white
-foreground black
-data {
3736 #define file_question_width 14
3737 #define file_question_height 15
3738 static unsigned char file_question_bits
[] = {
3739 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
3740 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
3741 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3742 } -maskdata $filemask
3744 image create bitmap file_removed
-background white
-foreground red
-data {
3745 #define file_removed_width 14
3746 #define file_removed_height 15
3747 static unsigned char file_removed_bits
[] = {
3748 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3749 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
3750 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
3751 } -maskdata $filemask
3753 image create bitmap file_merge
-background white
-foreground blue
-data {
3754 #define file_merge_width 14
3755 #define file_merge_height 15
3756 static unsigned char file_merge_bits
[] = {
3757 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
3758 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3759 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3760 } -maskdata $filemask
3763 #define file_width 18
3764 #define file_height 18
3765 static unsigned char file_bits
[] = {
3766 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00,
3767 0x0c, 0x03, 0x00, 0x04, 0xfe, 0x00, 0x06, 0x80, 0x00, 0xff, 0x9f, 0x00,
3768 0x03, 0x98, 0x00, 0x02, 0x90, 0x00, 0x06, 0xb0, 0x00, 0x04, 0xa0, 0x00,
3769 0x0c, 0xe0, 0x00, 0x08, 0xc0, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
3770 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3772 image create bitmap file_dir
-background white
-foreground blue \
3773 -data $file_dir_data -maskdata $file_dir_data
3776 set file_uplevel_data
{
3778 #define up_height 15
3779 static unsigned char up_bits
[] = {
3780 0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f,
3781 0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
3782 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
3784 image create bitmap file_uplevel
-background white
-foreground red \
3785 -data $file_uplevel_data -maskdata $file_uplevel_data
3786 unset file_uplevel_data
3788 set ui_index .vpane.files.index.list
3789 set ui_workdir .vpane.files.workdir.list
3791 set all_icons
(_
$ui_index) file_plain
3792 set all_icons
(A
$ui_index) file_fulltick
3793 set all_icons
(M
$ui_index) file_fulltick
3794 set all_icons
(D
$ui_index) file_removed
3795 set all_icons
(U
$ui_index) file_merge
3797 set all_icons
(_
$ui_workdir) file_plain
3798 set all_icons
(M
$ui_workdir) file_mod
3799 set all_icons
(D
$ui_workdir) file_question
3800 set all_icons
(U
$ui_workdir) file_merge
3801 set all_icons
(O
$ui_workdir) file_plain
3803 set max_status_desc
0
3807 {_M
"Modified, not staged"}
3808 {M_
"Staged for commit"}
3809 {MM
"Portions staged for commit"}
3810 {MD
"Staged for commit, missing"}
3812 {_O
"Untracked, not staged"}
3813 {A_
"Staged for commit"}
3814 {AM
"Portions staged for commit"}
3815 {AD
"Staged for commit, missing"}
3818 {D_
"Staged for removal"}
3819 {DO
"Staged for removal, still present"}
3821 {U_
"Requires merge resolution"}
3822 {UU
"Requires merge resolution"}
3823 {UM
"Requires merge resolution"}
3824 {UD
"Requires merge resolution"}
3826 if {$max_status_desc < [string length
[lindex
$i 1]]} {
3827 set max_status_desc
[string length
[lindex
$i 1]]
3829 set all_descs
([lindex
$i 0]) [lindex
$i 1]
3833 ######################################################################
3837 proc bind_button3
{w cmd
} {
3838 bind $w <Any-Button-3
> $cmd
3840 bind $w <Control-Button-1
> $cmd
3844 proc scrollbar2many
{list mode args
} {
3845 foreach w
$list {eval $w $mode $args}
3848 proc many2scrollbar
{list mode sb top bottom
} {
3849 $sb set $top $bottom
3850 foreach w
$list {$w $mode moveto
$top}
3853 proc incr_font_size
{font
{amt
1}} {
3854 set sz
[font configure
$font -size]
3856 font configure
$font -size $sz
3857 font configure
${font}bold
-size $sz
3860 proc hook_failed_popup
{hook msg
} {
3865 label
$w.m.l1
-text "$hook hook failed:" \
3870 -background white
-borderwidth 1 \
3872 -width 80 -height 10 \
3874 -yscrollcommand [list
$w.m.sby
set]
3876 -text {You must correct the above errors before committing.
} \
3880 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3881 pack
$w.m.l1
-side top
-fill x
3882 pack
$w.m.l2
-side bottom
-fill x
3883 pack
$w.m.sby
-side right
-fill y
3884 pack
$w.m.t
-side left
-fill both
-expand 1
3885 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3887 $w.m.t insert
1.0 $msg
3888 $w.m.t conf
-state disabled
3890 button
$w.ok
-text OK \
3893 -command "destroy $w"
3894 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3896 bind $w <Visibility
> "grab $w; focus $w"
3897 bind $w <Key-Return
> "destroy $w"
3898 wm title
$w "[appname] ([reponame]): error"
3902 set next_console_id
0
3904 proc new_console
{short_title long_title
} {
3905 global next_console_id console_data
3906 set w .console
[incr next_console_id
]
3907 set console_data
($w) [list
$short_title $long_title]
3908 return [console_init
$w]
3911 proc console_init
{w
} {
3912 global console_cr console_data M1B
3914 set console_cr
($w) 1.0
3917 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
3922 -background white
-borderwidth 1 \
3924 -width 80 -height 10 \
3927 -yscrollcommand [list
$w.m.sby
set]
3928 label
$w.m.s
-text {Working... please
wait...
} \
3932 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3933 pack
$w.m.l1
-side top
-fill x
3934 pack
$w.m.s
-side bottom
-fill x
3935 pack
$w.m.sby
-side right
-fill y
3936 pack
$w.m.t
-side left
-fill both
-expand 1
3937 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3939 menu
$w.ctxm
-tearoff 0
3940 $w.ctxm add
command -label "Copy" \
3942 -command "tk_textCopy $w.m.t"
3943 $w.ctxm add
command -label "Select All" \
3945 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
3946 $w.ctxm add
command -label "Copy All" \
3949 $w.m.t tag add sel 0.0 end
3951 $w.m.t tag remove sel 0.0 end
3954 button
$w.ok
-text {Close
} \
3957 -command "destroy $w"
3958 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3960 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
3961 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
3962 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
3963 bind $w <Visibility
> "focus $w"
3964 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
3968 proc console_exec
{w cmd after
} {
3969 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
3970 # But most users need that so we have to relogin. :-(
3973 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
3976 # -- Tcl won't let us redirect both stdout and stderr to
3977 # the same pipe. So pass it through cat...
3979 set cmd
[concat |
$cmd |
& cat]
3981 set fd_f
[open
$cmd r
]
3982 fconfigure
$fd_f -blocking 0 -translation binary
3983 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
3986 proc console_read
{w fd after
} {
3991 if {![winfo exists
$w]} {console_init
$w}
3992 $w.m.t conf
-state normal
3994 set n
[string length
$buf]
3996 set cr
[string first
"\r" $buf $c]
3997 set lf
[string first
"\n" $buf $c]
3998 if {$cr < 0} {set cr
[expr {$n + 1}]}
3999 if {$lf < 0} {set lf
[expr {$n + 1}]}
4002 $w.m.t insert end
[string range
$buf $c $lf]
4003 set console_cr
($w) [$w.m.t index
{end
-1c}]
4007 $w.m.t delete
$console_cr($w) end
4008 $w.m.t insert end
"\n"
4009 $w.m.t insert end
[string range
$buf $c $cr]
4014 $w.m.t conf
-state disabled
4018 fconfigure
$fd -blocking 1
4020 if {[catch
{close
$fd}]} {
4025 uplevel
#0 $after $w $ok
4028 fconfigure
$fd -blocking 0
4031 proc console_chain
{cmdlist w
{ok
1}} {
4033 if {[llength
$cmdlist] == 0} {
4038 set cmd
[lindex
$cmdlist 0]
4039 set cmdlist
[lrange
$cmdlist 1 end
]
4041 if {[lindex
$cmd 0] eq
{console_exec
}} {
4044 [list console_chain
$cmdlist]
4046 uplevel
#0 $cmd $cmdlist $w $ok
4053 proc console_done
{args
} {
4054 global console_cr console_data
4056 switch
-- [llength
$args] {
4058 set w
[lindex
$args 0]
4059 set ok
[lindex
$args 1]
4062 set w
[lindex
$args 1]
4063 set ok
[lindex
$args 2]
4066 error
"wrong number of args: console_done ?ignored? w ok"
4071 if {[winfo exists
$w]} {
4072 $w.m.s conf
-background green
-text {Success
}
4073 $w.ok conf
-state normal
4076 if {![winfo exists
$w]} {
4079 $w.m.s conf
-background red
-text {Error
: Command Failed
}
4080 $w.ok conf
-state normal
4083 array
unset console_cr
$w
4084 array
unset console_data
$w
4087 ######################################################################
4091 set starting_gitk_msg
{Starting gitk... please
wait...
}
4093 proc do_gitk
{revs
} {
4094 global env ui_status_value starting_gitk_msg
4096 # -- Always start gitk through whatever we were loaded with. This
4097 # lets us bypass using shell process on Windows systems.
4099 set cmd
[info nameofexecutable
]
4100 lappend cmd
[gitexec gitk
]
4106 if {[catch
{eval exec $cmd &} err
]} {
4107 error_popup
"Failed to start gitk:\n\n$err"
4109 set ui_status_value
$starting_gitk_msg
4111 if {$ui_status_value eq
$starting_gitk_msg} {
4112 set ui_status_value
{Ready.
}
4119 set fd
[open
"| git count-objects -v" r
]
4120 while {[gets
$fd line
] > 0} {
4121 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
4122 set stats
($name) $value
4128 foreach p
[glob
-directory [gitdir objects pack
] \
4131 incr packed_sz
[file size
$p]
4133 if {$packed_sz > 0} {
4134 set stats
(size-pack
) [expr {$packed_sz / 1024}]
4139 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4141 label
$w.header
-text {Database Statistics
} \
4143 pack
$w.header
-side top
-fill x
4145 frame
$w.buttons
-border 1
4146 button
$w.buttons.close
-text Close \
4148 -command [list destroy
$w]
4149 button
$w.buttons.gc
-text {Compress Database
} \
4151 -command "destroy $w;do_gc"
4152 pack
$w.buttons.close
-side right
4153 pack
$w.buttons.gc
-side left
4154 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4156 frame
$w.stat
-borderwidth 1 -relief solid
4158 {count
{Number of loose objects
}}
4159 {size
{Disk space used by loose objects
} { KiB
}}
4160 {in-pack
{Number of packed objects
}}
4161 {packs
{Number of packs
}}
4162 {size-pack
{Disk space used by packed objects
} { KiB
}}
4163 {prune-packable
{Packed objects waiting
for pruning
}}
4164 {garbage
{Garbage files
}}
4166 set name
[lindex
$s 0]
4167 set label
[lindex
$s 1]
4168 if {[catch
{set value
$stats($name)}]} continue
4169 if {[llength
$s] > 2} {
4170 set value
"$value[lindex $s 2]"
4173 label
$w.stat.l_
$name -text "$label:" -anchor w
-font font_ui
4174 label
$w.stat.v_
$name -text $value -anchor w
-font font_ui
4175 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
4177 pack
$w.stat
-pady 10 -padx 10
4179 bind $w <Visibility
> "grab $w; focus $w"
4180 bind $w <Key-Escape
> [list destroy
$w]
4181 bind $w <Key-Return
> [list destroy
$w]
4182 wm title
$w "[appname] ([reponame]): Database Statistics"
4187 set w
[new_console
{gc
} {Compressing the object database
}]
4189 {console_exec
{git pack-refs
--prune}}
4190 {console_exec
{git reflog expire
--all}}
4191 {console_exec
{git repack
-a -d -l}}
4192 {console_exec
{git rerere gc
}}
4196 proc do_fsck_objects
{} {
4197 set w
[new_console
{fsck-objects
} \
4198 {Verifying the object database with fsck-objects
}]
4199 set cmd
[list git fsck-objects
]
4202 lappend cmd
--strict
4203 console_exec
$w $cmd console_done
4209 global ui_comm is_quitting repo_config commit_type
4211 if {$is_quitting} return
4214 if {[winfo exists
$ui_comm]} {
4215 # -- Stash our current commit buffer.
4217 set save
[gitdir GITGUI_MSG
]
4218 set msg
[string trim
[$ui_comm get
0.0 end
]]
4219 regsub
-all -line {[ \r\t]+$
} $msg {} msg
4220 if {(![string match amend
* $commit_type]
4221 ||
[$ui_comm edit modified
])
4224 set fd
[open
$save w
]
4225 puts
-nonewline $fd $msg
4229 catch
{file delete
$save}
4232 # -- Stash our current window geometry into this repository.
4234 set cfg_geometry
[list
]
4235 lappend cfg_geometry
[wm geometry .
]
4236 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
4237 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
4238 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
4241 if {$cfg_geometry ne
$rc_geometry} {
4242 catch
{git config gui.geometry
$cfg_geometry}
4250 rescan
{set ui_status_value
{Ready.
}}
4253 proc unstage_helper
{txt paths
} {
4254 global file_states current_diff_path
4256 if {![lock_index begin-update
]} return
4260 foreach path
$paths {
4261 switch
-glob -- [lindex
$file_states($path) 0] {
4265 lappend pathList
$path
4266 if {$path eq
$current_diff_path} {
4267 set after
{reshow_diff
;}
4272 if {$pathList eq
{}} {
4278 [concat
$after {set ui_status_value
{Ready.
}}]
4282 proc do_unstage_selection
{} {
4283 global current_diff_path selected_paths
4285 if {[array size selected_paths
] > 0} {
4287 {Unstaging selected files from commit
} \
4288 [array names selected_paths
]
4289 } elseif
{$current_diff_path ne
{}} {
4291 "Unstaging [short_path $current_diff_path] from commit" \
4292 [list
$current_diff_path]
4296 proc add_helper
{txt paths
} {
4297 global file_states current_diff_path
4299 if {![lock_index begin-update
]} return
4303 foreach path
$paths {
4304 switch
-glob -- [lindex
$file_states($path) 0] {
4309 lappend pathList
$path
4310 if {$path eq
$current_diff_path} {
4311 set after
{reshow_diff
;}
4316 if {$pathList eq
{}} {
4322 [concat
$after {set ui_status_value
{Ready to commit.
}}]
4326 proc do_add_selection
{} {
4327 global current_diff_path selected_paths
4329 if {[array size selected_paths
] > 0} {
4331 {Adding selected files
} \
4332 [array names selected_paths
]
4333 } elseif
{$current_diff_path ne
{}} {
4335 "Adding [short_path $current_diff_path]" \
4336 [list
$current_diff_path]
4340 proc do_add_all
{} {
4344 foreach path
[array names file_states
] {
4345 switch
-glob -- [lindex
$file_states($path) 0] {
4348 ?D
{lappend paths
$path}
4351 add_helper
{Adding all changed files
} $paths
4354 proc revert_helper
{txt paths
} {
4355 global file_states current_diff_path
4357 if {![lock_index begin-update
]} return
4361 foreach path
$paths {
4362 switch
-glob -- [lindex
$file_states($path) 0] {
4366 lappend pathList
$path
4367 if {$path eq
$current_diff_path} {
4368 set after
{reshow_diff
;}
4374 set n
[llength
$pathList]
4378 } elseif
{$n == 1} {
4379 set s
"[short_path [lindex $pathList]]"
4381 set s
"these $n files"
4384 set reply
[tk_dialog \
4386 "[appname] ([reponame])" \
4387 "Revert changes in $s?
4389 Any unadded changes will be permanently lost by the revert." \
4399 [concat
$after {set ui_status_value
{Ready.
}}]
4405 proc do_revert_selection
{} {
4406 global current_diff_path selected_paths
4408 if {[array size selected_paths
] > 0} {
4410 {Reverting selected files
} \
4411 [array names selected_paths
]
4412 } elseif
{$current_diff_path ne
{}} {
4414 "Reverting [short_path $current_diff_path]" \
4415 [list
$current_diff_path]
4419 proc do_signoff
{} {
4422 set me
[committer_ident
]
4423 if {$me eq
{}} return
4425 set sob
"Signed-off-by: $me"
4426 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
4427 if {$last ne
$sob} {
4428 $ui_comm edit separator
4430 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
4431 $ui_comm insert end
"\n"
4433 $ui_comm insert end
"\n$sob"
4434 $ui_comm edit separator
4439 proc do_select_commit_type
{} {
4440 global commit_type selected_commit_type
4442 if {$selected_commit_type eq
{new
}
4443 && [string match amend
* $commit_type]} {
4445 } elseif
{$selected_commit_type eq
{amend
}
4446 && ![string match amend
* $commit_type]} {
4449 # The amend request was rejected...
4451 if {![string match amend
* $commit_type]} {
4452 set selected_commit_type new
4462 global appvers copyright
4463 global tcl_patchLevel tk_patchLevel
4467 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4469 label
$w.header
-text "About [appname]" \
4471 pack
$w.header
-side top
-fill x
4474 button
$w.buttons.close
-text {Close
} \
4476 -command [list destroy
$w]
4477 pack
$w.buttons.close
-side right
4478 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4481 -text "git-gui - a commit creation tool for Git.
4489 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
4492 append v
"git-gui version $appvers\n"
4493 append v
"[git version]\n"
4495 if {$tcl_patchLevel eq
$tk_patchLevel} {
4496 append v
"Tcl/Tk version $tcl_patchLevel"
4498 append v
"Tcl version $tcl_patchLevel"
4499 append v
", Tk version $tk_patchLevel"
4510 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
4512 menu
$w.ctxm
-tearoff 0
4513 $w.ctxm add
command \
4518 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
4521 bind $w <Visibility
> "grab $w; focus $w"
4522 bind $w <Key-Escape
> "destroy $w"
4523 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
4524 wm title
$w "About [appname]"
4528 proc do_options
{} {
4529 global repo_config global_config font_descs
4530 global repo_config_new global_config_new
4532 array
unset repo_config_new
4533 array
unset global_config_new
4534 foreach name
[array names repo_config
] {
4535 set repo_config_new
($name) $repo_config($name)
4538 foreach name
[array names repo_config
] {
4540 gui.diffcontext
{continue}
4542 set repo_config_new
($name) $repo_config($name)
4544 foreach name
[array names global_config
] {
4545 set global_config_new
($name) $global_config($name)
4548 set w .options_editor
4550 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4552 label
$w.header
-text "Options" \
4554 pack
$w.header
-side top
-fill x
4557 button
$w.buttons.restore
-text {Restore Defaults
} \
4559 -command do_restore_defaults
4560 pack
$w.buttons.restore
-side left
4561 button
$w.buttons.save
-text Save \
4563 -command [list do_save_config
$w]
4564 pack
$w.buttons.save
-side right
4565 button
$w.buttons.cancel
-text {Cancel
} \
4567 -command [list destroy
$w]
4568 pack
$w.buttons.cancel
-side right
-padx 5
4569 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4571 labelframe
$w.repo
-text "[reponame] Repository" \
4573 labelframe
$w.global
-text {Global
(All Repositories
)} \
4575 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
4576 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
4580 {t user.name
{User Name
}}
4581 {t user.email
{Email Address
}}
4583 {b merge.summary
{Summarize Merge Commits
}}
4584 {i-1.
.5 merge.verbosity
{Merge Verbosity
}}
4586 {b gui.trustmtime
{Trust File Modification Timestamps
}}
4587 {i-1.
.99 gui.diffcontext
{Number of Diff Context Lines
}}
4588 {t gui.newbranchtemplate
{New Branch Name Template
}}
4590 set type [lindex
$option 0]
4591 set name
[lindex
$option 1]
4592 set text
[lindex
$option 2]
4594 foreach f
{repo global
} {
4595 switch
-glob -- $type {
4597 checkbutton
$w.
$f.
$optid -text $text \
4598 -variable ${f}_config_new
($name) \
4602 pack
$w.
$f.
$optid -side top
-anchor w
4605 regexp
-- {-(\d
+)\.\.
(\d
+)$
} $type _junk min max
4607 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4608 pack
$w.
$f.
$optid.l
-side left
-anchor w
-fill x
4609 spinbox
$w.
$f.
$optid.v \
4610 -textvariable ${f}_config_new
($name) \
4614 -width [expr {1 + [string length
$max]}] \
4616 bind $w.
$f.
$optid.v
<FocusIn
> {%W selection range
0 end
}
4617 pack
$w.
$f.
$optid.v
-side right
-anchor e
-padx 5
4618 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4622 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4623 entry
$w.
$f.
$optid.v \
4627 -textvariable ${f}_config_new
($name) \
4629 pack
$w.
$f.
$optid.l
-side left
-anchor w
4630 pack
$w.
$f.
$optid.v
-side left
-anchor w \
4633 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4639 set all_fonts
[lsort
[font families
]]
4640 foreach option
$font_descs {
4641 set name
[lindex
$option 0]
4642 set font
[lindex
$option 1]
4643 set text
[lindex
$option 2]
4645 set global_config_new
(gui.
$font^^family
) \
4646 [font configure
$font -family]
4647 set global_config_new
(gui.
$font^^size
) \
4648 [font configure
$font -size]
4650 frame
$w.global.
$name
4651 label
$w.global.
$name.l
-text "$text:" -font font_ui
4652 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
4653 eval tk_optionMenu
$w.global.
$name.family \
4654 global_config_new
(gui.
$font^^family
) \
4656 spinbox
$w.global.
$name.size \
4657 -textvariable global_config_new
(gui.
$font^^size
) \
4658 -from 2 -to 80 -increment 1 \
4661 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
4662 pack
$w.global.
$name.size
-side right
-anchor e
4663 pack
$w.global.
$name.family
-side right
-anchor e
4664 pack
$w.global.
$name -side top
-anchor w
-fill x
4667 bind $w <Visibility
> "grab $w; focus $w"
4668 bind $w <Key-Escape
> "destroy $w"
4669 wm title
$w "[appname] ([reponame]): Options"
4673 proc do_restore_defaults
{} {
4674 global font_descs default_config repo_config
4675 global repo_config_new global_config_new
4677 foreach name
[array names default_config
] {
4678 set repo_config_new
($name) $default_config($name)
4679 set global_config_new
($name) $default_config($name)
4682 foreach option
$font_descs {
4683 set name
[lindex
$option 0]
4684 set repo_config
(gui.
$name) $default_config(gui.
$name)
4688 foreach option
$font_descs {
4689 set name
[lindex
$option 0]
4690 set font
[lindex
$option 1]
4691 set global_config_new
(gui.
$font^^family
) \
4692 [font configure
$font -family]
4693 set global_config_new
(gui.
$font^^size
) \
4694 [font configure
$font -size]
4698 proc do_save_config
{w
} {
4699 if {[catch
{save_config
} err
]} {
4700 error_popup
"Failed to completely save options:\n\n$err"
4706 proc do_windows_shortcut
{} {
4709 set fn
[tk_getSaveFile \
4711 -title "[appname] ([reponame]): Create Desktop Icon" \
4712 -initialfile "Git [reponame].bat"]
4716 puts
$fd "@ECHO Entering [reponame]"
4717 puts
$fd "@ECHO Starting git-gui... please wait..."
4718 puts
$fd "@SET PATH=[file normalize [gitexec]];%PATH%"
4719 puts
$fd "@SET GIT_DIR=[file normalize [gitdir]]"
4720 puts
-nonewline $fd "@\"[info nameofexecutable]\""
4721 puts
$fd " \"[file normalize $argv0]\""
4724 error_popup
"Cannot write script:\n\n$err"
4729 proc do_cygwin_shortcut
{} {
4733 set desktop
[exec cygpath \
4741 set fn
[tk_getSaveFile \
4743 -title "[appname] ([reponame]): Create Desktop Icon" \
4744 -initialdir $desktop \
4745 -initialfile "Git [reponame].bat"]
4749 set sh
[exec cygpath \
4753 set me
[exec cygpath \
4757 set gd
[exec cygpath \
4761 set gw
[exec cygpath \
4764 [file dirname [gitdir
]]]
4765 regsub
-all ' $me "'\\''" me
4766 regsub -all ' $gd "'\\''" gd
4767 puts $fd "@ECHO Entering $gw"
4768 puts $fd "@ECHO Starting git-gui... please wait..."
4769 puts -nonewline $fd "@\"$sh\" --login -c \""
4770 puts -nonewline $fd "GIT_DIR='$gd'"
4771 puts -nonewline $fd " '$me'"
4775 error_popup "Cannot write script:\n\n$err"
4780 proc do_macosx_app {} {
4783 set fn [tk_getSaveFile \
4785 -title "[appname] ([reponame]): Create Desktop Icon" \
4786 -initialdir [file join $env(HOME) Desktop] \
4787 -initialfile "Git [reponame].app"]
4790 set Contents [file join $fn Contents]
4791 set MacOS [file join $Contents MacOS]
4792 set exe [file join $MacOS git-gui]
4796 set fd [open [file join $Contents Info.plist] w]
4797 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
4798 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4799 <plist version="1.0">
4801 <key>CFBundleDevelopmentRegion</key>
4802 <string>English</string>
4803 <key>CFBundleExecutable</key>
4804 <string>git-gui</string>
4805 <key>CFBundleIdentifier</key>
4806 <string>org.spearce.git-gui</string>
4807 <key>CFBundleInfoDictionaryVersion</key>
4808 <string>6.0</string>
4809 <key>CFBundlePackageType</key>
4810 <string>APPL</string>
4811 <key>CFBundleSignature</key>
4812 <string>????</string>
4813 <key>CFBundleVersion</key>
4814 <string>1.0</string>
4815 <key>NSPrincipalClass</key>
4816 <string>NSApplication</string>
4821 set fd [open $exe w]
4822 set gd [file normalize [gitdir]]
4823 set ep [file normalize [gitexec]]
4824 regsub -all ' $gd "'\\''" gd
4825 regsub
-all ' $ep "'\\''" ep
4826 puts $fd "#!/bin/sh"
4827 foreach name
[array names env
] {
4828 if {[string match GIT_
* $name]} {
4829 regsub
-all ' $env($name) "'\\''" v
4830 puts $fd "export $name='$v'"
4833 puts $fd "export PATH
='$ep':\
$PATH"
4834 puts $fd "export GIT_DIR
='$gd'"
4835 puts $fd "exec [file normalize
$argv0]"
4838 file attributes $exe -permissions u+x,g+x,o+x
4840 error_popup "Cannot
write icon
:\n\n$err"
4845 proc toggle_or_diff {w x y} {
4846 global file_states file_lists current_diff_path ui_index ui_workdir
4847 global last_clicked selected_paths
4849 set pos [split [$w index @$x,$y] .]
4850 set lno [lindex $pos 0]
4851 set col [lindex $pos 1]
4852 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4858 set last_clicked [list $w $lno]
4859 array unset selected_paths
4860 $ui_index tag remove in_sel 0.0 end
4861 $ui_workdir tag remove in_sel 0.0 end
4864 if {$current_diff_path eq $path} {
4865 set after {reshow_diff;}
4869 if {$w eq $ui_index} {
4871 "Unstaging
[short_path
$path] from commit
" \
4873 [concat $after {set ui_status_value {Ready.}}]
4874 } elseif {$w eq $ui_workdir} {
4876 "Adding
[short_path
$path]" \
4878 [concat $after {set ui_status_value {Ready.}}]
4881 show_diff $path $w $lno
4885 proc add_one_to_selection {w x y} {
4886 global file_lists last_clicked selected_paths
4888 set lno [lindex [split [$w index @$x,$y] .] 0]
4889 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4895 if {$last_clicked ne {}
4896 && [lindex $last_clicked 0] ne $w} {
4897 array unset selected_paths
4898 [lindex $last_clicked 0] tag remove in_sel 0.0 end
4901 set last_clicked [list $w $lno]
4902 if {[catch {set in_sel $selected_paths($path)}]} {
4906 unset selected_paths($path)
4907 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
4909 set selected_paths($path) 1
4910 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
4914 proc add_range_to_selection {w x y} {
4915 global file_lists last_clicked selected_paths
4917 if {[lindex $last_clicked 0] ne $w} {
4918 toggle_or_diff $w $x $y
4922 set lno [lindex [split [$w index @$x,$y] .] 0]
4923 set lc [lindex $last_clicked 1]
4932 foreach path [lrange $file_lists($w) \
4933 [expr {$begin - 1}] \
4934 [expr {$end - 1}]] {
4935 set selected_paths($path) 1
4937 $w tag add in_sel $begin.0 [expr {$end + 1}].0
4940 ######################################################################
4944 set cursor_ptr arrow
4945 font create font_diff -family Courier -size 10
4949 eval font configure font_ui [font actual [.dummy cget -font]]
4953 font create font_uibold
4954 font create font_diffbold
4959 } elseif {[is_MacOSX]} {
4967 proc apply_config {} {
4968 global repo_config font_descs
4970 foreach option $font_descs {
4971 set name [lindex $option 0]
4972 set font [lindex $option 1]
4974 foreach {cn cv} $repo_config(gui.$name) {
4975 font configure $font $cn $cv
4978 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
4980 foreach {cn cv} [font configure $font] {
4981 font configure ${font}bold $cn $cv
4983 font configure ${font}bold -weight bold
4987 set default_config(merge.summary) false
4988 set default_config(merge.verbosity) 2
4989 set default_config(user.name) {}
4990 set default_config(user.email) {}
4992 set default_config(gui.trustmtime) false
4993 set default_config(gui.diffcontext) 5
4994 set default_config(gui.newbranchtemplate) {}
4995 set default_config(gui.fontui) [font configure font_ui]
4996 set default_config(gui.fontdiff) [font configure font_diff]
4998 {fontui font_ui {Main Font}}
4999 {fontdiff font_diff {Diff/Console Font}}
5004 ######################################################################
5006 ## feature option selection
5008 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
5013 if {$subcommand eq {gui.sh}} {
5016 if {$subcommand eq {gui} && [llength $argv] > 0} {
5017 set subcommand [lindex $argv 0]
5018 set argv [lrange $argv 1 end]
5021 enable_option multicommit
5022 enable_option branch
5023 enable_option transport
5025 switch -- $subcommand {
5030 disable_option multicommit
5031 disable_option branch
5032 disable_option transport
5035 enable_option singlecommit
5037 disable_option multicommit
5038 disable_option branch
5039 disable_option transport
5043 ######################################################################
5051 menu .mbar -tearoff 0
5052 .mbar add cascade -label Repository -menu .mbar.repository
5053 .mbar add cascade -label Edit -menu .mbar.edit
5054 if {[is_enabled branch]} {
5055 .mbar add cascade -label Branch -menu .mbar.branch
5057 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
5058 .mbar add cascade -label Commit -menu .mbar.commit
5060 if {[is_enabled transport]} {
5061 .mbar add cascade -label Merge -menu .mbar.merge
5062 .mbar add cascade -label Fetch -menu .mbar.fetch
5063 .mbar add cascade -label Push -menu .mbar.push
5065 . configure -menu .mbar
5067 # -- Repository Menu
5069 menu .mbar.repository
5071 .mbar.repository add command \
5072 -label {Browse Current Branch} \
5073 -command {new_browser $current_branch} \
5075 trace add variable current_branch write ".mbar.repository entryconf
[.mbar.repository index last
] -label \"Browse \
$current_branch\" ;#"
5076 .mbar.repository add separator
5078 .mbar.repository add
command \
5079 -label {Visualize Current Branch
} \
5080 -command {do_gitk
$current_branch} \
5082 trace add variable current_branch
write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#"
5083 .mbar.repository add
command \
5084 -label {Visualize All Branches
} \
5085 -command {do_gitk
--all} \
5087 .mbar.repository add separator
5089 if {[is_enabled multicommit
]} {
5090 .mbar.repository add
command -label {Database Statistics
} \
5094 .mbar.repository add
command -label {Compress Database
} \
5098 .mbar.repository add
command -label {Verify Database
} \
5099 -command do_fsck_objects \
5102 .mbar.repository add separator
5105 .mbar.repository add
command \
5106 -label {Create Desktop Icon
} \
5107 -command do_cygwin_shortcut \
5109 } elseif
{[is_Windows
]} {
5110 .mbar.repository add
command \
5111 -label {Create Desktop Icon
} \
5112 -command do_windows_shortcut \
5114 } elseif
{[is_MacOSX
]} {
5115 .mbar.repository add
command \
5116 -label {Create Desktop Icon
} \
5117 -command do_macosx_app \
5122 .mbar.repository add
command -label Quit \
5124 -accelerator $M1T-Q \
5130 .mbar.edit add
command -label Undo \
5131 -command {catch
{[focus
] edit undo
}} \
5132 -accelerator $M1T-Z \
5134 .mbar.edit add
command -label Redo \
5135 -command {catch
{[focus
] edit redo
}} \
5136 -accelerator $M1T-Y \
5138 .mbar.edit add separator
5139 .mbar.edit add
command -label Cut \
5140 -command {catch
{tk_textCut
[focus
]}} \
5141 -accelerator $M1T-X \
5143 .mbar.edit add
command -label Copy \
5144 -command {catch
{tk_textCopy
[focus
]}} \
5145 -accelerator $M1T-C \
5147 .mbar.edit add
command -label Paste \
5148 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
5149 -accelerator $M1T-V \
5151 .mbar.edit add
command -label Delete \
5152 -command {catch
{[focus
] delete sel.first sel.last
}} \
5155 .mbar.edit add separator
5156 .mbar.edit add
command -label {Select All
} \
5157 -command {catch
{[focus
] tag add sel
0.0 end
}} \
5158 -accelerator $M1T-A \
5163 if {[is_enabled branch
]} {
5166 .mbar.branch add
command -label {Create...
} \
5167 -command do_create_branch \
5168 -accelerator $M1T-N \
5170 lappend disable_on_lock
[list .mbar.branch entryconf \
5171 [.mbar.branch index last
] -state]
5173 .mbar.branch add
command -label {Delete...
} \
5174 -command do_delete_branch \
5176 lappend disable_on_lock
[list .mbar.branch entryconf \
5177 [.mbar.branch index last
] -state]
5182 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
5185 .mbar.commit add radiobutton \
5186 -label {New Commit
} \
5187 -command do_select_commit_type \
5188 -variable selected_commit_type \
5191 lappend disable_on_lock \
5192 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5194 .mbar.commit add radiobutton \
5195 -label {Amend Last Commit
} \
5196 -command do_select_commit_type \
5197 -variable selected_commit_type \
5200 lappend disable_on_lock \
5201 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5203 .mbar.commit add separator
5205 .mbar.commit add
command -label Rescan \
5206 -command do_rescan \
5209 lappend disable_on_lock \
5210 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5212 .mbar.commit add
command -label {Add To Commit
} \
5213 -command do_add_selection \
5215 lappend disable_on_lock \
5216 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5218 .mbar.commit add
command -label {Add Existing To Commit
} \
5219 -command do_add_all \
5220 -accelerator $M1T-I \
5222 lappend disable_on_lock \
5223 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5225 .mbar.commit add
command -label {Unstage From Commit
} \
5226 -command do_unstage_selection \
5228 lappend disable_on_lock \
5229 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5231 .mbar.commit add
command -label {Revert Changes
} \
5232 -command do_revert_selection \
5234 lappend disable_on_lock \
5235 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5237 .mbar.commit add separator
5239 .mbar.commit add
command -label {Sign Off
} \
5240 -command do_signoff \
5241 -accelerator $M1T-S \
5244 .mbar.commit add
command -label Commit \
5245 -command do_commit \
5246 -accelerator $M1T-Return \
5248 lappend disable_on_lock \
5249 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5253 # -- Apple Menu (Mac OS X only)
5255 .mbar add cascade
-label Apple
-menu .mbar.apple
5258 .mbar.apple add
command -label "About [appname]" \
5261 .mbar.apple add
command -label "Options..." \
5262 -command do_options \
5267 .mbar.edit add separator
5268 .mbar.edit add
command -label {Options...
} \
5269 -command do_options \
5274 if {[file exists
/usr
/local
/miga
/lib
/gui-miga
]
5275 && [file exists .pvcsrc
]} {
5277 global ui_status_value
5278 if {![lock_index update
]} return
5279 set cmd
[list sh
--login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
5280 set miga_fd
[open
"|$cmd" r
]
5281 fconfigure
$miga_fd -blocking 0
5282 fileevent
$miga_fd readable
[list miga_done
$miga_fd]
5283 set ui_status_value
{Running miga...
}
5285 proc miga_done
{fd
} {
5290 rescan
[list
set ui_status_value
{Ready.
}]
5293 .mbar add cascade
-label Tools
-menu .mbar.tools
5295 .mbar.tools add
command -label "Migrate" \
5298 lappend disable_on_lock \
5299 [list .mbar.tools entryconf
[.mbar.tools index last
] -state]
5305 .mbar add cascade
-label Help
-menu .mbar.
help
5309 .mbar.
help add
command -label "About [appname]" \
5315 catch
{set browser
$repo_config(instaweb.browser
)}
5316 set doc_path
[file dirname [gitexec
]]
5317 set doc_path
[file join $doc_path Documentation index.html
]
5320 set doc_path
[exec cygpath
--windows $doc_path]
5323 if {$browser eq
{}} {
5326 } elseif
{[is_Cygwin
]} {
5327 set program_files
[file dirname [exec cygpath
--windir]]
5328 set program_files
[file join $program_files {Program Files
}]
5329 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
5330 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
5331 if {[file exists
$firefox]} {
5332 set browser
$firefox
5333 } elseif
{[file exists
$ie]} {
5336 unset program_files firefox ie
5340 if {[file isfile
$doc_path]} {
5341 set doc_url
"file:$doc_path"
5343 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
5346 if {$browser ne
{}} {
5347 .mbar.
help add
command -label {Online Documentation
} \
5348 -command [list
exec $browser $doc_url &] \
5351 unset browser doc_path doc_url
5353 # -- Standard bindings
5355 bind .
<Destroy
> do_quit
5356 bind all
<$M1B-Key-q> do_quit
5357 bind all
<$M1B-Key-Q> do_quit
5358 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
5359 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
5361 # -- Not a normal commit type invocation? Do that instead!
5363 switch
-- $subcommand {
5366 puts
"git-gui version $appvers"
5370 if {[llength
$argv] != 1} {
5371 puts stderr
"usage: $argv0 browser commit"
5374 set current_branch
[lindex
$argv 0]
5375 new_browser
$current_branch
5379 if {[llength
$argv] != 2} {
5380 puts stderr
"usage: $argv0 blame commit path"
5383 set current_branch
[lindex
$argv 0]
5384 show_blame
$current_branch [lindex
$argv 1]
5389 if {[llength
$argv] != 0} {
5390 puts
-nonewline stderr
"usage: $argv0"
5391 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
5392 puts
-nonewline stderr
" $subcommand"
5397 # fall through to setup UI for commits
5400 puts stderr
"usage: $argv0 \[{blame|citool}\]"
5411 -text {Current Branch
:} \
5416 -textvariable current_branch \
5420 pack .branch.l1
-side left
5421 pack .branch.cb
-side left
-fill x
5422 pack .branch
-side top
-fill x
5424 if {[is_enabled branch
]} {
5426 .mbar.merge add
command -label {Local Merge...
} \
5427 -command do_local_merge \
5429 lappend disable_on_lock \
5430 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5431 .mbar.merge add
command -label {Abort Merge...
} \
5432 -command do_reset_hard \
5434 lappend disable_on_lock \
5435 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5441 .mbar.push add
command -label {Push...
} \
5442 -command do_push_anywhere \
5446 # -- Main Window Layout
5448 panedwindow .vpane
-orient vertical
5449 panedwindow .vpane.files
-orient horizontal
5450 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
5451 pack .vpane
-anchor n
-side top
-fill both
-expand 1
5453 # -- Index File List
5455 frame .vpane.files.index
-height 100 -width 200
5456 label .vpane.files.index.title
-text {Changes To Be Committed
} \
5459 text
$ui_index -background white
-borderwidth 0 \
5460 -width 20 -height 10 \
5463 -cursor $cursor_ptr \
5464 -xscrollcommand {.vpane.files.index.sx
set} \
5465 -yscrollcommand {.vpane.files.index.sy
set} \
5467 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
5468 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
5469 pack .vpane.files.index.title
-side top
-fill x
5470 pack .vpane.files.index.sx
-side bottom
-fill x
5471 pack .vpane.files.index.sy
-side right
-fill y
5472 pack
$ui_index -side left
-fill both
-expand 1
5473 .vpane.files add .vpane.files.index
-sticky nsew
5475 # -- Working Directory File List
5477 frame .vpane.files.workdir
-height 100 -width 200
5478 label .vpane.files.workdir.title
-text {Changed But Not Updated
} \
5481 text
$ui_workdir -background white
-borderwidth 0 \
5482 -width 20 -height 10 \
5485 -cursor $cursor_ptr \
5486 -xscrollcommand {.vpane.files.workdir.sx
set} \
5487 -yscrollcommand {.vpane.files.workdir.sy
set} \
5489 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
5490 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
5491 pack .vpane.files.workdir.title
-side top
-fill x
5492 pack .vpane.files.workdir.sx
-side bottom
-fill x
5493 pack .vpane.files.workdir.sy
-side right
-fill y
5494 pack
$ui_workdir -side left
-fill both
-expand 1
5495 .vpane.files add .vpane.files.workdir
-sticky nsew
5497 foreach i
[list
$ui_index $ui_workdir] {
5498 $i tag conf in_diff
-font font_uibold
5499 $i tag conf in_sel \
5500 -background [$i cget
-foreground] \
5501 -foreground [$i cget
-background]
5505 # -- Diff and Commit Area
5507 frame .vpane.lower
-height 300 -width 400
5508 frame .vpane.lower.commarea
5509 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
5510 pack .vpane.lower.commarea
-side top
-fill x
5511 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
5512 .vpane add .vpane.lower
-sticky nsew
5514 # -- Commit Area Buttons
5516 frame .vpane.lower.commarea.buttons
5517 label .vpane.lower.commarea.buttons.l
-text {} \
5521 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
5522 pack .vpane.lower.commarea.buttons
-side left
-fill y
5524 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
5525 -command do_rescan \
5527 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
5528 lappend disable_on_lock \
5529 {.vpane.lower.commarea.buttons.rescan conf
-state}
5531 button .vpane.lower.commarea.buttons.incall
-text {Add Existing
} \
5532 -command do_add_all \
5534 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
5535 lappend disable_on_lock \
5536 {.vpane.lower.commarea.buttons.incall conf
-state}
5538 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
5539 -command do_signoff \
5541 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
5543 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
5544 -command do_commit \
5546 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
5547 lappend disable_on_lock \
5548 {.vpane.lower.commarea.buttons.commit conf
-state}
5550 # -- Commit Message Buffer
5552 frame .vpane.lower.commarea.buffer
5553 frame .vpane.lower.commarea.buffer.header
5554 set ui_comm .vpane.lower.commarea.buffer.t
5555 set ui_coml .vpane.lower.commarea.buffer.header.l
5556 radiobutton .vpane.lower.commarea.buffer.header.new \
5557 -text {New Commit
} \
5558 -command do_select_commit_type \
5559 -variable selected_commit_type \
5562 lappend disable_on_lock \
5563 [list .vpane.lower.commarea.buffer.header.new conf
-state]
5564 radiobutton .vpane.lower.commarea.buffer.header.amend \
5565 -text {Amend Last Commit
} \
5566 -command do_select_commit_type \
5567 -variable selected_commit_type \
5570 lappend disable_on_lock \
5571 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
5576 proc trace_commit_type
{varname args
} {
5577 global ui_coml commit_type
5578 switch
-glob -- $commit_type {
5579 initial
{set txt
{Initial Commit Message
:}}
5580 amend
{set txt
{Amended Commit Message
:}}
5581 amend-initial
{set txt
{Amended Initial Commit Message
:}}
5582 amend-merge
{set txt
{Amended Merge Commit Message
:}}
5583 merge
{set txt
{Merge Commit Message
:}}
5584 * {set txt
{Commit Message
:}}
5586 $ui_coml conf
-text $txt
5588 trace add variable commit_type
write trace_commit_type
5589 pack
$ui_coml -side left
-fill x
5590 pack .vpane.lower.commarea.buffer.header.amend
-side right
5591 pack .vpane.lower.commarea.buffer.header.new
-side right
5593 text
$ui_comm -background white
-borderwidth 1 \
5596 -autoseparators true \
5598 -width 75 -height 9 -wrap none \
5600 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
5601 scrollbar .vpane.lower.commarea.buffer.sby \
5602 -command [list
$ui_comm yview
]
5603 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
5604 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
5605 pack
$ui_comm -side left
-fill y
5606 pack .vpane.lower.commarea.buffer
-side left
-fill y
5608 # -- Commit Message Buffer Context Menu
5610 set ctxm .vpane.lower.commarea.buffer.ctxm
5611 menu
$ctxm -tearoff 0
5615 -command {tk_textCut
$ui_comm}
5619 -command {tk_textCopy
$ui_comm}
5623 -command {tk_textPaste
$ui_comm}
5627 -command {$ui_comm delete sel.first sel.last
}
5630 -label {Select All
} \
5632 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
5637 $ui_comm tag add sel
0.0 end
5638 tk_textCopy
$ui_comm
5639 $ui_comm tag remove sel
0.0 end
5646 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
5650 set current_diff_path
{}
5651 set current_diff_side
{}
5652 set diff_actions
[list
]
5653 proc trace_current_diff_path
{varname args
} {
5654 global current_diff_path diff_actions file_states
5655 if {$current_diff_path eq
{}} {
5661 set p
$current_diff_path
5662 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
5664 set p
[escape_path
$p]
5668 .vpane.lower.
diff.header.status configure
-text $s
5669 .vpane.lower.
diff.header.
file configure
-text $f
5670 .vpane.lower.
diff.header.path configure
-text $p
5671 foreach w
$diff_actions {
5675 trace add variable current_diff_path
write trace_current_diff_path
5677 frame .vpane.lower.
diff.header
-background orange
5678 label .vpane.lower.
diff.header.status \
5679 -background orange \
5680 -width $max_status_desc \
5684 label .vpane.lower.
diff.header.
file \
5685 -background orange \
5689 label .vpane.lower.
diff.header.path \
5690 -background orange \
5694 pack .vpane.lower.
diff.header.status
-side left
5695 pack .vpane.lower.
diff.header.
file -side left
5696 pack .vpane.lower.
diff.header.path
-fill x
5697 set ctxm .vpane.lower.
diff.header.ctxm
5698 menu
$ctxm -tearoff 0
5707 -- $current_diff_path
5709 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5710 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
5714 frame .vpane.lower.
diff.body
5715 set ui_diff .vpane.lower.
diff.body.t
5716 text
$ui_diff -background white
-borderwidth 0 \
5717 -width 80 -height 15 -wrap none \
5719 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
5720 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
5722 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
5723 -command [list
$ui_diff xview
]
5724 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
5725 -command [list
$ui_diff yview
]
5726 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
5727 pack .vpane.lower.
diff.body.sby
-side right
-fill y
5728 pack
$ui_diff -side left
-fill both
-expand 1
5729 pack .vpane.lower.
diff.header
-side top
-fill x
5730 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
5732 $ui_diff tag conf d_cr
-elide true
5733 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
5734 $ui_diff tag conf d_
+ -foreground {#00a000}
5735 $ui_diff tag conf d_-
-foreground red
5737 $ui_diff tag conf d_
++ -foreground {#00a000}
5738 $ui_diff tag conf d_--
-foreground red
5739 $ui_diff tag conf d_
+s \
5740 -foreground {#00a000} \
5741 -background {#e2effa}
5742 $ui_diff tag conf d_-s \
5744 -background {#e2effa}
5745 $ui_diff tag conf d_s
+ \
5746 -foreground {#00a000} \
5748 $ui_diff tag conf d_s- \
5752 $ui_diff tag conf d
<<<<<<< \
5753 -foreground orange \
5755 $ui_diff tag conf d
======= \
5756 -foreground orange \
5758 $ui_diff tag conf d
>>>>>>> \
5759 -foreground orange \
5762 $ui_diff tag raise sel
5764 # -- Diff Body Context Menu
5766 set ctxm .vpane.lower.
diff.body.ctxm
5767 menu
$ctxm -tearoff 0
5771 -command reshow_diff
5772 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5776 -command {tk_textCopy
$ui_diff}
5777 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5779 -label {Select All
} \
5781 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
5782 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5787 $ui_diff tag add sel
0.0 end
5788 tk_textCopy
$ui_diff
5789 $ui_diff tag remove sel
0.0 end
5791 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5794 -label {Apply
/Reverse Hunk
} \
5796 -command {apply_hunk
$cursorX $cursorY}
5797 set ui_diff_applyhunk
[$ctxm index last
]
5798 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
5801 -label {Decrease Font Size
} \
5803 -command {incr_font_size font_diff
-1}
5804 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5806 -label {Increase Font Size
} \
5808 -command {incr_font_size font_diff
1}
5809 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5812 -label {Show Less Context
} \
5814 -command {if {$repo_config(gui.diffcontext
) >= 2} {
5815 incr repo_config
(gui.diffcontext
) -1
5818 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5820 -label {Show More Context
} \
5823 incr repo_config
(gui.diffcontext
)
5826 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5828 $ctxm add
command -label {Options...
} \
5831 bind_button3
$ui_diff "
5834 if {\$ui_index eq \$current_diff_side} {
5835 $ctxm entryconf $ui_diff_applyhunk -label {Unstage Hunk From Commit}
5837 $ctxm entryconf $ui_diff_applyhunk -label {Stage Hunk For Commit}
5839 tk_popup $ctxm %X %Y
5841 unset ui_diff_applyhunk
5845 set ui_status_value
{Initializing...
}
5846 label .status
-textvariable ui_status_value \
5852 pack .status
-anchor w
-side bottom
-fill x
5857 set gm
$repo_config(gui.geometry
)
5858 wm geometry .
[lindex
$gm 0]
5859 .vpane sash place
0 \
5860 [lindex
[.vpane sash coord
0] 0] \
5862 .vpane.files sash place
0 \
5864 [lindex
[.vpane.files sash coord
0] 1]
5870 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
5871 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
5872 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
5873 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
5874 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
5875 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
5876 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
5877 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
5878 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
5879 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5880 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5882 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
5883 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
5884 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
5885 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
5886 bind $ui_diff <$M1B-Key-v> {break}
5887 bind $ui_diff <$M1B-Key-V> {break}
5888 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5889 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5890 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
5891 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
5892 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
5893 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
5894 bind $ui_diff <Button-1
> {focus
%W
}
5896 if {[is_enabled branch
]} {
5897 bind .
<$M1B-Key-n> do_create_branch
5898 bind .
<$M1B-Key-N> do_create_branch
5901 bind all
<Key-F5
> do_rescan
5902 bind all
<$M1B-Key-r> do_rescan
5903 bind all
<$M1B-Key-R> do_rescan
5904 bind .
<$M1B-Key-s> do_signoff
5905 bind .
<$M1B-Key-S> do_signoff
5906 bind .
<$M1B-Key-i> do_add_all
5907 bind .
<$M1B-Key-I> do_add_all
5908 bind .
<$M1B-Key-Return> do_commit
5909 foreach i
[list
$ui_index $ui_workdir] {
5910 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
5911 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
5912 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
5916 set file_lists
($ui_index) [list
]
5917 set file_lists
($ui_workdir) [list
]
5921 set MERGE_HEAD
[list
]
5924 set current_branch
{}
5925 set current_diff_path
{}
5926 set selected_commit_type new
5928 wm title .
"[appname] ([file normalize [file dirname [gitdir]]])"
5929 focus
-force $ui_comm
5931 # -- Warn the user about environmental problems. Cygwin's Tcl
5932 # does *not* pass its env array onto any processes it spawns.
5933 # This means that git processes get none of our environment.
5938 set msg
"Possible environment issues exist.
5940 The following environment variables are probably
5941 going to be ignored by any Git subprocess run
5945 foreach name
[array names env
] {
5946 switch
-regexp -- $name {
5947 {^GIT_INDEX_FILE$
} -
5948 {^GIT_OBJECT_DIRECTORY$
} -
5949 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
5951 {^GIT_EXTERNAL_DIFF$
} -
5955 {^GIT_CONFIG_LOCAL$
} -
5956 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
5957 append msg
" - $name\n"
5960 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
5961 append msg
" - $name\n"
5963 set suggest_user
$name
5967 if {$ignored_env > 0} {
5969 This is due to a known issue with the
5970 Tcl binary distributed by Cygwin."
5972 if {$suggest_user ne
{}} {
5975 A good replacement for $suggest_user
5976 is placing values for the user.name and
5977 user.email settings into your personal
5983 unset ignored_env msg suggest_user name
5986 # -- Only initialize complex UI if we are going to stay running.
5988 if {[is_enabled transport
]} {
5992 populate_branch_menu
5997 # -- Only suggest a gc run if we are going to stay running.
5999 if {[is_enabled multicommit
]} {
6000 set object_limit
2000
6001 if {[is_Windows
]} {set object_limit
200}
6002 regexp
{^
([0-9]+) objects
,} [git count-objects
] _junk objects_current
6003 if {$objects_current >= $object_limit} {
6005 "This repository currently has $objects_current loose objects.
6007 To maintain optimal performance it is strongly
6008 recommended that you compress the database
6009 when more than $object_limit loose objects exist.
6011 Compress the database now?"] eq
yes} {
6015 unset object_limit _junk objects_current
6018 lock_index begin-read