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 set w .browser
[incr next_browser_id
]
3048 set w_list
$w.list.l
3049 set browser_commit
($w_list) $commit
3050 set browser_status
($w_list) {Starting...
}
3051 set browser_stack
($w_list) {}
3052 set browser_path
($w_list) $browser_commit($w_list):
3053 set browser_busy
($w_list) 1
3056 label
$w.path
-textvariable browser_path
($w_list) \
3062 pack
$w.path
-anchor w
-side top
-fill x
3065 text
$w_list -background white
-borderwidth 0 \
3066 -cursor $cursor_ptr \
3071 -xscrollcommand [list
$w.list.sbx
set] \
3072 -yscrollcommand [list
$w.list.sby
set] \
3074 $w_list tag conf in_sel \
3075 -background [$w_list cget
-foreground] \
3076 -foreground [$w_list cget
-background]
3077 scrollbar
$w.list.sbx
-orient h
-command [list
$w_list xview
]
3078 scrollbar
$w.list.sby
-orient v
-command [list
$w_list yview
]
3079 pack
$w.list.sbx
-side bottom
-fill x
3080 pack
$w.list.sby
-side right
-fill y
3081 pack
$w_list -side left
-fill both
-expand 1
3082 pack
$w.list
-side top
-fill both
-expand 1
3084 label
$w.status
-textvariable browser_status
($w_list) \
3090 pack
$w.status
-anchor w
-side bottom
-fill x
3092 bind $w_list <Button-1
> "browser_click 0 $w_list @%x,%y;break"
3093 bind $w_list <Double-Button-1
> "browser_click 1 $w_list @%x,%y;break"
3094 bind $w_list <$M1B-Up> "browser_parent $w_list;break"
3095 bind $w_list <$M1B-Left> "browser_parent $w_list;break"
3096 bind $w_list <Up
> "browser_move -1 $w_list;break"
3097 bind $w_list <Down
> "browser_move 1 $w_list;break"
3098 bind $w_list <$M1B-Right> "browser_enter $w_list;break"
3099 bind $w_list <Return
> "browser_enter $w_list;break"
3100 bind $w_list <Prior
> "browser_page -1 $w_list;break"
3101 bind $w_list <Next
> "browser_page 1 $w_list;break"
3102 bind $w_list <Left
> break
3103 bind $w_list <Right
> break
3105 bind $w <Visibility
> "focus $w"
3107 array unset browser_buffer $w_list
3108 array unset browser_files $w_list
3109 array unset browser_status $w_list
3110 array unset browser_stack $w_list
3111 array unset browser_path $w_list
3112 array unset browser_commit $w_list
3113 array unset browser_busy $w_list
3115 wm title
$w "[appname] ([reponame]): File Browser"
3116 ls_tree
$w_list $browser_commit($w_list) {}
3119 proc browser_move
{dir w
} {
3120 global browser_files browser_busy
3122 if {$browser_busy($w)} return
3123 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3125 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3126 $w tag remove in_sel
0.0 end
3127 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3132 proc browser_page
{dir w
} {
3133 global browser_files browser_busy
3135 if {$browser_busy($w)} return
3136 $w yview scroll
$dir pages
3138 [lindex
[$w yview
] 0]
3139 * [llength
$browser_files($w)]
3141 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3142 $w tag remove in_sel
0.0 end
3143 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3148 proc browser_parent
{w
} {
3149 global browser_files browser_status browser_path
3150 global browser_stack browser_busy
3152 if {$browser_busy($w)} return
3153 set info
[lindex
$browser_files($w) 0]
3154 if {[lindex
$info 0] eq
{parent
}} {
3155 set parent
[lindex
$browser_stack($w) end-1
]
3156 set browser_stack
($w) [lrange
$browser_stack($w) 0 end-2
]
3157 if {$browser_stack($w) eq
{}} {
3158 regsub
{:.
*$
} $browser_path($w) {:} browser_path
($w)
3160 regsub
{/[^
/]+$
} $browser_path($w) {} browser_path
($w)
3162 set browser_status
($w) "Loading $browser_path($w)..."
3163 ls_tree
$w [lindex
$parent 0] [lindex
$parent 1]
3167 proc browser_enter
{w
} {
3168 global browser_files browser_status browser_path
3169 global browser_commit browser_stack browser_busy
3171 if {$browser_busy($w)} return
3172 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3173 set info
[lindex
$browser_files($w) [expr {$lno - 1}]]
3175 switch
-- [lindex
$info 0] {
3180 set name
[lindex
$info 2]
3181 set escn
[escape_path
$name]
3182 set browser_status
($w) "Loading $escn..."
3183 append browser_path
($w) $escn
3184 ls_tree
$w [lindex
$info 1] $name
3187 set name
[lindex
$info 2]
3189 foreach n
$browser_stack($w) {
3190 append p
[lindex
$n 1]
3193 show_blame
$browser_commit($w) $p
3199 proc browser_click
{was_double_click w pos
} {
3200 global browser_files browser_busy
3202 if {$browser_busy($w)} return
3203 set lno
[lindex
[split [$w index
$pos] .
] 0]
3206 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3207 $w tag remove in_sel
0.0 end
3208 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3209 if {$was_double_click} {
3215 proc ls_tree
{w tree_id name
} {
3216 global browser_buffer browser_files browser_stack browser_busy
3218 set browser_buffer
($w) {}
3219 set browser_files
($w) {}
3220 set browser_busy
($w) 1
3222 $w conf
-state normal
3223 $w tag remove in_sel
0.0 end
3225 if {$browser_stack($w) ne
{}} {
3226 $w image create end \
3227 -align center
-padx 5 -pady 1 \
3230 $w insert end
{[Up To Parent
]}
3231 lappend browser_files
($w) parent
3233 lappend browser_stack
($w) [list
$tree_id $name]
3234 $w conf
-state disabled
3236 set cmd
[list git ls-tree
-z $tree_id]
3237 set fd
[open
"| $cmd" r
]
3238 fconfigure
$fd -blocking 0 -translation binary
-encoding binary
3239 fileevent
$fd readable
[list read_ls_tree
$fd $w]
3242 proc read_ls_tree
{fd w
} {
3243 global browser_buffer browser_files browser_status browser_busy
3245 if {![winfo exists
$w]} {
3250 append browser_buffer
($w) [read $fd]
3251 set pck
[split $browser_buffer($w) "\0"]
3252 set browser_buffer
($w) [lindex
$pck end
]
3254 set n
[llength
$browser_files($w)]
3255 $w conf
-state normal
3256 foreach p
[lrange
$pck 0 end-1
] {
3257 set info
[split $p "\t"]
3258 set path
[lindex
$info 1]
3259 set info
[split [lindex
$info 0] { }]
3260 set type [lindex
$info 1]
3261 set object
[lindex
$info 2]
3272 set image file_question
3276 if {$n > 0} {$w insert end
"\n"}
3277 $w image create end \
3278 -align center
-padx 5 -pady 1 \
3279 -name icon
[incr n
] \
3281 $w insert end
[escape_path
$path]
3282 lappend browser_files
($w) [list
$type $object $path]
3284 $w conf
-state disabled
3288 set browser_status
($w) Ready.
3289 set browser_busy
($w) 0
3290 array
unset browser_buffer
$w
3292 $w tag add in_sel
1.0 2.0
3298 proc show_blame
{commit path
} {
3299 global next_browser_id blame_status blame_data
3301 if {[winfo ismapped .
]} {
3302 set w .browser
[incr next_browser_id
]
3309 set blame_status
($w) {Loading current
file content...
}
3311 label
$w.path
-text "$commit:$path" \
3317 pack
$w.path
-side top
-fill x
3320 text
$w.out.loaded_t \
3321 -background white
-borderwidth 0 \
3327 $w.out.loaded_t tag conf annotated
-background grey
3329 text
$w.out.linenumber_t \
3330 -background white
-borderwidth 0 \
3336 $w.out.linenumber_t tag conf linenumber
-justify right
3338 text
$w.out.file_t \
3339 -background white
-borderwidth 0 \
3344 -xscrollcommand [list
$w.out.sbx
set] \
3347 scrollbar
$w.out.sbx
-orient h
-command [list
$w.out.file_t xview
]
3348 scrollbar
$w.out.sby
-orient v \
3349 -command [list scrollbar2many
[list \
3351 $w.out.linenumber_t \
3355 $w.out.linenumber_t \
3360 grid conf
$w.out.sbx
-column 2 -sticky we
3361 grid columnconfigure
$w.out
2 -weight 1
3362 grid rowconfigure
$w.out
0 -weight 1
3363 pack
$w.out
-fill both
-expand 1
3365 label
$w.status
-textvariable blame_status
($w) \
3371 pack
$w.status
-side bottom
-fill x
3375 -background white
-borderwidth 0 \
3380 -xscrollcommand [list
$w.cm.sbx
set] \
3381 -yscrollcommand [list
$w.cm.sby
set] \
3383 scrollbar
$w.cm.sbx
-orient h
-command [list
$w.cm.t xview
]
3384 scrollbar
$w.cm.sby
-orient v
-command [list
$w.cm.t yview
]
3385 pack
$w.cm.sby
-side right
-fill y
3386 pack
$w.cm.sbx
-side bottom
-fill x
3387 pack
$w.cm.t
-expand 1 -fill both
3388 pack
$w.cm
-side bottom
-fill x
3390 menu
$w.ctxm
-tearoff 0
3391 $w.ctxm add
command -label "Copy Commit" \
3393 -command "blame_copycommit $w \$cursorW @\$cursorX,\$cursorY"
3397 $w.out.linenumber_t \
3399 $i tag conf in_sel \
3400 -background [$i cget
-foreground] \
3401 -foreground [$i cget
-background]
3402 $i conf
-yscrollcommand \
3403 [list many2scrollbar
[list \
3405 $w.out.linenumber_t \
3408 bind $i <Button-1
> "
3411 $w.out.linenumber_t \\
3420 tk_popup $w.ctxm %X %Y
3424 bind $w.cm.t
<Button-1
> "focus $w.cm.t"
3425 bind $tl <Visibility
> "focus $tl"
3426 bind $tl <Destroy
> "
3427 array unset blame_status {$w}
3428 array unset blame_data $w,*
3430 wm title
$tl "[appname] ([reponame]): File Viewer"
3432 set blame_data
($w,commit_count
) 0
3433 set blame_data
($w,commit_list
) {}
3434 set blame_data
($w,total_lines
) 0
3435 set blame_data
($w,blame_lines
) 0
3436 set blame_data
($w,highlight_commit
) {}
3437 set blame_data
($w,highlight_line
) -1
3439 set cmd
[list git cat-file blob
"$commit:$path"]
3440 set fd
[open
"| $cmd" r
]
3441 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3442 fileevent
$fd readable
[list read_blame_catfile \
3443 $fd $w $commit $path \
3444 $w.cm.t
$w.out.loaded_t
$w.out.linenumber_t
$w.out.file_t
]
3447 proc read_blame_catfile
{fd w commit path w_cmit w_load w_line w_file
} {
3448 global blame_status blame_data
3450 if {![winfo exists
$w_file]} {
3455 set n
$blame_data($w,total_lines
)
3456 $w_load conf
-state normal
3457 $w_line conf
-state normal
3458 $w_file conf
-state normal
3459 while {[gets
$fd line
] >= 0} {
3460 regsub
"\r\$" $line {} line
3462 $w_load insert end
"\n"
3463 $w_line insert end
"$n\n" linenumber
3464 $w_file insert end
"$line\n"
3466 $w_load conf
-state disabled
3467 $w_line conf
-state disabled
3468 $w_file conf
-state disabled
3469 set blame_data
($w,total_lines
) $n
3473 blame_incremental_status
$w
3474 set cmd
[list git blame
-M -C --incremental]
3475 lappend cmd
$commit -- $path
3476 set fd
[open
"| $cmd" r
]
3477 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3478 fileevent
$fd readable
[list read_blame_incremental
$fd $w \
3479 $w_load $w_cmit $w_line $w_file]
3483 proc read_blame_incremental
{fd w w_load w_cmit w_line w_file
} {
3484 global blame_status blame_data
3486 if {![winfo exists
$w_file]} {
3491 while {[gets
$fd line
] >= 0} {
3492 if {[regexp
{^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$
} $line line \
3493 cmit original_line final_line line_count
]} {
3494 set blame_data
($w,commit
) $cmit
3495 set blame_data
($w,original_line
) $original_line
3496 set blame_data
($w,final_line
) $final_line
3497 set blame_data
($w,line_count
) $line_count
3499 if {[catch
{set g
$blame_data($w,$cmit,order
)}]} {
3500 $w_line tag conf g
$cmit
3501 $w_file tag conf g
$cmit
3502 $w_line tag raise in_sel
3503 $w_file tag raise in_sel
3504 $w_file tag raise sel
3505 set blame_data
($w,$cmit,order
) $blame_data($w,commit_count
)
3506 incr blame_data
($w,commit_count
)
3507 lappend blame_data
($w,commit_list
) $cmit
3509 } elseif
{[string match
{filename
*} $line]} {
3510 set file [string range
$line 9 end
]
3511 set n
$blame_data($w,line_count
)
3512 set lno
$blame_data($w,final_line
)
3513 set cmit
$blame_data($w,commit
)
3516 if {[catch
{set g g
$blame_data($w,line
$lno,commit
)}]} {
3517 $w_load tag add annotated
$lno.0 "$lno.0 lineend + 1c"
3519 $w_line tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3520 $w_file tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3523 set blame_data
($w,line
$lno,commit
) $cmit
3524 set blame_data
($w,line
$lno,file) $file
3525 $w_line tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3526 $w_file tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3528 if {$blame_data($w,highlight_line
) == -1} {
3529 if {[lindex
[$w_file yview
] 0] == 0} {
3531 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3533 } elseif
{$blame_data($w,highlight_line
) == $lno} {
3534 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3539 incr blame_data
($w,blame_lines
)
3542 set hc
$blame_data($w,highlight_commit
)
3544 && [expr {$blame_data($w,$hc,order
) + 1}]
3545 == $blame_data($w,$cmit,order
)} {
3546 blame_showcommit
$w $w_cmit $w_line $w_file \
3547 $blame_data($w,highlight_line
)
3549 } elseif
{[regexp
{^
([a-z-
]+) (.
*)$
} $line line header data
]} {
3550 set blame_data
($w,$blame_data($w,commit
),$header) $data
3556 set blame_status
($w) {Annotation complete.
}
3558 blame_incremental_status
$w
3562 proc blame_incremental_status
{w
} {
3563 global blame_status blame_data
3565 set blame_status
($w) [format \
3566 "Loading annotations... %i of %i lines annotated (%2i%%)" \
3567 $blame_data($w,blame_lines
) \
3568 $blame_data($w,total_lines
) \
3569 [expr {100 * $blame_data($w,blame_lines
)
3570 / $blame_data($w,total_lines
)}]]
3573 proc blame_click
{w w_cmit w_line w_file cur_w pos
} {
3574 set lno
[lindex
[split [$cur_w index
$pos] .
] 0]
3575 if {$lno eq
{}} return
3577 $w_line tag remove in_sel
0.0 end
3578 $w_file tag remove in_sel
0.0 end
3579 $w_line tag add in_sel
$lno.0 "$lno.0 + 1 line"
3580 $w_file tag add in_sel
$lno.0 "$lno.0 + 1 line"
3582 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3591 proc blame_showcommit
{w w_cmit w_line w_file lno
} {
3592 global blame_colors blame_data repo_config
3594 set cmit
$blame_data($w,highlight_commit
)
3596 set idx
$blame_data($w,$cmit,order
)
3598 foreach c
$blame_colors {
3599 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3600 $w_line tag conf g
$h -background white
3601 $w_file tag conf g
$h -background white
3606 $w_cmit conf
-state normal
3607 $w_cmit delete
0.0 end
3608 if {[catch
{set cmit
$blame_data($w,line
$lno,commit
)}]} {
3610 $w_cmit insert end
"Loading annotation..."
3612 set idx
$blame_data($w,$cmit,order
)
3614 foreach c
$blame_colors {
3615 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3616 $w_line tag conf g
$h -background $c
3617 $w_file tag conf g
$h -background $c
3621 if {[catch
{set msg
$blame_data($w,$cmit,message
)}]} {
3624 set fd
[open
"| git cat-file commit $cmit" r
]
3625 fconfigure
$fd -encoding binary
-translation lf
3626 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
3629 while {[gets
$fd line
] > 0} {
3630 if {[string match
{encoding
*} $line]} {
3631 set enc
[string tolower
[string range
$line 9 end
]]
3634 fconfigure
$fd -encoding $enc
3635 set msg
[string trim
[read $fd]]
3638 set blame_data
($w,$cmit,message
) $msg
3644 catch
{set author_name
$blame_data($w,$cmit,author
)}
3645 catch
{set author_email
$blame_data($w,$cmit,author-mail
)}
3646 catch
{set author_time
[clock format
$blame_data($w,$cmit,author-time
)]}
3648 set committer_name
{}
3649 set committer_email
{}
3650 set committer_time
{}
3651 catch
{set committer_name
$blame_data($w,$cmit,committer
)}
3652 catch
{set committer_email
$blame_data($w,$cmit,committer-mail
)}
3653 catch
{set committer_time
[clock format
$blame_data($w,$cmit,committer-time
)]}
3655 $w_cmit insert end
"commit $cmit\n"
3656 $w_cmit insert end
"Author: $author_name $author_email $author_time\n"
3657 $w_cmit insert end
"Committer: $committer_name $committer_email $committer_time\n"
3658 $w_cmit insert end
"Original File: [escape_path $blame_data($w,line$lno,file)]\n"
3659 $w_cmit insert end
"\n"
3660 $w_cmit insert end
$msg
3662 $w_cmit conf
-state disabled
3664 set blame_data
($w,highlight_line
) $lno
3665 set blame_data
($w,highlight_commit
) $cmit
3668 proc blame_copycommit
{w i pos
} {
3670 set lno
[lindex
[split [$i index
$pos] .
] 0]
3671 if {![catch
{set commit
$blame_data($w,line
$lno,commit
)}]} {
3680 ######################################################################
3685 #define mask_width 14
3686 #define mask_height 15
3687 static unsigned char mask_bits
[] = {
3688 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3689 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3690 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
3693 image create bitmap file_plain
-background white
-foreground black
-data {
3694 #define plain_width 14
3695 #define plain_height 15
3696 static unsigned char plain_bits
[] = {
3697 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3698 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
3699 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3700 } -maskdata $filemask
3702 image create bitmap file_mod
-background white
-foreground blue
-data {
3703 #define mod_width 14
3704 #define mod_height 15
3705 static unsigned char mod_bits
[] = {
3706 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3707 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3708 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3709 } -maskdata $filemask
3711 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
3712 #define file_fulltick_width 14
3713 #define file_fulltick_height 15
3714 static unsigned char file_fulltick_bits
[] = {
3715 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
3716 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
3717 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3718 } -maskdata $filemask
3720 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
3721 #define parttick_width 14
3722 #define parttick_height 15
3723 static unsigned char parttick_bits
[] = {
3724 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3725 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
3726 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3727 } -maskdata $filemask
3729 image create bitmap file_question
-background white
-foreground black
-data {
3730 #define file_question_width 14
3731 #define file_question_height 15
3732 static unsigned char file_question_bits
[] = {
3733 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
3734 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
3735 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3736 } -maskdata $filemask
3738 image create bitmap file_removed
-background white
-foreground red
-data {
3739 #define file_removed_width 14
3740 #define file_removed_height 15
3741 static unsigned char file_removed_bits
[] = {
3742 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3743 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
3744 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
3745 } -maskdata $filemask
3747 image create bitmap file_merge
-background white
-foreground blue
-data {
3748 #define file_merge_width 14
3749 #define file_merge_height 15
3750 static unsigned char file_merge_bits
[] = {
3751 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
3752 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3753 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3754 } -maskdata $filemask
3757 #define file_width 18
3758 #define file_height 18
3759 static unsigned char file_bits
[] = {
3760 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00,
3761 0x0c, 0x03, 0x00, 0x04, 0xfe, 0x00, 0x06, 0x80, 0x00, 0xff, 0x9f, 0x00,
3762 0x03, 0x98, 0x00, 0x02, 0x90, 0x00, 0x06, 0xb0, 0x00, 0x04, 0xa0, 0x00,
3763 0x0c, 0xe0, 0x00, 0x08, 0xc0, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
3764 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3766 image create bitmap file_dir
-background white
-foreground blue \
3767 -data $file_dir_data -maskdata $file_dir_data
3770 set file_uplevel_data
{
3772 #define up_height 15
3773 static unsigned char up_bits
[] = {
3774 0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f,
3775 0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
3776 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
3778 image create bitmap file_uplevel
-background white
-foreground red \
3779 -data $file_uplevel_data -maskdata $file_uplevel_data
3780 unset file_uplevel_data
3782 set ui_index .vpane.files.index.list
3783 set ui_workdir .vpane.files.workdir.list
3785 set all_icons
(_
$ui_index) file_plain
3786 set all_icons
(A
$ui_index) file_fulltick
3787 set all_icons
(M
$ui_index) file_fulltick
3788 set all_icons
(D
$ui_index) file_removed
3789 set all_icons
(U
$ui_index) file_merge
3791 set all_icons
(_
$ui_workdir) file_plain
3792 set all_icons
(M
$ui_workdir) file_mod
3793 set all_icons
(D
$ui_workdir) file_question
3794 set all_icons
(U
$ui_workdir) file_merge
3795 set all_icons
(O
$ui_workdir) file_plain
3797 set max_status_desc
0
3801 {_M
"Modified, not staged"}
3802 {M_
"Staged for commit"}
3803 {MM
"Portions staged for commit"}
3804 {MD
"Staged for commit, missing"}
3806 {_O
"Untracked, not staged"}
3807 {A_
"Staged for commit"}
3808 {AM
"Portions staged for commit"}
3809 {AD
"Staged for commit, missing"}
3812 {D_
"Staged for removal"}
3813 {DO
"Staged for removal, still present"}
3815 {U_
"Requires merge resolution"}
3816 {UU
"Requires merge resolution"}
3817 {UM
"Requires merge resolution"}
3818 {UD
"Requires merge resolution"}
3820 if {$max_status_desc < [string length
[lindex
$i 1]]} {
3821 set max_status_desc
[string length
[lindex
$i 1]]
3823 set all_descs
([lindex
$i 0]) [lindex
$i 1]
3827 ######################################################################
3831 proc bind_button3
{w cmd
} {
3832 bind $w <Any-Button-3
> $cmd
3834 bind $w <Control-Button-1
> $cmd
3838 proc scrollbar2many
{list mode args
} {
3839 foreach w
$list {eval $w $mode $args}
3842 proc many2scrollbar
{list mode sb top bottom
} {
3843 $sb set $top $bottom
3844 foreach w
$list {$w $mode moveto
$top}
3847 proc incr_font_size
{font
{amt
1}} {
3848 set sz
[font configure
$font -size]
3850 font configure
$font -size $sz
3851 font configure
${font}bold
-size $sz
3854 proc hook_failed_popup
{hook msg
} {
3859 label
$w.m.l1
-text "$hook hook failed:" \
3864 -background white
-borderwidth 1 \
3866 -width 80 -height 10 \
3868 -yscrollcommand [list
$w.m.sby
set]
3870 -text {You must correct the above errors before committing.
} \
3874 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3875 pack
$w.m.l1
-side top
-fill x
3876 pack
$w.m.l2
-side bottom
-fill x
3877 pack
$w.m.sby
-side right
-fill y
3878 pack
$w.m.t
-side left
-fill both
-expand 1
3879 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3881 $w.m.t insert
1.0 $msg
3882 $w.m.t conf
-state disabled
3884 button
$w.ok
-text OK \
3887 -command "destroy $w"
3888 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3890 bind $w <Visibility
> "grab $w; focus $w"
3891 bind $w <Key-Return
> "destroy $w"
3892 wm title
$w "[appname] ([reponame]): error"
3896 set next_console_id
0
3898 proc new_console
{short_title long_title
} {
3899 global next_console_id console_data
3900 set w .console
[incr next_console_id
]
3901 set console_data
($w) [list
$short_title $long_title]
3902 return [console_init
$w]
3905 proc console_init
{w
} {
3906 global console_cr console_data M1B
3908 set console_cr
($w) 1.0
3911 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
3916 -background white
-borderwidth 1 \
3918 -width 80 -height 10 \
3921 -yscrollcommand [list
$w.m.sby
set]
3922 label
$w.m.s
-text {Working... please
wait...
} \
3926 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3927 pack
$w.m.l1
-side top
-fill x
3928 pack
$w.m.s
-side bottom
-fill x
3929 pack
$w.m.sby
-side right
-fill y
3930 pack
$w.m.t
-side left
-fill both
-expand 1
3931 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3933 menu
$w.ctxm
-tearoff 0
3934 $w.ctxm add
command -label "Copy" \
3936 -command "tk_textCopy $w.m.t"
3937 $w.ctxm add
command -label "Select All" \
3939 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
3940 $w.ctxm add
command -label "Copy All" \
3943 $w.m.t tag add sel 0.0 end
3945 $w.m.t tag remove sel 0.0 end
3948 button
$w.ok
-text {Close
} \
3951 -command "destroy $w"
3952 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3954 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
3955 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
3956 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
3957 bind $w <Visibility
> "focus $w"
3958 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
3962 proc console_exec
{w cmd after
} {
3963 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
3964 # But most users need that so we have to relogin. :-(
3967 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
3970 # -- Tcl won't let us redirect both stdout and stderr to
3971 # the same pipe. So pass it through cat...
3973 set cmd
[concat |
$cmd |
& cat]
3975 set fd_f
[open
$cmd r
]
3976 fconfigure
$fd_f -blocking 0 -translation binary
3977 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
3980 proc console_read
{w fd after
} {
3985 if {![winfo exists
$w]} {console_init
$w}
3986 $w.m.t conf
-state normal
3988 set n
[string length
$buf]
3990 set cr
[string first
"\r" $buf $c]
3991 set lf
[string first
"\n" $buf $c]
3992 if {$cr < 0} {set cr
[expr {$n + 1}]}
3993 if {$lf < 0} {set lf
[expr {$n + 1}]}
3996 $w.m.t insert end
[string range
$buf $c $lf]
3997 set console_cr
($w) [$w.m.t index
{end
-1c}]
4001 $w.m.t delete
$console_cr($w) end
4002 $w.m.t insert end
"\n"
4003 $w.m.t insert end
[string range
$buf $c $cr]
4008 $w.m.t conf
-state disabled
4012 fconfigure
$fd -blocking 1
4014 if {[catch
{close
$fd}]} {
4019 uplevel
#0 $after $w $ok
4022 fconfigure
$fd -blocking 0
4025 proc console_chain
{cmdlist w
{ok
1}} {
4027 if {[llength
$cmdlist] == 0} {
4032 set cmd
[lindex
$cmdlist 0]
4033 set cmdlist
[lrange
$cmdlist 1 end
]
4035 if {[lindex
$cmd 0] eq
{console_exec
}} {
4038 [list console_chain
$cmdlist]
4040 uplevel
#0 $cmd $cmdlist $w $ok
4047 proc console_done
{args
} {
4048 global console_cr console_data
4050 switch
-- [llength
$args] {
4052 set w
[lindex
$args 0]
4053 set ok
[lindex
$args 1]
4056 set w
[lindex
$args 1]
4057 set ok
[lindex
$args 2]
4060 error
"wrong number of args: console_done ?ignored? w ok"
4065 if {[winfo exists
$w]} {
4066 $w.m.s conf
-background green
-text {Success
}
4067 $w.ok conf
-state normal
4070 if {![winfo exists
$w]} {
4073 $w.m.s conf
-background red
-text {Error
: Command Failed
}
4074 $w.ok conf
-state normal
4077 array
unset console_cr
$w
4078 array
unset console_data
$w
4081 ######################################################################
4085 set starting_gitk_msg
{Starting gitk... please
wait...
}
4087 proc do_gitk
{revs
} {
4088 global env ui_status_value starting_gitk_msg
4090 # -- Always start gitk through whatever we were loaded with. This
4091 # lets us bypass using shell process on Windows systems.
4093 set cmd
[info nameofexecutable
]
4094 lappend cmd
[gitexec gitk
]
4100 if {[catch
{eval exec $cmd &} err
]} {
4101 error_popup
"Failed to start gitk:\n\n$err"
4103 set ui_status_value
$starting_gitk_msg
4105 if {$ui_status_value eq
$starting_gitk_msg} {
4106 set ui_status_value
{Ready.
}
4113 set fd
[open
"| git count-objects -v" r
]
4114 while {[gets
$fd line
] > 0} {
4115 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
4116 set stats
($name) $value
4122 foreach p
[glob
-directory [gitdir objects pack
] \
4125 incr packed_sz
[file size
$p]
4127 if {$packed_sz > 0} {
4128 set stats
(size-pack
) [expr {$packed_sz / 1024}]
4133 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4135 label
$w.header
-text {Database Statistics
} \
4137 pack
$w.header
-side top
-fill x
4139 frame
$w.buttons
-border 1
4140 button
$w.buttons.close
-text Close \
4142 -command [list destroy
$w]
4143 button
$w.buttons.gc
-text {Compress Database
} \
4145 -command "destroy $w;do_gc"
4146 pack
$w.buttons.close
-side right
4147 pack
$w.buttons.gc
-side left
4148 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4150 frame
$w.stat
-borderwidth 1 -relief solid
4152 {count
{Number of loose objects
}}
4153 {size
{Disk space used by loose objects
} { KiB
}}
4154 {in-pack
{Number of packed objects
}}
4155 {packs
{Number of packs
}}
4156 {size-pack
{Disk space used by packed objects
} { KiB
}}
4157 {prune-packable
{Packed objects waiting
for pruning
}}
4158 {garbage
{Garbage files
}}
4160 set name
[lindex
$s 0]
4161 set label
[lindex
$s 1]
4162 if {[catch
{set value
$stats($name)}]} continue
4163 if {[llength
$s] > 2} {
4164 set value
"$value[lindex $s 2]"
4167 label
$w.stat.l_
$name -text "$label:" -anchor w
-font font_ui
4168 label
$w.stat.v_
$name -text $value -anchor w
-font font_ui
4169 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
4171 pack
$w.stat
-pady 10 -padx 10
4173 bind $w <Visibility
> "grab $w; focus $w"
4174 bind $w <Key-Escape
> [list destroy
$w]
4175 bind $w <Key-Return
> [list destroy
$w]
4176 wm title
$w "[appname] ([reponame]): Database Statistics"
4181 set w
[new_console
{gc
} {Compressing the object database
}]
4183 {console_exec
{git pack-refs
--prune}}
4184 {console_exec
{git reflog expire
--all}}
4185 {console_exec
{git repack
-a -d -l}}
4186 {console_exec
{git rerere gc
}}
4190 proc do_fsck_objects
{} {
4191 set w
[new_console
{fsck-objects
} \
4192 {Verifying the object database with fsck-objects
}]
4193 set cmd
[list git fsck-objects
]
4196 lappend cmd
--strict
4197 console_exec
$w $cmd console_done
4203 global ui_comm is_quitting repo_config commit_type
4205 if {$is_quitting} return
4208 if {[winfo exists
$ui_comm]} {
4209 # -- Stash our current commit buffer.
4211 set save
[gitdir GITGUI_MSG
]
4212 set msg
[string trim
[$ui_comm get
0.0 end
]]
4213 regsub
-all -line {[ \r\t]+$
} $msg {} msg
4214 if {(![string match amend
* $commit_type]
4215 ||
[$ui_comm edit modified
])
4218 set fd
[open
$save w
]
4219 puts
-nonewline $fd $msg
4223 catch
{file delete
$save}
4226 # -- Stash our current window geometry into this repository.
4228 set cfg_geometry
[list
]
4229 lappend cfg_geometry
[wm geometry .
]
4230 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
4231 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
4232 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
4235 if {$cfg_geometry ne
$rc_geometry} {
4236 catch
{git config gui.geometry
$cfg_geometry}
4244 rescan
{set ui_status_value
{Ready.
}}
4247 proc unstage_helper
{txt paths
} {
4248 global file_states current_diff_path
4250 if {![lock_index begin-update
]} return
4254 foreach path
$paths {
4255 switch
-glob -- [lindex
$file_states($path) 0] {
4259 lappend pathList
$path
4260 if {$path eq
$current_diff_path} {
4261 set after
{reshow_diff
;}
4266 if {$pathList eq
{}} {
4272 [concat
$after {set ui_status_value
{Ready.
}}]
4276 proc do_unstage_selection
{} {
4277 global current_diff_path selected_paths
4279 if {[array size selected_paths
] > 0} {
4281 {Unstaging selected files from commit
} \
4282 [array names selected_paths
]
4283 } elseif
{$current_diff_path ne
{}} {
4285 "Unstaging [short_path $current_diff_path] from commit" \
4286 [list
$current_diff_path]
4290 proc add_helper
{txt paths
} {
4291 global file_states current_diff_path
4293 if {![lock_index begin-update
]} return
4297 foreach path
$paths {
4298 switch
-glob -- [lindex
$file_states($path) 0] {
4303 lappend pathList
$path
4304 if {$path eq
$current_diff_path} {
4305 set after
{reshow_diff
;}
4310 if {$pathList eq
{}} {
4316 [concat
$after {set ui_status_value
{Ready to commit.
}}]
4320 proc do_add_selection
{} {
4321 global current_diff_path selected_paths
4323 if {[array size selected_paths
] > 0} {
4325 {Adding selected files
} \
4326 [array names selected_paths
]
4327 } elseif
{$current_diff_path ne
{}} {
4329 "Adding [short_path $current_diff_path]" \
4330 [list
$current_diff_path]
4334 proc do_add_all
{} {
4338 foreach path
[array names file_states
] {
4339 switch
-glob -- [lindex
$file_states($path) 0] {
4342 ?D
{lappend paths
$path}
4345 add_helper
{Adding all changed files
} $paths
4348 proc revert_helper
{txt paths
} {
4349 global file_states current_diff_path
4351 if {![lock_index begin-update
]} return
4355 foreach path
$paths {
4356 switch
-glob -- [lindex
$file_states($path) 0] {
4360 lappend pathList
$path
4361 if {$path eq
$current_diff_path} {
4362 set after
{reshow_diff
;}
4368 set n
[llength
$pathList]
4372 } elseif
{$n == 1} {
4373 set s
"[short_path [lindex $pathList]]"
4375 set s
"these $n files"
4378 set reply
[tk_dialog \
4380 "[appname] ([reponame])" \
4381 "Revert changes in $s?
4383 Any unadded changes will be permanently lost by the revert." \
4393 [concat
$after {set ui_status_value
{Ready.
}}]
4399 proc do_revert_selection
{} {
4400 global current_diff_path selected_paths
4402 if {[array size selected_paths
] > 0} {
4404 {Reverting selected files
} \
4405 [array names selected_paths
]
4406 } elseif
{$current_diff_path ne
{}} {
4408 "Reverting [short_path $current_diff_path]" \
4409 [list
$current_diff_path]
4413 proc do_signoff
{} {
4416 set me
[committer_ident
]
4417 if {$me eq
{}} return
4419 set sob
"Signed-off-by: $me"
4420 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
4421 if {$last ne
$sob} {
4422 $ui_comm edit separator
4424 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
4425 $ui_comm insert end
"\n"
4427 $ui_comm insert end
"\n$sob"
4428 $ui_comm edit separator
4433 proc do_select_commit_type
{} {
4434 global commit_type selected_commit_type
4436 if {$selected_commit_type eq
{new
}
4437 && [string match amend
* $commit_type]} {
4439 } elseif
{$selected_commit_type eq
{amend
}
4440 && ![string match amend
* $commit_type]} {
4443 # The amend request was rejected...
4445 if {![string match amend
* $commit_type]} {
4446 set selected_commit_type new
4456 global appvers copyright
4457 global tcl_patchLevel tk_patchLevel
4461 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4463 label
$w.header
-text "About [appname]" \
4465 pack
$w.header
-side top
-fill x
4468 button
$w.buttons.close
-text {Close
} \
4470 -command [list destroy
$w]
4471 pack
$w.buttons.close
-side right
4472 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4475 -text "git-gui - a commit creation tool for Git.
4483 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
4486 append v
"git-gui version $appvers\n"
4487 append v
"[git version]\n"
4489 if {$tcl_patchLevel eq
$tk_patchLevel} {
4490 append v
"Tcl/Tk version $tcl_patchLevel"
4492 append v
"Tcl version $tcl_patchLevel"
4493 append v
", Tk version $tk_patchLevel"
4504 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
4506 menu
$w.ctxm
-tearoff 0
4507 $w.ctxm add
command \
4512 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
4515 bind $w <Visibility
> "grab $w; focus $w"
4516 bind $w <Key-Escape
> "destroy $w"
4517 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
4518 wm title
$w "About [appname]"
4522 proc do_options
{} {
4523 global repo_config global_config font_descs
4524 global repo_config_new global_config_new
4526 array
unset repo_config_new
4527 array
unset global_config_new
4528 foreach name
[array names repo_config
] {
4529 set repo_config_new
($name) $repo_config($name)
4532 foreach name
[array names repo_config
] {
4534 gui.diffcontext
{continue}
4536 set repo_config_new
($name) $repo_config($name)
4538 foreach name
[array names global_config
] {
4539 set global_config_new
($name) $global_config($name)
4542 set w .options_editor
4544 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4546 label
$w.header
-text "Options" \
4548 pack
$w.header
-side top
-fill x
4551 button
$w.buttons.restore
-text {Restore Defaults
} \
4553 -command do_restore_defaults
4554 pack
$w.buttons.restore
-side left
4555 button
$w.buttons.save
-text Save \
4557 -command [list do_save_config
$w]
4558 pack
$w.buttons.save
-side right
4559 button
$w.buttons.cancel
-text {Cancel
} \
4561 -command [list destroy
$w]
4562 pack
$w.buttons.cancel
-side right
-padx 5
4563 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4565 labelframe
$w.repo
-text "[reponame] Repository" \
4567 labelframe
$w.global
-text {Global
(All Repositories
)} \
4569 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
4570 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
4574 {t user.name
{User Name
}}
4575 {t user.email
{Email Address
}}
4577 {b merge.summary
{Summarize Merge Commits
}}
4578 {i-1.
.5 merge.verbosity
{Merge Verbosity
}}
4580 {b gui.trustmtime
{Trust File Modification Timestamps
}}
4581 {i-1.
.99 gui.diffcontext
{Number of Diff Context Lines
}}
4582 {t gui.newbranchtemplate
{New Branch Name Template
}}
4584 set type [lindex
$option 0]
4585 set name
[lindex
$option 1]
4586 set text
[lindex
$option 2]
4588 foreach f
{repo global
} {
4589 switch
-glob -- $type {
4591 checkbutton
$w.
$f.
$optid -text $text \
4592 -variable ${f}_config_new
($name) \
4596 pack
$w.
$f.
$optid -side top
-anchor w
4599 regexp
-- {-(\d
+)\.\.
(\d
+)$
} $type _junk min max
4601 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4602 pack
$w.
$f.
$optid.l
-side left
-anchor w
-fill x
4603 spinbox
$w.
$f.
$optid.v \
4604 -textvariable ${f}_config_new
($name) \
4608 -width [expr {1 + [string length
$max]}] \
4610 bind $w.
$f.
$optid.v
<FocusIn
> {%W selection range
0 end
}
4611 pack
$w.
$f.
$optid.v
-side right
-anchor e
-padx 5
4612 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4616 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4617 entry
$w.
$f.
$optid.v \
4621 -textvariable ${f}_config_new
($name) \
4623 pack
$w.
$f.
$optid.l
-side left
-anchor w
4624 pack
$w.
$f.
$optid.v
-side left
-anchor w \
4627 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4633 set all_fonts
[lsort
[font families
]]
4634 foreach option
$font_descs {
4635 set name
[lindex
$option 0]
4636 set font
[lindex
$option 1]
4637 set text
[lindex
$option 2]
4639 set global_config_new
(gui.
$font^^family
) \
4640 [font configure
$font -family]
4641 set global_config_new
(gui.
$font^^size
) \
4642 [font configure
$font -size]
4644 frame
$w.global.
$name
4645 label
$w.global.
$name.l
-text "$text:" -font font_ui
4646 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
4647 eval tk_optionMenu
$w.global.
$name.family \
4648 global_config_new
(gui.
$font^^family
) \
4650 spinbox
$w.global.
$name.size \
4651 -textvariable global_config_new
(gui.
$font^^size
) \
4652 -from 2 -to 80 -increment 1 \
4655 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
4656 pack
$w.global.
$name.size
-side right
-anchor e
4657 pack
$w.global.
$name.family
-side right
-anchor e
4658 pack
$w.global.
$name -side top
-anchor w
-fill x
4661 bind $w <Visibility
> "grab $w; focus $w"
4662 bind $w <Key-Escape
> "destroy $w"
4663 wm title
$w "[appname] ([reponame]): Options"
4667 proc do_restore_defaults
{} {
4668 global font_descs default_config repo_config
4669 global repo_config_new global_config_new
4671 foreach name
[array names default_config
] {
4672 set repo_config_new
($name) $default_config($name)
4673 set global_config_new
($name) $default_config($name)
4676 foreach option
$font_descs {
4677 set name
[lindex
$option 0]
4678 set repo_config
(gui.
$name) $default_config(gui.
$name)
4682 foreach option
$font_descs {
4683 set name
[lindex
$option 0]
4684 set font
[lindex
$option 1]
4685 set global_config_new
(gui.
$font^^family
) \
4686 [font configure
$font -family]
4687 set global_config_new
(gui.
$font^^size
) \
4688 [font configure
$font -size]
4692 proc do_save_config
{w
} {
4693 if {[catch
{save_config
} err
]} {
4694 error_popup
"Failed to completely save options:\n\n$err"
4700 proc do_windows_shortcut
{} {
4703 set fn
[tk_getSaveFile \
4705 -title "[appname] ([reponame]): Create Desktop Icon" \
4706 -initialfile "Git [reponame].bat"]
4710 puts
$fd "@ECHO Entering [reponame]"
4711 puts
$fd "@ECHO Starting git-gui... please wait..."
4712 puts
$fd "@SET PATH=[file normalize [gitexec]];%PATH%"
4713 puts
$fd "@SET GIT_DIR=[file normalize [gitdir]]"
4714 puts
-nonewline $fd "@\"[info nameofexecutable]\""
4715 puts
$fd " \"[file normalize $argv0]\""
4718 error_popup
"Cannot write script:\n\n$err"
4723 proc do_cygwin_shortcut
{} {
4727 set desktop
[exec cygpath \
4735 set fn
[tk_getSaveFile \
4737 -title "[appname] ([reponame]): Create Desktop Icon" \
4738 -initialdir $desktop \
4739 -initialfile "Git [reponame].bat"]
4743 set sh
[exec cygpath \
4747 set me
[exec cygpath \
4751 set gd
[exec cygpath \
4755 set gw
[exec cygpath \
4758 [file dirname [gitdir
]]]
4759 regsub
-all ' $me "'\\''" me
4760 regsub -all ' $gd "'\\''" gd
4761 puts $fd "@ECHO Entering $gw"
4762 puts $fd "@ECHO Starting git-gui... please wait..."
4763 puts -nonewline $fd "@\"$sh\" --login -c \""
4764 puts -nonewline $fd "GIT_DIR='$gd'"
4765 puts -nonewline $fd " '$me'"
4769 error_popup "Cannot write script:\n\n$err"
4774 proc do_macosx_app {} {
4777 set fn [tk_getSaveFile \
4779 -title "[appname] ([reponame]): Create Desktop Icon" \
4780 -initialdir [file join $env(HOME) Desktop] \
4781 -initialfile "Git [reponame].app"]
4784 set Contents [file join $fn Contents]
4785 set MacOS [file join $Contents MacOS]
4786 set exe [file join $MacOS git-gui]
4790 set fd [open [file join $Contents Info.plist] w]
4791 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
4792 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4793 <plist version="1.0">
4795 <key>CFBundleDevelopmentRegion</key>
4796 <string>English</string>
4797 <key>CFBundleExecutable</key>
4798 <string>git-gui</string>
4799 <key>CFBundleIdentifier</key>
4800 <string>org.spearce.git-gui</string>
4801 <key>CFBundleInfoDictionaryVersion</key>
4802 <string>6.0</string>
4803 <key>CFBundlePackageType</key>
4804 <string>APPL</string>
4805 <key>CFBundleSignature</key>
4806 <string>????</string>
4807 <key>CFBundleVersion</key>
4808 <string>1.0</string>
4809 <key>NSPrincipalClass</key>
4810 <string>NSApplication</string>
4815 set fd [open $exe w]
4816 set gd [file normalize [gitdir]]
4817 set ep [file normalize [gitexec]]
4818 regsub -all ' $gd "'\\''" gd
4819 regsub
-all ' $ep "'\\''" ep
4820 puts $fd "#!/bin/sh"
4821 foreach name
[array names env
] {
4822 if {[string match GIT_
* $name]} {
4823 regsub
-all ' $env($name) "'\\''" v
4824 puts $fd "export $name='$v'"
4827 puts $fd "export PATH
='$ep':\
$PATH"
4828 puts $fd "export GIT_DIR
='$gd'"
4829 puts $fd "exec [file normalize
$argv0]"
4832 file attributes $exe -permissions u+x,g+x,o+x
4834 error_popup "Cannot
write icon
:\n\n$err"
4839 proc toggle_or_diff {w x y} {
4840 global file_states file_lists current_diff_path ui_index ui_workdir
4841 global last_clicked selected_paths
4843 set pos [split [$w index @$x,$y] .]
4844 set lno [lindex $pos 0]
4845 set col [lindex $pos 1]
4846 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4852 set last_clicked [list $w $lno]
4853 array unset selected_paths
4854 $ui_index tag remove in_sel 0.0 end
4855 $ui_workdir tag remove in_sel 0.0 end
4858 if {$current_diff_path eq $path} {
4859 set after {reshow_diff;}
4863 if {$w eq $ui_index} {
4865 "Unstaging
[short_path
$path] from commit
" \
4867 [concat $after {set ui_status_value {Ready.}}]
4868 } elseif {$w eq $ui_workdir} {
4870 "Adding
[short_path
$path]" \
4872 [concat $after {set ui_status_value {Ready.}}]
4875 show_diff $path $w $lno
4879 proc add_one_to_selection {w x y} {
4880 global file_lists last_clicked selected_paths
4882 set lno [lindex [split [$w index @$x,$y] .] 0]
4883 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4889 if {$last_clicked ne {}
4890 && [lindex $last_clicked 0] ne $w} {
4891 array unset selected_paths
4892 [lindex $last_clicked 0] tag remove in_sel 0.0 end
4895 set last_clicked [list $w $lno]
4896 if {[catch {set in_sel $selected_paths($path)}]} {
4900 unset selected_paths($path)
4901 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
4903 set selected_paths($path) 1
4904 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
4908 proc add_range_to_selection {w x y} {
4909 global file_lists last_clicked selected_paths
4911 if {[lindex $last_clicked 0] ne $w} {
4912 toggle_or_diff $w $x $y
4916 set lno [lindex [split [$w index @$x,$y] .] 0]
4917 set lc [lindex $last_clicked 1]
4926 foreach path [lrange $file_lists($w) \
4927 [expr {$begin - 1}] \
4928 [expr {$end - 1}]] {
4929 set selected_paths($path) 1
4931 $w tag add in_sel $begin.0 [expr {$end + 1}].0
4934 ######################################################################
4938 set cursor_ptr arrow
4939 font create font_diff -family Courier -size 10
4943 eval font configure font_ui [font actual [.dummy cget -font]]
4947 font create font_uibold
4948 font create font_diffbold
4953 } elseif {[is_MacOSX]} {
4961 proc apply_config {} {
4962 global repo_config font_descs
4964 foreach option $font_descs {
4965 set name [lindex $option 0]
4966 set font [lindex $option 1]
4968 foreach {cn cv} $repo_config(gui.$name) {
4969 font configure $font $cn $cv
4972 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
4974 foreach {cn cv} [font configure $font] {
4975 font configure ${font}bold $cn $cv
4977 font configure ${font}bold -weight bold
4981 set default_config(merge.summary) false
4982 set default_config(merge.verbosity) 2
4983 set default_config(user.name) {}
4984 set default_config(user.email) {}
4986 set default_config(gui.trustmtime) false
4987 set default_config(gui.diffcontext) 5
4988 set default_config(gui.newbranchtemplate) {}
4989 set default_config(gui.fontui) [font configure font_ui]
4990 set default_config(gui.fontdiff) [font configure font_diff]
4992 {fontui font_ui {Main Font}}
4993 {fontdiff font_diff {Diff/Console Font}}
4998 ######################################################################
5000 ## feature option selection
5002 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
5007 if {$subcommand eq {gui.sh}} {
5010 if {$subcommand eq {gui} && [llength $argv] > 0} {
5011 set subcommand [lindex $argv 0]
5012 set argv [lrange $argv 1 end]
5015 enable_option multicommit
5016 enable_option branch
5017 enable_option transport
5019 switch -- $subcommand {
5023 disable_option multicommit
5024 disable_option branch
5025 disable_option transport
5028 enable_option singlecommit
5030 disable_option multicommit
5031 disable_option branch
5032 disable_option transport
5036 ######################################################################
5044 menu .mbar -tearoff 0
5045 .mbar add cascade -label Repository -menu .mbar.repository
5046 .mbar add cascade -label Edit -menu .mbar.edit
5047 if {[is_enabled branch]} {
5048 .mbar add cascade -label Branch -menu .mbar.branch
5050 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
5051 .mbar add cascade -label Commit -menu .mbar.commit
5053 if {[is_enabled transport]} {
5054 .mbar add cascade -label Merge -menu .mbar.merge
5055 .mbar add cascade -label Fetch -menu .mbar.fetch
5056 .mbar add cascade -label Push -menu .mbar.push
5058 . configure -menu .mbar
5060 # -- Repository Menu
5062 menu .mbar.repository
5064 .mbar.repository add command \
5065 -label {Browse Current Branch} \
5066 -command {new_browser $current_branch} \
5068 trace add variable current_branch write ".mbar.repository entryconf
[.mbar.repository index last
] -label \"Browse \
$current_branch\" ;#"
5069 .mbar.repository add separator
5071 .mbar.repository add
command \
5072 -label {Visualize Current Branch
} \
5073 -command {do_gitk
$current_branch} \
5075 trace add variable current_branch
write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#"
5076 .mbar.repository add
command \
5077 -label {Visualize All Branches
} \
5078 -command {do_gitk
--all} \
5080 .mbar.repository add separator
5082 if {[is_enabled multicommit
]} {
5083 .mbar.repository add
command -label {Database Statistics
} \
5087 .mbar.repository add
command -label {Compress Database
} \
5091 .mbar.repository add
command -label {Verify Database
} \
5092 -command do_fsck_objects \
5095 .mbar.repository add separator
5098 .mbar.repository add
command \
5099 -label {Create Desktop Icon
} \
5100 -command do_cygwin_shortcut \
5102 } elseif
{[is_Windows
]} {
5103 .mbar.repository add
command \
5104 -label {Create Desktop Icon
} \
5105 -command do_windows_shortcut \
5107 } elseif
{[is_MacOSX
]} {
5108 .mbar.repository add
command \
5109 -label {Create Desktop Icon
} \
5110 -command do_macosx_app \
5115 .mbar.repository add
command -label Quit \
5117 -accelerator $M1T-Q \
5123 .mbar.edit add
command -label Undo \
5124 -command {catch
{[focus
] edit undo
}} \
5125 -accelerator $M1T-Z \
5127 .mbar.edit add
command -label Redo \
5128 -command {catch
{[focus
] edit redo
}} \
5129 -accelerator $M1T-Y \
5131 .mbar.edit add separator
5132 .mbar.edit add
command -label Cut \
5133 -command {catch
{tk_textCut
[focus
]}} \
5134 -accelerator $M1T-X \
5136 .mbar.edit add
command -label Copy \
5137 -command {catch
{tk_textCopy
[focus
]}} \
5138 -accelerator $M1T-C \
5140 .mbar.edit add
command -label Paste \
5141 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
5142 -accelerator $M1T-V \
5144 .mbar.edit add
command -label Delete \
5145 -command {catch
{[focus
] delete sel.first sel.last
}} \
5148 .mbar.edit add separator
5149 .mbar.edit add
command -label {Select All
} \
5150 -command {catch
{[focus
] tag add sel
0.0 end
}} \
5151 -accelerator $M1T-A \
5156 if {[is_enabled branch
]} {
5159 .mbar.branch add
command -label {Create...
} \
5160 -command do_create_branch \
5161 -accelerator $M1T-N \
5163 lappend disable_on_lock
[list .mbar.branch entryconf \
5164 [.mbar.branch index last
] -state]
5166 .mbar.branch add
command -label {Delete...
} \
5167 -command do_delete_branch \
5169 lappend disable_on_lock
[list .mbar.branch entryconf \
5170 [.mbar.branch index last
] -state]
5175 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
5178 .mbar.commit add radiobutton \
5179 -label {New Commit
} \
5180 -command do_select_commit_type \
5181 -variable selected_commit_type \
5184 lappend disable_on_lock \
5185 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5187 .mbar.commit add radiobutton \
5188 -label {Amend Last Commit
} \
5189 -command do_select_commit_type \
5190 -variable selected_commit_type \
5193 lappend disable_on_lock \
5194 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5196 .mbar.commit add separator
5198 .mbar.commit add
command -label Rescan \
5199 -command do_rescan \
5202 lappend disable_on_lock \
5203 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5205 .mbar.commit add
command -label {Add To Commit
} \
5206 -command do_add_selection \
5208 lappend disable_on_lock \
5209 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5211 .mbar.commit add
command -label {Add Existing To Commit
} \
5212 -command do_add_all \
5213 -accelerator $M1T-I \
5215 lappend disable_on_lock \
5216 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5218 .mbar.commit add
command -label {Unstage From Commit
} \
5219 -command do_unstage_selection \
5221 lappend disable_on_lock \
5222 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5224 .mbar.commit add
command -label {Revert Changes
} \
5225 -command do_revert_selection \
5227 lappend disable_on_lock \
5228 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5230 .mbar.commit add separator
5232 .mbar.commit add
command -label {Sign Off
} \
5233 -command do_signoff \
5234 -accelerator $M1T-S \
5237 .mbar.commit add
command -label Commit \
5238 -command do_commit \
5239 -accelerator $M1T-Return \
5241 lappend disable_on_lock \
5242 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5246 # -- Apple Menu (Mac OS X only)
5248 .mbar add cascade
-label Apple
-menu .mbar.apple
5251 .mbar.apple add
command -label "About [appname]" \
5254 .mbar.apple add
command -label "Options..." \
5255 -command do_options \
5260 .mbar.edit add separator
5261 .mbar.edit add
command -label {Options...
} \
5262 -command do_options \
5267 if {[file exists
/usr
/local
/miga
/lib
/gui-miga
]
5268 && [file exists .pvcsrc
]} {
5270 global ui_status_value
5271 if {![lock_index update
]} return
5272 set cmd
[list sh
--login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
5273 set miga_fd
[open
"|$cmd" r
]
5274 fconfigure
$miga_fd -blocking 0
5275 fileevent
$miga_fd readable
[list miga_done
$miga_fd]
5276 set ui_status_value
{Running miga...
}
5278 proc miga_done
{fd
} {
5283 rescan
[list
set ui_status_value
{Ready.
}]
5286 .mbar add cascade
-label Tools
-menu .mbar.tools
5288 .mbar.tools add
command -label "Migrate" \
5291 lappend disable_on_lock \
5292 [list .mbar.tools entryconf
[.mbar.tools index last
] -state]
5298 .mbar add cascade
-label Help
-menu .mbar.
help
5302 .mbar.
help add
command -label "About [appname]" \
5308 catch
{set browser
$repo_config(instaweb.browser
)}
5309 set doc_path
[file dirname [gitexec
]]
5310 set doc_path
[file join $doc_path Documentation index.html
]
5313 set doc_path
[exec cygpath
--windows $doc_path]
5316 if {$browser eq
{}} {
5319 } elseif
{[is_Cygwin
]} {
5320 set program_files
[file dirname [exec cygpath
--windir]]
5321 set program_files
[file join $program_files {Program Files
}]
5322 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
5323 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
5324 if {[file exists
$firefox]} {
5325 set browser
$firefox
5326 } elseif
{[file exists
$ie]} {
5329 unset program_files firefox ie
5333 if {[file isfile
$doc_path]} {
5334 set doc_url
"file:$doc_path"
5336 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
5339 if {$browser ne
{}} {
5340 .mbar.
help add
command -label {Online Documentation
} \
5341 -command [list
exec $browser $doc_url &] \
5344 unset browser doc_path doc_url
5346 # -- Standard bindings
5348 bind .
<Destroy
> do_quit
5349 bind all
<$M1B-Key-q> do_quit
5350 bind all
<$M1B-Key-Q> do_quit
5351 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
5352 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
5354 # -- Not a normal commit type invocation? Do that instead!
5356 switch
-- $subcommand {
5359 puts
"git-gui version $appvers"
5363 if {[llength
$argv] != 2} {
5364 puts stderr
"usage: $argv0 blame commit path"
5367 set current_branch
[lindex
$argv 0]
5368 show_blame
$current_branch [lindex
$argv 1]
5373 if {[llength
$argv] != 0} {
5374 puts
-nonewline stderr
"usage: $argv0"
5375 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
5376 puts
-nonewline stderr
" $subcommand"
5381 # fall through to setup UI for commits
5384 puts stderr
"usage: $argv0 \[{blame|citool}\]"
5395 -text {Current Branch
:} \
5400 -textvariable current_branch \
5404 pack .branch.l1
-side left
5405 pack .branch.cb
-side left
-fill x
5406 pack .branch
-side top
-fill x
5408 if {[is_enabled branch
]} {
5410 .mbar.merge add
command -label {Local Merge...
} \
5411 -command do_local_merge \
5413 lappend disable_on_lock \
5414 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5415 .mbar.merge add
command -label {Abort Merge...
} \
5416 -command do_reset_hard \
5418 lappend disable_on_lock \
5419 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5425 .mbar.push add
command -label {Push...
} \
5426 -command do_push_anywhere \
5430 # -- Main Window Layout
5432 panedwindow .vpane
-orient vertical
5433 panedwindow .vpane.files
-orient horizontal
5434 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
5435 pack .vpane
-anchor n
-side top
-fill both
-expand 1
5437 # -- Index File List
5439 frame .vpane.files.index
-height 100 -width 200
5440 label .vpane.files.index.title
-text {Changes To Be Committed
} \
5443 text
$ui_index -background white
-borderwidth 0 \
5444 -width 20 -height 10 \
5447 -cursor $cursor_ptr \
5448 -xscrollcommand {.vpane.files.index.sx
set} \
5449 -yscrollcommand {.vpane.files.index.sy
set} \
5451 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
5452 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
5453 pack .vpane.files.index.title
-side top
-fill x
5454 pack .vpane.files.index.sx
-side bottom
-fill x
5455 pack .vpane.files.index.sy
-side right
-fill y
5456 pack
$ui_index -side left
-fill both
-expand 1
5457 .vpane.files add .vpane.files.index
-sticky nsew
5459 # -- Working Directory File List
5461 frame .vpane.files.workdir
-height 100 -width 200
5462 label .vpane.files.workdir.title
-text {Changed But Not Updated
} \
5465 text
$ui_workdir -background white
-borderwidth 0 \
5466 -width 20 -height 10 \
5469 -cursor $cursor_ptr \
5470 -xscrollcommand {.vpane.files.workdir.sx
set} \
5471 -yscrollcommand {.vpane.files.workdir.sy
set} \
5473 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
5474 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
5475 pack .vpane.files.workdir.title
-side top
-fill x
5476 pack .vpane.files.workdir.sx
-side bottom
-fill x
5477 pack .vpane.files.workdir.sy
-side right
-fill y
5478 pack
$ui_workdir -side left
-fill both
-expand 1
5479 .vpane.files add .vpane.files.workdir
-sticky nsew
5481 foreach i
[list
$ui_index $ui_workdir] {
5482 $i tag conf in_diff
-font font_uibold
5483 $i tag conf in_sel \
5484 -background [$i cget
-foreground] \
5485 -foreground [$i cget
-background]
5489 # -- Diff and Commit Area
5491 frame .vpane.lower
-height 300 -width 400
5492 frame .vpane.lower.commarea
5493 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
5494 pack .vpane.lower.commarea
-side top
-fill x
5495 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
5496 .vpane add .vpane.lower
-sticky nsew
5498 # -- Commit Area Buttons
5500 frame .vpane.lower.commarea.buttons
5501 label .vpane.lower.commarea.buttons.l
-text {} \
5505 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
5506 pack .vpane.lower.commarea.buttons
-side left
-fill y
5508 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
5509 -command do_rescan \
5511 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
5512 lappend disable_on_lock \
5513 {.vpane.lower.commarea.buttons.rescan conf
-state}
5515 button .vpane.lower.commarea.buttons.incall
-text {Add Existing
} \
5516 -command do_add_all \
5518 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
5519 lappend disable_on_lock \
5520 {.vpane.lower.commarea.buttons.incall conf
-state}
5522 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
5523 -command do_signoff \
5525 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
5527 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
5528 -command do_commit \
5530 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
5531 lappend disable_on_lock \
5532 {.vpane.lower.commarea.buttons.commit conf
-state}
5534 # -- Commit Message Buffer
5536 frame .vpane.lower.commarea.buffer
5537 frame .vpane.lower.commarea.buffer.header
5538 set ui_comm .vpane.lower.commarea.buffer.t
5539 set ui_coml .vpane.lower.commarea.buffer.header.l
5540 radiobutton .vpane.lower.commarea.buffer.header.new \
5541 -text {New Commit
} \
5542 -command do_select_commit_type \
5543 -variable selected_commit_type \
5546 lappend disable_on_lock \
5547 [list .vpane.lower.commarea.buffer.header.new conf
-state]
5548 radiobutton .vpane.lower.commarea.buffer.header.amend \
5549 -text {Amend Last Commit
} \
5550 -command do_select_commit_type \
5551 -variable selected_commit_type \
5554 lappend disable_on_lock \
5555 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
5560 proc trace_commit_type
{varname args
} {
5561 global ui_coml commit_type
5562 switch
-glob -- $commit_type {
5563 initial
{set txt
{Initial Commit Message
:}}
5564 amend
{set txt
{Amended Commit Message
:}}
5565 amend-initial
{set txt
{Amended Initial Commit Message
:}}
5566 amend-merge
{set txt
{Amended Merge Commit Message
:}}
5567 merge
{set txt
{Merge Commit Message
:}}
5568 * {set txt
{Commit Message
:}}
5570 $ui_coml conf
-text $txt
5572 trace add variable commit_type
write trace_commit_type
5573 pack
$ui_coml -side left
-fill x
5574 pack .vpane.lower.commarea.buffer.header.amend
-side right
5575 pack .vpane.lower.commarea.buffer.header.new
-side right
5577 text
$ui_comm -background white
-borderwidth 1 \
5580 -autoseparators true \
5582 -width 75 -height 9 -wrap none \
5584 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
5585 scrollbar .vpane.lower.commarea.buffer.sby \
5586 -command [list
$ui_comm yview
]
5587 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
5588 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
5589 pack
$ui_comm -side left
-fill y
5590 pack .vpane.lower.commarea.buffer
-side left
-fill y
5592 # -- Commit Message Buffer Context Menu
5594 set ctxm .vpane.lower.commarea.buffer.ctxm
5595 menu
$ctxm -tearoff 0
5599 -command {tk_textCut
$ui_comm}
5603 -command {tk_textCopy
$ui_comm}
5607 -command {tk_textPaste
$ui_comm}
5611 -command {$ui_comm delete sel.first sel.last
}
5614 -label {Select All
} \
5616 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
5621 $ui_comm tag add sel
0.0 end
5622 tk_textCopy
$ui_comm
5623 $ui_comm tag remove sel
0.0 end
5630 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
5634 set current_diff_path
{}
5635 set current_diff_side
{}
5636 set diff_actions
[list
]
5637 proc trace_current_diff_path
{varname args
} {
5638 global current_diff_path diff_actions file_states
5639 if {$current_diff_path eq
{}} {
5645 set p
$current_diff_path
5646 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
5648 set p
[escape_path
$p]
5652 .vpane.lower.
diff.header.status configure
-text $s
5653 .vpane.lower.
diff.header.
file configure
-text $f
5654 .vpane.lower.
diff.header.path configure
-text $p
5655 foreach w
$diff_actions {
5659 trace add variable current_diff_path
write trace_current_diff_path
5661 frame .vpane.lower.
diff.header
-background orange
5662 label .vpane.lower.
diff.header.status \
5663 -background orange \
5664 -width $max_status_desc \
5668 label .vpane.lower.
diff.header.
file \
5669 -background orange \
5673 label .vpane.lower.
diff.header.path \
5674 -background orange \
5678 pack .vpane.lower.
diff.header.status
-side left
5679 pack .vpane.lower.
diff.header.
file -side left
5680 pack .vpane.lower.
diff.header.path
-fill x
5681 set ctxm .vpane.lower.
diff.header.ctxm
5682 menu
$ctxm -tearoff 0
5691 -- $current_diff_path
5693 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5694 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
5698 frame .vpane.lower.
diff.body
5699 set ui_diff .vpane.lower.
diff.body.t
5700 text
$ui_diff -background white
-borderwidth 0 \
5701 -width 80 -height 15 -wrap none \
5703 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
5704 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
5706 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
5707 -command [list
$ui_diff xview
]
5708 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
5709 -command [list
$ui_diff yview
]
5710 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
5711 pack .vpane.lower.
diff.body.sby
-side right
-fill y
5712 pack
$ui_diff -side left
-fill both
-expand 1
5713 pack .vpane.lower.
diff.header
-side top
-fill x
5714 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
5716 $ui_diff tag conf d_cr
-elide true
5717 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
5718 $ui_diff tag conf d_
+ -foreground {#00a000}
5719 $ui_diff tag conf d_-
-foreground red
5721 $ui_diff tag conf d_
++ -foreground {#00a000}
5722 $ui_diff tag conf d_--
-foreground red
5723 $ui_diff tag conf d_
+s \
5724 -foreground {#00a000} \
5725 -background {#e2effa}
5726 $ui_diff tag conf d_-s \
5728 -background {#e2effa}
5729 $ui_diff tag conf d_s
+ \
5730 -foreground {#00a000} \
5732 $ui_diff tag conf d_s- \
5736 $ui_diff tag conf d
<<<<<<< \
5737 -foreground orange \
5739 $ui_diff tag conf d
======= \
5740 -foreground orange \
5742 $ui_diff tag conf d
>>>>>>> \
5743 -foreground orange \
5746 $ui_diff tag raise sel
5748 # -- Diff Body Context Menu
5750 set ctxm .vpane.lower.
diff.body.ctxm
5751 menu
$ctxm -tearoff 0
5755 -command reshow_diff
5756 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5760 -command {tk_textCopy
$ui_diff}
5761 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5763 -label {Select All
} \
5765 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
5766 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5771 $ui_diff tag add sel
0.0 end
5772 tk_textCopy
$ui_diff
5773 $ui_diff tag remove sel
0.0 end
5775 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5778 -label {Apply
/Reverse Hunk
} \
5780 -command {apply_hunk
$cursorX $cursorY}
5781 set ui_diff_applyhunk
[$ctxm index last
]
5782 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
5785 -label {Decrease Font Size
} \
5787 -command {incr_font_size font_diff
-1}
5788 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5790 -label {Increase Font Size
} \
5792 -command {incr_font_size font_diff
1}
5793 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5796 -label {Show Less Context
} \
5798 -command {if {$repo_config(gui.diffcontext
) >= 2} {
5799 incr repo_config
(gui.diffcontext
) -1
5802 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5804 -label {Show More Context
} \
5807 incr repo_config
(gui.diffcontext
)
5810 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5812 $ctxm add
command -label {Options...
} \
5815 bind_button3
$ui_diff "
5818 if {\$ui_index eq \$current_diff_side} {
5819 $ctxm entryconf $ui_diff_applyhunk -label {Unstage Hunk From Commit}
5821 $ctxm entryconf $ui_diff_applyhunk -label {Stage Hunk For Commit}
5823 tk_popup $ctxm %X %Y
5825 unset ui_diff_applyhunk
5829 set ui_status_value
{Initializing...
}
5830 label .status
-textvariable ui_status_value \
5836 pack .status
-anchor w
-side bottom
-fill x
5841 set gm
$repo_config(gui.geometry
)
5842 wm geometry .
[lindex
$gm 0]
5843 .vpane sash place
0 \
5844 [lindex
[.vpane sash coord
0] 0] \
5846 .vpane.files sash place
0 \
5848 [lindex
[.vpane.files sash coord
0] 1]
5854 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
5855 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
5856 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
5857 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
5858 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
5859 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
5860 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
5861 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
5862 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
5863 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5864 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5866 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
5867 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
5868 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
5869 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
5870 bind $ui_diff <$M1B-Key-v> {break}
5871 bind $ui_diff <$M1B-Key-V> {break}
5872 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5873 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5874 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
5875 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
5876 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
5877 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
5878 bind $ui_diff <Button-1
> {focus
%W
}
5880 if {[is_enabled branch
]} {
5881 bind .
<$M1B-Key-n> do_create_branch
5882 bind .
<$M1B-Key-N> do_create_branch
5885 bind all
<Key-F5
> do_rescan
5886 bind all
<$M1B-Key-r> do_rescan
5887 bind all
<$M1B-Key-R> do_rescan
5888 bind .
<$M1B-Key-s> do_signoff
5889 bind .
<$M1B-Key-S> do_signoff
5890 bind .
<$M1B-Key-i> do_add_all
5891 bind .
<$M1B-Key-I> do_add_all
5892 bind .
<$M1B-Key-Return> do_commit
5893 foreach i
[list
$ui_index $ui_workdir] {
5894 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
5895 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
5896 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
5900 set file_lists
($ui_index) [list
]
5901 set file_lists
($ui_workdir) [list
]
5905 set MERGE_HEAD
[list
]
5908 set current_branch
{}
5909 set current_diff_path
{}
5910 set selected_commit_type new
5912 wm title .
"[appname] ([file normalize [file dirname [gitdir]]])"
5913 focus
-force $ui_comm
5915 # -- Warn the user about environmental problems. Cygwin's Tcl
5916 # does *not* pass its env array onto any processes it spawns.
5917 # This means that git processes get none of our environment.
5922 set msg
"Possible environment issues exist.
5924 The following environment variables are probably
5925 going to be ignored by any Git subprocess run
5929 foreach name
[array names env
] {
5930 switch
-regexp -- $name {
5931 {^GIT_INDEX_FILE$
} -
5932 {^GIT_OBJECT_DIRECTORY$
} -
5933 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
5935 {^GIT_EXTERNAL_DIFF$
} -
5939 {^GIT_CONFIG_LOCAL$
} -
5940 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
5941 append msg
" - $name\n"
5944 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
5945 append msg
" - $name\n"
5947 set suggest_user
$name
5951 if {$ignored_env > 0} {
5953 This is due to a known issue with the
5954 Tcl binary distributed by Cygwin."
5956 if {$suggest_user ne
{}} {
5959 A good replacement for $suggest_user
5960 is placing values for the user.name and
5961 user.email settings into your personal
5967 unset ignored_env msg suggest_user name
5970 # -- Only initialize complex UI if we are going to stay running.
5972 if {[is_enabled transport
]} {
5976 populate_branch_menu
5981 # -- Only suggest a gc run if we are going to stay running.
5983 if {[is_enabled multicommit
]} {
5984 set object_limit
2000
5985 if {[is_Windows
]} {set object_limit
200}
5986 regexp
{^
([0-9]+) objects
,} [git count-objects
] _junk objects_current
5987 if {$objects_current >= $object_limit} {
5989 "This repository currently has $objects_current loose objects.
5991 To maintain optimal performance it is strongly
5992 recommended that you compress the database
5993 when more than $object_limit loose objects exist.
5995 Compress the database now?"] eq
yes} {
5999 unset object_limit _junk objects_current
6002 lock_index begin-read