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 do_create_branch_action
{w
} {
1920 global all_heads null_sha1 repo_config
1921 global create_branch_checkout create_branch_revtype
1922 global create_branch_head create_branch_trackinghead
1923 global create_branch_name create_branch_revexp
1925 set newbranch
$create_branch_name
1926 if {$newbranch eq
{}
1927 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1931 -title [wm title
$w] \
1933 -message "Please supply a branch name."
1934 focus
$w.desc.name_t
1937 if {![catch
{git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1941 -title [wm title
$w] \
1943 -message "Branch '$newbranch' already exists."
1944 focus
$w.desc.name_t
1947 if {[catch
{git check-ref-format
"heads/$newbranch"}]} {
1951 -title [wm title
$w] \
1953 -message "We do not like '$newbranch' as a branch name."
1954 focus
$w.desc.name_t
1959 switch
-- $create_branch_revtype {
1960 head {set rev $create_branch_head}
1961 tracking
{set rev $create_branch_trackinghead}
1962 expression
{set rev $create_branch_revexp}
1964 if {[catch
{set cmt
[git rev-parse
--verify "${rev}^0"]}]} {
1968 -title [wm title
$w] \
1970 -message "Invalid starting revision: $rev"
1973 set cmd
[list git update-ref
]
1975 lappend cmd
"branch: Created from $rev"
1976 lappend cmd
"refs/heads/$newbranch"
1978 lappend cmd
$null_sha1
1979 if {[catch
{eval exec $cmd} err
]} {
1983 -title [wm title
$w] \
1985 -message "Failed to create '$newbranch'.\n\n$err"
1989 lappend all_heads
$newbranch
1990 set all_heads
[lsort
$all_heads]
1991 populate_branch_menu
1993 if {$create_branch_checkout} {
1994 switch_branch
$newbranch
1998 proc radio_selector
{varname value args
} {
1999 upvar
#0 $varname var
2003 trace add variable create_branch_head
write \
2004 [list radio_selector create_branch_revtype
head]
2005 trace add variable create_branch_trackinghead
write \
2006 [list radio_selector create_branch_revtype tracking
]
2008 trace add variable delete_branch_head
write \
2009 [list radio_selector delete_branch_checktype
head]
2010 trace add variable delete_branch_trackinghead
write \
2011 [list radio_selector delete_branch_checktype tracking
]
2013 proc do_create_branch
{} {
2014 global all_heads current_branch repo_config
2015 global create_branch_checkout create_branch_revtype
2016 global create_branch_head create_branch_trackinghead
2017 global create_branch_name create_branch_revexp
2019 set w .branch_editor
2021 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2023 label
$w.header
-text {Create New Branch
} \
2025 pack
$w.header
-side top
-fill x
2028 button
$w.buttons.create
-text Create \
2031 -command [list do_create_branch_action
$w]
2032 pack
$w.buttons.create
-side right
2033 button
$w.buttons.cancel
-text {Cancel
} \
2035 -command [list destroy
$w]
2036 pack
$w.buttons.cancel
-side right
-padx 5
2037 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2039 labelframe
$w.desc \
2040 -text {Branch Description
} \
2042 label
$w.desc.name_l
-text {Name
:} -font font_ui
2043 entry
$w.desc.name_t \
2047 -textvariable create_branch_name \
2051 if {%d
== 1 && [regexp
{[~^
:?
*\
[\
0- ]} %S
]} {return 0}
2054 grid
$w.desc.name_l
$w.desc.name_t
-sticky we
-padx {0 5}
2055 grid columnconfigure
$w.desc
1 -weight 1
2056 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
2058 labelframe
$w.from \
2059 -text {Starting Revision
} \
2061 radiobutton
$w.from.head_r \
2062 -text {Local Branch
:} \
2064 -variable create_branch_revtype \
2066 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
2067 grid
$w.from.head_r
$w.from.head_m
-sticky w
2068 set all_trackings
[all_tracking_branches
]
2069 if {$all_trackings ne
{}} {
2070 set create_branch_trackinghead
[lindex
$all_trackings 0]
2071 radiobutton
$w.from.tracking_r \
2072 -text {Tracking Branch
:} \
2074 -variable create_branch_revtype \
2076 eval tk_optionMenu
$w.from.tracking_m \
2077 create_branch_trackinghead \
2079 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
2081 radiobutton
$w.from.exp_r \
2082 -text {Revision Expression
:} \
2084 -variable create_branch_revtype \
2086 entry
$w.from.exp_t \
2090 -textvariable create_branch_revexp \
2094 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2095 if {%d
== 1 && [string length
%S
] > 0} {
2096 set create_branch_revtype expression
2100 grid
$w.from.exp_r
$w.from.exp_t
-sticky we
-padx {0 5}
2101 grid columnconfigure
$w.from
1 -weight 1
2102 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
2104 labelframe
$w.postActions \
2105 -text {Post Creation Actions
} \
2107 checkbutton
$w.postActions.checkout \
2108 -text {Checkout after creation
} \
2109 -variable create_branch_checkout \
2111 pack
$w.postActions.checkout
-anchor nw
2112 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
2114 set create_branch_checkout
1
2115 set create_branch_head
$current_branch
2116 set create_branch_revtype
head
2117 set create_branch_name
$repo_config(gui.newbranchtemplate
)
2118 set create_branch_revexp
{}
2120 bind $w <Visibility
> "
2122 $w.desc.name_t icursor end
2123 focus $w.desc.name_t
2125 bind $w <Key-Escape
> "destroy $w"
2126 bind $w <Key-Return
> "do_create_branch_action $w;break"
2127 wm title
$w "[appname] ([reponame]): Create Branch"
2131 proc do_delete_branch_action
{w
} {
2133 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2136 switch
-- $delete_branch_checktype {
2137 head {set check_rev
$delete_branch_head}
2138 tracking
{set check_rev
$delete_branch_trackinghead}
2139 always
{set check_rev
{:none
}}
2141 if {$check_rev eq
{:none
}} {
2143 } elseif
{[catch
{set check_cmt
[git rev-parse
--verify "${check_rev}^0"]}]} {
2147 -title [wm title
$w] \
2149 -message "Invalid check revision: $check_rev"
2153 set to_delete
[list
]
2154 set not_merged
[list
]
2155 foreach i
[$w.list.l curselection
] {
2156 set b
[$w.list.l get
$i]
2157 if {[catch
{set o
[git rev-parse
--verify $b]}]} continue
2158 if {$check_cmt ne
{}} {
2159 if {$b eq
$check_rev} continue
2160 if {[catch
{set m
[git merge-base
$o $check_cmt]}]} continue
2162 lappend not_merged
$b
2166 lappend to_delete
[list
$b $o]
2168 if {$not_merged ne
{}} {
2169 set msg
"The following branches are not completely merged into $check_rev:
2171 - [join $not_merged "\n - "]"
2175 -title [wm title
$w] \
2179 if {$to_delete eq
{}} return
2180 if {$delete_branch_checktype eq
{always
}} {
2181 set msg
{Recovering deleted branches is difficult.
2183 Delete the selected branches?
}
2184 if {[tk_messageBox \
2187 -title [wm title
$w] \
2189 -message $msg] ne
yes} {
2195 foreach i
$to_delete {
2198 if {[catch
{git update-ref
-d "refs/heads/$b" $o} err
]} {
2199 append failed
" - $b: $err\n"
2201 set x
[lsearch
-sorted -exact $all_heads $b]
2203 set all_heads
[lreplace
$all_heads $x $x]
2208 if {$failed ne
{}} {
2212 -title [wm title
$w] \
2214 -message "Failed to delete branches:\n$failed"
2217 set all_heads
[lsort
$all_heads]
2218 populate_branch_menu
2222 proc do_delete_branch
{} {
2223 global all_heads tracking_branches current_branch
2224 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2226 set w .branch_editor
2228 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2230 label
$w.header
-text {Delete Local Branch
} \
2232 pack
$w.header
-side top
-fill x
2235 button
$w.buttons.create
-text Delete \
2237 -command [list do_delete_branch_action
$w]
2238 pack
$w.buttons.create
-side right
2239 button
$w.buttons.cancel
-text {Cancel
} \
2241 -command [list destroy
$w]
2242 pack
$w.buttons.cancel
-side right
-padx 5
2243 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2245 labelframe
$w.list \
2246 -text {Local Branches
} \
2251 -selectmode extended \
2252 -yscrollcommand [list
$w.list.sby
set] \
2254 foreach h
$all_heads {
2255 if {$h ne
$current_branch} {
2256 $w.list.l insert end
$h
2259 scrollbar
$w.list.sby
-command [list
$w.list.l yview
]
2260 pack
$w.list.sby
-side right
-fill y
2261 pack
$w.list.l
-side left
-fill both
-expand 1
2262 pack
$w.list
-fill both
-expand 1 -pady 5 -padx 5
2264 labelframe
$w.validate \
2265 -text {Delete Only If
} \
2267 radiobutton
$w.validate.head_r \
2268 -text {Merged Into Local Branch
:} \
2270 -variable delete_branch_checktype \
2272 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2273 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2274 set all_trackings
[all_tracking_branches
]
2275 if {$all_trackings ne
{}} {
2276 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2277 radiobutton
$w.validate.tracking_r \
2278 -text {Merged Into Tracking Branch
:} \
2280 -variable delete_branch_checktype \
2282 eval tk_optionMenu
$w.validate.tracking_m \
2283 delete_branch_trackinghead \
2285 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2287 radiobutton
$w.validate.always_r \
2288 -text {Always
(Do not perform merge checks
)} \
2290 -variable delete_branch_checktype \
2292 grid
$w.validate.always_r
-columnspan 2 -sticky w
2293 grid columnconfigure
$w.validate
1 -weight 1
2294 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2296 set delete_branch_head
$current_branch
2297 set delete_branch_checktype
head
2299 bind $w <Visibility
> "grab $w; focus $w"
2300 bind $w <Key-Escape
> "destroy $w"
2301 wm title
$w "[appname] ([reponame]): Delete Branch"
2305 proc switch_branch
{new_branch
} {
2306 global HEAD commit_type current_branch repo_config
2308 if {![lock_index switch
]} return
2310 # -- Our in memory state should match the repository.
2312 repository_state curType curHEAD curMERGE_HEAD
2313 if {[string match amend
* $commit_type]
2314 && $curType eq
{normal
}
2315 && $curHEAD eq
$HEAD} {
2316 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2317 info_popup
{Last scanned state does not match repository state.
2319 Another Git program has modified this repository
2320 since the last scan. A rescan must be performed
2321 before the current branch can be changed.
2323 The rescan will be automatically started now.
2326 rescan
{set ui_status_value
{Ready.
}}
2330 # -- Don't do a pointless switch.
2332 if {$current_branch eq
$new_branch} {
2337 if {$repo_config(gui.trustmtime
) eq
{true
}} {
2338 switch_branch_stage2
{} $new_branch
2340 set ui_status_value
{Refreshing
file status...
}
2341 set cmd
[list git update-index
]
2343 lappend cmd
--unmerged
2344 lappend cmd
--ignore-missing
2345 lappend cmd
--refresh
2346 set fd_rf
[open
"| $cmd" r
]
2347 fconfigure
$fd_rf -blocking 0 -translation binary
2348 fileevent
$fd_rf readable \
2349 [list switch_branch_stage2
$fd_rf $new_branch]
2353 proc switch_branch_stage2
{fd_rf new_branch
} {
2354 global ui_status_value HEAD
2358 if {![eof
$fd_rf]} return
2362 set ui_status_value
"Updating working directory to '$new_branch'..."
2363 set cmd
[list git read-tree
]
2366 lappend cmd
--exclude-per-directory=.gitignore
2368 lappend cmd
$new_branch
2369 set fd_rt
[open
"| $cmd" r
]
2370 fconfigure
$fd_rt -blocking 0 -translation binary
2371 fileevent
$fd_rt readable \
2372 [list switch_branch_readtree_wait
$fd_rt $new_branch]
2375 proc switch_branch_readtree_wait
{fd_rt new_branch
} {
2376 global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
2377 global current_branch
2378 global ui_comm ui_status_value
2380 # -- We never get interesting output on stdout; only stderr.
2383 fconfigure
$fd_rt -blocking 1
2384 if {![eof
$fd_rt]} {
2385 fconfigure
$fd_rt -blocking 0
2389 # -- The working directory wasn't in sync with the index and
2390 # we'd have to overwrite something to make the switch. A
2391 # merge is required.
2393 if {[catch
{close
$fd_rt} err
]} {
2394 regsub
{^fatal
: } $err {} err
2395 warn_popup
"File level merge required.
2399 Staying on branch '$current_branch'."
2400 set ui_status_value
"Aborted checkout of '$new_branch' (file level merging is required)."
2405 # -- Update the symbolic ref. Core git doesn't even check for failure
2406 # here, it Just Works(tm). If it doesn't we are in some really ugly
2407 # state that is difficult to recover from within git-gui.
2409 if {[catch
{git symbolic-ref HEAD
"refs/heads/$new_branch"} err
]} {
2410 error_popup
"Failed to set current branch.
2412 This working directory is only partially switched.
2413 We successfully updated your files, but failed to
2414 update an internal Git file.
2416 This should not have occurred. [appname] will now
2424 # -- Update our repository state. If we were previously in amend mode
2425 # we need to toss the current buffer and do a full rescan to update
2426 # our file lists. If we weren't in amend mode our file lists are
2427 # accurate and we can avoid the rescan.
2430 set selected_commit_type new
2431 if {[string match amend
* $commit_type]} {
2432 $ui_comm delete
0.0 end
2434 $ui_comm edit modified false
2435 rescan
{set ui_status_value
"Checked out branch '$current_branch'."}
2437 repository_state commit_type HEAD MERGE_HEAD
2439 set ui_status_value
"Checked out branch '$current_branch'."
2443 ######################################################################
2445 ## remote management
2447 proc load_all_remotes
{} {
2449 global all_remotes tracking_branches
2451 set all_remotes
[list
]
2452 array
unset tracking_branches
2454 set rm_dir
[gitdir remotes
]
2455 if {[file isdirectory
$rm_dir]} {
2456 set all_remotes
[glob \
2460 -directory $rm_dir *]
2462 foreach name
$all_remotes {
2464 set fd
[open
[file join $rm_dir $name] r
]
2465 while {[gets
$fd line
] >= 0} {
2466 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2467 $line line src dst
]} continue
2468 if {![regexp ^refs
/ $dst]} {
2469 set dst
"refs/heads/$dst"
2471 set tracking_branches
($dst) [list
$name $src]
2478 foreach line
[array names repo_config remote.
*.url
] {
2479 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2480 lappend all_remotes
$name
2482 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2486 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2487 if {![regexp ^refs
/ $dst]} {
2488 set dst
"refs/heads/$dst"
2490 set tracking_branches
($dst) [list
$name $src]
2494 set all_remotes
[lsort
-unique $all_remotes]
2497 proc populate_fetch_menu
{} {
2498 global all_remotes repo_config
2501 foreach r
$all_remotes {
2503 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2504 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2509 set fd
[open
[gitdir remotes
$r] r
]
2510 while {[gets
$fd n
] >= 0} {
2511 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2522 -label "Fetch from $r..." \
2523 -command [list fetch_from
$r] \
2529 proc populate_push_menu
{} {
2530 global all_remotes repo_config
2534 foreach r
$all_remotes {
2536 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2537 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2542 set fd
[open
[gitdir remotes
$r] r
]
2543 while {[gets
$fd n
] >= 0} {
2544 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2558 -label "Push to $r..." \
2559 -command [list push_to
$r] \
2566 proc start_push_anywhere_action
{w
} {
2567 global push_urltype push_remote push_url push_thin push_tags
2570 switch
-- $push_urltype {
2571 remote
{set r_url
$push_remote}
2572 url
{set r_url
$push_url}
2574 if {$r_url eq
{}} return
2576 set cmd
[list git push
]
2586 foreach i
[$w.
source.l curselection
] {
2587 set b
[$w.
source.l get
$i]
2588 lappend cmd
"refs/heads/$b:refs/heads/$b"
2593 } elseif
{$cnt == 1} {
2599 set cons
[new_console
"push $r_url" "Pushing $cnt $unit to $r_url"]
2600 console_exec
$cons $cmd console_done
2604 trace add variable push_remote
write \
2605 [list radio_selector push_urltype remote
]
2607 proc do_push_anywhere
{} {
2608 global all_heads all_remotes current_branch
2609 global push_urltype push_remote push_url push_thin push_tags
2613 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2615 label
$w.header
-text {Push Branches
} -font font_uibold
2616 pack
$w.header
-side top
-fill x
2619 button
$w.buttons.create
-text Push \
2621 -command [list start_push_anywhere_action
$w]
2622 pack
$w.buttons.create
-side right
2623 button
$w.buttons.cancel
-text {Cancel
} \
2625 -command [list destroy
$w]
2626 pack
$w.buttons.cancel
-side right
-padx 5
2627 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2629 labelframe
$w.
source \
2630 -text {Source Branches
} \
2632 listbox
$w.
source.l \
2635 -selectmode extended \
2636 -yscrollcommand [list
$w.
source.sby
set] \
2638 foreach h
$all_heads {
2639 $w.
source.l insert end
$h
2640 if {$h eq
$current_branch} {
2641 $w.
source.l
select set end
2644 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2645 pack
$w.
source.sby
-side right
-fill y
2646 pack
$w.
source.l
-side left
-fill both
-expand 1
2647 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2649 labelframe
$w.dest \
2650 -text {Destination Repository
} \
2652 if {$all_remotes ne
{}} {
2653 radiobutton
$w.dest.remote_r \
2656 -variable push_urltype \
2658 eval tk_optionMenu
$w.dest.remote_m push_remote
$all_remotes
2659 grid
$w.dest.remote_r
$w.dest.remote_m
-sticky w
2660 if {[lsearch
-sorted -exact $all_remotes origin
] != -1} {
2661 set push_remote origin
2663 set push_remote
[lindex
$all_remotes 0]
2665 set push_urltype remote
2667 set push_urltype url
2669 radiobutton
$w.dest.url_r \
2670 -text {Arbitrary URL
:} \
2672 -variable push_urltype \
2674 entry
$w.dest.url_t \
2678 -textvariable push_url \
2682 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2683 if {%d
== 1 && [string length
%S
] > 0} {
2684 set push_urltype url
2688 grid
$w.dest.url_r
$w.dest.url_t
-sticky we
-padx {0 5}
2689 grid columnconfigure
$w.dest
1 -weight 1
2690 pack
$w.dest
-anchor nw
-fill x
-pady 5 -padx 5
2692 labelframe
$w.options \
2693 -text {Transfer Options
} \
2695 checkbutton
$w.options.thin \
2696 -text {Use thin pack
(for slow network connections
)} \
2697 -variable push_thin \
2699 grid
$w.options.thin
-columnspan 2 -sticky w
2700 checkbutton
$w.options.tags \
2701 -text {Include tags
} \
2702 -variable push_tags \
2704 grid
$w.options.tags
-columnspan 2 -sticky w
2705 grid columnconfigure
$w.options
1 -weight 1
2706 pack
$w.options
-anchor nw
-fill x
-pady 5 -padx 5
2712 bind $w <Visibility
> "grab $w"
2713 bind $w <Key-Escape
> "destroy $w"
2714 wm title
$w "[appname] ([reponame]): Push"
2718 ######################################################################
2723 global HEAD commit_type file_states
2725 if {[string match amend
* $commit_type]} {
2726 info_popup
{Cannot merge
while amending.
2728 You must finish amending this commit before
2729 starting any
type of merge.
2734 if {[committer_ident
] eq
{}} {return 0}
2735 if {![lock_index merge
]} {return 0}
2737 # -- Our in memory state should match the repository.
2739 repository_state curType curHEAD curMERGE_HEAD
2740 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2741 info_popup
{Last scanned state does not match repository state.
2743 Another Git program has modified this repository
2744 since the last scan. A rescan must be performed
2745 before a merge can be performed.
2747 The rescan will be automatically started now.
2750 rescan
{set ui_status_value
{Ready.
}}
2754 foreach path
[array names file_states
] {
2755 switch
-glob -- [lindex
$file_states($path) 0] {
2757 continue; # and pray it works!
2760 error_popup
"You are in the middle of a conflicted merge.
2762 File [short_path $path] has merge conflicts.
2764 You must resolve them, add the file, and commit to
2765 complete the current merge. Only then can you
2766 begin another merge.
2772 error_popup
"You are in the middle of a change.
2774 File [short_path $path] is modified.
2776 You should complete the current commit before
2777 starting a merge. Doing so will help you abort
2778 a failed merge, should the need arise.
2789 proc visualize_local_merge
{w
} {
2791 foreach i
[$w.
source.l curselection
] {
2792 lappend revs
[$w.
source.l get
$i]
2794 if {$revs eq
{}} return
2795 lappend revs
--not HEAD
2799 proc start_local_merge_action
{w
} {
2800 global HEAD ui_status_value current_branch
2802 set cmd
[list git merge
]
2805 foreach i
[$w.
source.l curselection
] {
2806 set b
[$w.
source.l get
$i]
2814 } elseif
{$revcnt == 1} {
2816 } elseif
{$revcnt <= 15} {
2822 -title [wm title
$w] \
2824 -message "Too many branches selected.
2826 You have requested to merge $revcnt branches
2827 in an octopus merge. This exceeds Git's
2828 internal limit of 15 branches per merge.
2830 Please select fewer branches. To merge more
2831 than 15 branches, merge the branches in batches.
2836 set msg
"Merging $current_branch, [join $names {, }]"
2837 set ui_status_value
"$msg..."
2838 set cons
[new_console
"Merge" $msg]
2839 console_exec
$cons $cmd [list finish_merge
$revcnt]
2840 bind $w <Destroy
> {}
2844 proc finish_merge
{revcnt w ok
} {
2847 set msg
{Merge completed successfully.
}
2850 info_popup
"Octopus merge failed.
2852 Your merge of $revcnt branches has failed.
2854 There are file-level conflicts between the
2855 branches which must be resolved manually.
2857 The working directory will now be reset.
2859 You can attempt this merge again
2860 by merging only one branch at a time." $w
2862 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2863 fconfigure
$fd -blocking 0 -translation binary
2864 fileevent
$fd readable
[list reset_hard_wait
$fd]
2865 set ui_status_value
{Aborting... please
wait...
}
2869 set msg
{Merge failed. Conflict resolution is required.
}
2872 rescan
[list
set ui_status_value
$msg]
2875 proc do_local_merge
{} {
2876 global current_branch
2878 if {![can_merge
]} return
2882 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2885 -text "Merge Into $current_branch" \
2887 pack
$w.header
-side top
-fill x
2890 button
$w.buttons.visualize
-text Visualize \
2892 -command [list visualize_local_merge
$w]
2893 pack
$w.buttons.visualize
-side left
2894 button
$w.buttons.create
-text Merge \
2896 -command [list start_local_merge_action
$w]
2897 pack
$w.buttons.create
-side right
2898 button
$w.buttons.cancel
-text {Cancel
} \
2900 -command [list destroy
$w]
2901 pack
$w.buttons.cancel
-side right
-padx 5
2902 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2904 labelframe
$w.
source \
2905 -text {Source Branches
} \
2907 listbox
$w.
source.l \
2910 -selectmode extended \
2911 -yscrollcommand [list
$w.
source.sby
set] \
2913 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2914 pack
$w.
source.sby
-side right
-fill y
2915 pack
$w.
source.l
-side left
-fill both
-expand 1
2916 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2918 set cmd
[list git for-each-ref
]
2919 lappend cmd
{--format=%(objectname
) %(*objectname
) %(refname
)}
2920 lappend cmd refs
/heads
2921 lappend cmd refs
/remotes
2922 lappend cmd refs
/tags
2923 set fr_fd
[open
"| $cmd" r
]
2924 fconfigure
$fr_fd -translation binary
2925 while {[gets
$fr_fd line
] > 0} {
2926 set line
[split $line { }]
2927 set sha1
([lindex
$line 0]) [lindex
$line 2]
2928 set sha1
([lindex
$line 1]) [lindex
$line 2]
2933 set fr_fd
[open
"| git rev-list --all --not HEAD"]
2934 while {[gets
$fr_fd line
] > 0} {
2935 if {[catch
{set ref
$sha1($line)}]} continue
2936 regsub ^refs
/(heads|remotes|tags
)/ $ref {} ref
2937 lappend to_show
$ref
2941 foreach ref
[lsort
-unique $to_show] {
2942 $w.
source.l insert end
$ref
2945 bind $w <Visibility
> "grab $w"
2946 bind $w <Key-Escape
> "unlock_index;destroy $w"
2947 bind $w <Destroy
> unlock_index
2948 wm title
$w "[appname] ([reponame]): Merge"
2952 proc do_reset_hard
{} {
2953 global HEAD commit_type file_states
2955 if {[string match amend
* $commit_type]} {
2956 info_popup
{Cannot abort
while amending.
2958 You must finish amending this commit.
2963 if {![lock_index abort
]} return
2965 if {[string match
*merge
* $commit_type]} {
2971 if {[ask_popup
"Abort $op?
2973 Aborting the current $op will cause
2974 *ALL* uncommitted changes to be lost.
2976 Continue with aborting the current $op?"] eq
{yes}} {
2977 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2978 fconfigure
$fd -blocking 0 -translation binary
2979 fileevent
$fd readable
[list reset_hard_wait
$fd]
2980 set ui_status_value
{Aborting... please
wait...
}
2986 proc reset_hard_wait
{fd
} {
2994 $ui_comm delete
0.0 end
2995 $ui_comm edit modified false
2997 catch
{file delete
[gitdir MERGE_HEAD
]}
2998 catch
{file delete
[gitdir rr-cache MERGE_RR
]}
2999 catch
{file delete
[gitdir SQUASH_MSG
]}
3000 catch
{file delete
[gitdir MERGE_MSG
]}
3001 catch
{file delete
[gitdir GITGUI_MSG
]}
3003 rescan
{set ui_status_value
{Abort completed. Ready.
}}
3007 ######################################################################
3011 set next_browser_id
0
3013 proc new_browser
{commit
} {
3014 global next_browser_id cursor_ptr M1B
3015 global browser_commit browser_status browser_stack browser_path browser_busy
3017 set w .browser
[incr next_browser_id
]
3018 set w_list
$w.list.l
3019 set browser_commit
($w_list) $commit
3020 set browser_status
($w_list) {Starting...
}
3021 set browser_stack
($w_list) {}
3022 set browser_path
($w_list) $browser_commit($w_list):
3023 set browser_busy
($w_list) 1
3026 label
$w.path
-textvariable browser_path
($w_list) \
3032 pack
$w.path
-anchor w
-side top
-fill x
3035 text
$w_list -background white
-borderwidth 0 \
3036 -cursor $cursor_ptr \
3041 -xscrollcommand [list
$w.list.sbx
set] \
3042 -yscrollcommand [list
$w.list.sby
set] \
3044 $w_list tag conf in_sel \
3045 -background [$w_list cget
-foreground] \
3046 -foreground [$w_list cget
-background]
3047 scrollbar
$w.list.sbx
-orient h
-command [list
$w_list xview
]
3048 scrollbar
$w.list.sby
-orient v
-command [list
$w_list yview
]
3049 pack
$w.list.sbx
-side bottom
-fill x
3050 pack
$w.list.sby
-side right
-fill y
3051 pack
$w_list -side left
-fill both
-expand 1
3052 pack
$w.list
-side top
-fill both
-expand 1
3054 label
$w.status
-textvariable browser_status
($w_list) \
3060 pack
$w.status
-anchor w
-side bottom
-fill x
3062 bind $w_list <Button-1
> "browser_click 0 $w_list @%x,%y;break"
3063 bind $w_list <Double-Button-1
> "browser_click 1 $w_list @%x,%y;break"
3064 bind $w_list <$M1B-Up> "browser_parent $w_list;break"
3065 bind $w_list <$M1B-Left> "browser_parent $w_list;break"
3066 bind $w_list <Up
> "browser_move -1 $w_list;break"
3067 bind $w_list <Down
> "browser_move 1 $w_list;break"
3068 bind $w_list <$M1B-Right> "browser_enter $w_list;break"
3069 bind $w_list <Return
> "browser_enter $w_list;break"
3070 bind $w_list <Prior
> "browser_page -1 $w_list;break"
3071 bind $w_list <Next
> "browser_page 1 $w_list;break"
3072 bind $w_list <Left
> break
3073 bind $w_list <Right
> break
3075 bind $w <Visibility
> "focus $w"
3077 array unset browser_buffer $w_list
3078 array unset browser_files $w_list
3079 array unset browser_status $w_list
3080 array unset browser_stack $w_list
3081 array unset browser_path $w_list
3082 array unset browser_commit $w_list
3083 array unset browser_busy $w_list
3085 wm title
$w "[appname] ([reponame]): File Browser"
3086 ls_tree
$w_list $browser_commit($w_list) {}
3089 proc browser_move
{dir w
} {
3090 global browser_files browser_busy
3092 if {$browser_busy($w)} return
3093 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3095 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3096 $w tag remove in_sel
0.0 end
3097 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3102 proc browser_page
{dir w
} {
3103 global browser_files browser_busy
3105 if {$browser_busy($w)} return
3106 $w yview scroll
$dir pages
3108 [lindex
[$w yview
] 0]
3109 * [llength
$browser_files($w)]
3111 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3112 $w tag remove in_sel
0.0 end
3113 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3118 proc browser_parent
{w
} {
3119 global browser_files browser_status browser_path
3120 global browser_stack browser_busy
3122 if {$browser_busy($w)} return
3123 set info
[lindex
$browser_files($w) 0]
3124 if {[lindex
$info 0] eq
{parent
}} {
3125 set parent
[lindex
$browser_stack($w) end-1
]
3126 set browser_stack
($w) [lrange
$browser_stack($w) 0 end-2
]
3127 if {$browser_stack($w) eq
{}} {
3128 regsub
{:.
*$
} $browser_path($w) {:} browser_path
($w)
3130 regsub
{/[^
/]+$
} $browser_path($w) {} browser_path
($w)
3132 set browser_status
($w) "Loading $browser_path($w)..."
3133 ls_tree
$w [lindex
$parent 0] [lindex
$parent 1]
3137 proc browser_enter
{w
} {
3138 global browser_files browser_status browser_path
3139 global browser_commit browser_stack browser_busy
3141 if {$browser_busy($w)} return
3142 set lno
[lindex
[split [$w index in_sel.first
] .
] 0]
3143 set info
[lindex
$browser_files($w) [expr {$lno - 1}]]
3145 switch
-- [lindex
$info 0] {
3150 set name
[lindex
$info 2]
3151 set escn
[escape_path
$name]
3152 set browser_status
($w) "Loading $escn..."
3153 append browser_path
($w) $escn
3154 ls_tree
$w [lindex
$info 1] $name
3157 set name
[lindex
$info 2]
3159 foreach n
$browser_stack($w) {
3160 append p
[lindex
$n 1]
3163 show_blame
$browser_commit($w) $p
3169 proc browser_click
{was_double_click w pos
} {
3170 global browser_files browser_busy
3172 if {$browser_busy($w)} return
3173 set lno
[lindex
[split [$w index
$pos] .
] 0]
3176 if {[lindex
$browser_files($w) [expr {$lno - 1}]] ne
{}} {
3177 $w tag remove in_sel
0.0 end
3178 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
3179 if {$was_double_click} {
3185 proc ls_tree
{w tree_id name
} {
3186 global browser_buffer browser_files browser_stack browser_busy
3188 set browser_buffer
($w) {}
3189 set browser_files
($w) {}
3190 set browser_busy
($w) 1
3192 $w conf
-state normal
3193 $w tag remove in_sel
0.0 end
3195 if {$browser_stack($w) ne
{}} {
3196 $w image create end \
3197 -align center
-padx 5 -pady 1 \
3200 $w insert end
{[Up To Parent
]}
3201 lappend browser_files
($w) parent
3203 lappend browser_stack
($w) [list
$tree_id $name]
3204 $w conf
-state disabled
3206 set cmd
[list git ls-tree
-z $tree_id]
3207 set fd
[open
"| $cmd" r
]
3208 fconfigure
$fd -blocking 0 -translation binary
-encoding binary
3209 fileevent
$fd readable
[list read_ls_tree
$fd $w]
3212 proc read_ls_tree
{fd w
} {
3213 global browser_buffer browser_files browser_status browser_busy
3215 if {![winfo exists
$w]} {
3220 append browser_buffer
($w) [read $fd]
3221 set pck
[split $browser_buffer($w) "\0"]
3222 set browser_buffer
($w) [lindex
$pck end
]
3224 set n
[llength
$browser_files($w)]
3225 $w conf
-state normal
3226 foreach p
[lrange
$pck 0 end-1
] {
3227 set info
[split $p "\t"]
3228 set path
[lindex
$info 1]
3229 set info
[split [lindex
$info 0] { }]
3230 set type [lindex
$info 1]
3231 set object
[lindex
$info 2]
3242 set image file_question
3246 if {$n > 0} {$w insert end
"\n"}
3247 $w image create end \
3248 -align center
-padx 5 -pady 1 \
3249 -name icon
[incr n
] \
3251 $w insert end
[escape_path
$path]
3252 lappend browser_files
($w) [list
$type $object $path]
3254 $w conf
-state disabled
3258 set browser_status
($w) Ready.
3259 set browser_busy
($w) 0
3260 array
unset browser_buffer
$w
3262 $w tag add in_sel
1.0 2.0
3268 proc show_blame
{commit path
} {
3269 global next_browser_id blame_status blame_data
3271 if {[winfo ismapped .
]} {
3272 set w .browser
[incr next_browser_id
]
3279 set blame_status
($w) {Loading current
file content...
}
3281 label
$w.path
-text "$commit:$path" \
3287 pack
$w.path
-side top
-fill x
3290 text
$w.out.loaded_t \
3291 -background white
-borderwidth 0 \
3297 $w.out.loaded_t tag conf annotated
-background grey
3299 text
$w.out.linenumber_t \
3300 -background white
-borderwidth 0 \
3306 $w.out.linenumber_t tag conf linenumber
-justify right
3308 text
$w.out.file_t \
3309 -background white
-borderwidth 0 \
3314 -xscrollcommand [list
$w.out.sbx
set] \
3317 scrollbar
$w.out.sbx
-orient h
-command [list
$w.out.file_t xview
]
3318 scrollbar
$w.out.sby
-orient v \
3319 -command [list scrollbar2many
[list \
3321 $w.out.linenumber_t \
3325 $w.out.linenumber_t \
3330 grid conf
$w.out.sbx
-column 2 -sticky we
3331 grid columnconfigure
$w.out
2 -weight 1
3332 grid rowconfigure
$w.out
0 -weight 1
3333 pack
$w.out
-fill both
-expand 1
3335 label
$w.status
-textvariable blame_status
($w) \
3341 pack
$w.status
-side bottom
-fill x
3345 -background white
-borderwidth 0 \
3350 -xscrollcommand [list
$w.cm.sbx
set] \
3351 -yscrollcommand [list
$w.cm.sby
set] \
3353 scrollbar
$w.cm.sbx
-orient h
-command [list
$w.cm.t xview
]
3354 scrollbar
$w.cm.sby
-orient v
-command [list
$w.cm.t yview
]
3355 pack
$w.cm.sby
-side right
-fill y
3356 pack
$w.cm.sbx
-side bottom
-fill x
3357 pack
$w.cm.t
-expand 1 -fill both
3358 pack
$w.cm
-side bottom
-fill x
3360 menu
$w.ctxm
-tearoff 0
3361 $w.ctxm add
command -label "Copy Commit" \
3363 -command "blame_copycommit $w \$cursorW @\$cursorX,\$cursorY"
3367 $w.out.linenumber_t \
3369 $i tag conf in_sel \
3370 -background [$i cget
-foreground] \
3371 -foreground [$i cget
-background]
3372 $i conf
-yscrollcommand \
3373 [list many2scrollbar
[list \
3375 $w.out.linenumber_t \
3378 bind $i <Button-1
> "
3381 $w.out.linenumber_t \\
3390 tk_popup $w.ctxm %X %Y
3394 bind $w.cm.t
<Button-1
> "focus $w.cm.t"
3395 bind $tl <Visibility
> "focus $tl"
3396 bind $tl <Destroy
> "
3397 array unset blame_status {$w}
3398 array unset blame_data $w,*
3400 wm title
$tl "[appname] ([reponame]): File Viewer"
3402 set blame_data
($w,commit_count
) 0
3403 set blame_data
($w,commit_list
) {}
3404 set blame_data
($w,total_lines
) 0
3405 set blame_data
($w,blame_lines
) 0
3406 set blame_data
($w,highlight_commit
) {}
3407 set blame_data
($w,highlight_line
) -1
3409 set cmd
[list git cat-file blob
"$commit:$path"]
3410 set fd
[open
"| $cmd" r
]
3411 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3412 fileevent
$fd readable
[list read_blame_catfile \
3413 $fd $w $commit $path \
3414 $w.cm.t
$w.out.loaded_t
$w.out.linenumber_t
$w.out.file_t
]
3417 proc read_blame_catfile
{fd w commit path w_cmit w_load w_line w_file
} {
3418 global blame_status blame_data
3420 if {![winfo exists
$w_file]} {
3425 set n
$blame_data($w,total_lines
)
3426 $w_load conf
-state normal
3427 $w_line conf
-state normal
3428 $w_file conf
-state normal
3429 while {[gets
$fd line
] >= 0} {
3430 regsub
"\r\$" $line {} line
3432 $w_load insert end
"\n"
3433 $w_line insert end
"$n\n" linenumber
3434 $w_file insert end
"$line\n"
3436 $w_load conf
-state disabled
3437 $w_line conf
-state disabled
3438 $w_file conf
-state disabled
3439 set blame_data
($w,total_lines
) $n
3443 blame_incremental_status
$w
3444 set cmd
[list git blame
-M -C --incremental]
3445 lappend cmd
$commit -- $path
3446 set fd
[open
"| $cmd" r
]
3447 fconfigure
$fd -blocking 0 -translation lf
-encoding binary
3448 fileevent
$fd readable
[list read_blame_incremental
$fd $w \
3449 $w_load $w_cmit $w_line $w_file]
3453 proc read_blame_incremental
{fd w w_load w_cmit w_line w_file
} {
3454 global blame_status blame_data
3456 if {![winfo exists
$w_file]} {
3461 while {[gets
$fd line
] >= 0} {
3462 if {[regexp
{^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$
} $line line \
3463 cmit original_line final_line line_count
]} {
3464 set blame_data
($w,commit
) $cmit
3465 set blame_data
($w,original_line
) $original_line
3466 set blame_data
($w,final_line
) $final_line
3467 set blame_data
($w,line_count
) $line_count
3469 if {[catch
{set g
$blame_data($w,$cmit,order
)}]} {
3470 $w_line tag conf g
$cmit
3471 $w_file tag conf g
$cmit
3472 $w_line tag raise in_sel
3473 $w_file tag raise in_sel
3474 $w_file tag raise sel
3475 set blame_data
($w,$cmit,order
) $blame_data($w,commit_count
)
3476 incr blame_data
($w,commit_count
)
3477 lappend blame_data
($w,commit_list
) $cmit
3479 } elseif
{[string match
{filename
*} $line]} {
3480 set file [string range
$line 9 end
]
3481 set n
$blame_data($w,line_count
)
3482 set lno
$blame_data($w,final_line
)
3483 set cmit
$blame_data($w,commit
)
3486 if {[catch
{set g g
$blame_data($w,line
$lno,commit
)}]} {
3487 $w_load tag add annotated
$lno.0 "$lno.0 lineend + 1c"
3489 $w_line tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3490 $w_file tag remove g
$g $lno.0 "$lno.0 lineend + 1c"
3493 set blame_data
($w,line
$lno,commit
) $cmit
3494 set blame_data
($w,line
$lno,file) $file
3495 $w_line tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3496 $w_file tag add g
$cmit $lno.0 "$lno.0 lineend + 1c"
3498 if {$blame_data($w,highlight_line
) == -1} {
3499 if {[lindex
[$w_file yview
] 0] == 0} {
3501 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3503 } elseif
{$blame_data($w,highlight_line
) == $lno} {
3504 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3509 incr blame_data
($w,blame_lines
)
3512 set hc
$blame_data($w,highlight_commit
)
3514 && [expr {$blame_data($w,$hc,order
) + 1}]
3515 == $blame_data($w,$cmit,order
)} {
3516 blame_showcommit
$w $w_cmit $w_line $w_file \
3517 $blame_data($w,highlight_line
)
3519 } elseif
{[regexp
{^
([a-z-
]+) (.
*)$
} $line line header data
]} {
3520 set blame_data
($w,$blame_data($w,commit
),$header) $data
3526 set blame_status
($w) {Annotation complete.
}
3528 blame_incremental_status
$w
3532 proc blame_incremental_status
{w
} {
3533 global blame_status blame_data
3535 set blame_status
($w) [format \
3536 "Loading annotations... %i of %i lines annotated (%2i%%)" \
3537 $blame_data($w,blame_lines
) \
3538 $blame_data($w,total_lines
) \
3539 [expr {100 * $blame_data($w,blame_lines
)
3540 / $blame_data($w,total_lines
)}]]
3543 proc blame_click
{w w_cmit w_line w_file cur_w pos
} {
3544 set lno
[lindex
[split [$cur_w index
$pos] .
] 0]
3545 if {$lno eq
{}} return
3547 $w_line tag remove in_sel
0.0 end
3548 $w_file tag remove in_sel
0.0 end
3549 $w_line tag add in_sel
$lno.0 "$lno.0 + 1 line"
3550 $w_file tag add in_sel
$lno.0 "$lno.0 + 1 line"
3552 blame_showcommit
$w $w_cmit $w_line $w_file $lno
3561 proc blame_showcommit
{w w_cmit w_line w_file lno
} {
3562 global blame_colors blame_data repo_config
3564 set cmit
$blame_data($w,highlight_commit
)
3566 set idx
$blame_data($w,$cmit,order
)
3568 foreach c
$blame_colors {
3569 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3570 $w_line tag conf g
$h -background white
3571 $w_file tag conf g
$h -background white
3576 $w_cmit conf
-state normal
3577 $w_cmit delete
0.0 end
3578 if {[catch
{set cmit
$blame_data($w,line
$lno,commit
)}]} {
3580 $w_cmit insert end
"Loading annotation..."
3582 set idx
$blame_data($w,$cmit,order
)
3584 foreach c
$blame_colors {
3585 set h
[lindex
$blame_data($w,commit_list
) [expr {$idx - 1 + $i}]]
3586 $w_line tag conf g
$h -background $c
3587 $w_file tag conf g
$h -background $c
3591 if {[catch
{set msg
$blame_data($w,$cmit,message
)}]} {
3594 set fd
[open
"| git cat-file commit $cmit" r
]
3595 fconfigure
$fd -encoding binary
-translation lf
3596 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
3599 while {[gets
$fd line
] > 0} {
3600 if {[string match
{encoding
*} $line]} {
3601 set enc
[string tolower
[string range
$line 9 end
]]
3604 fconfigure
$fd -encoding $enc
3605 set msg
[string trim
[read $fd]]
3608 set blame_data
($w,$cmit,message
) $msg
3614 catch
{set author_name
$blame_data($w,$cmit,author
)}
3615 catch
{set author_email
$blame_data($w,$cmit,author-mail
)}
3616 catch
{set author_time
[clock format
$blame_data($w,$cmit,author-time
)]}
3618 set committer_name
{}
3619 set committer_email
{}
3620 set committer_time
{}
3621 catch
{set committer_name
$blame_data($w,$cmit,committer
)}
3622 catch
{set committer_email
$blame_data($w,$cmit,committer-mail
)}
3623 catch
{set committer_time
[clock format
$blame_data($w,$cmit,committer-time
)]}
3625 $w_cmit insert end
"commit $cmit\n"
3626 $w_cmit insert end
"Author: $author_name $author_email $author_time\n"
3627 $w_cmit insert end
"Committer: $committer_name $committer_email $committer_time\n"
3628 $w_cmit insert end
"Original File: [escape_path $blame_data($w,line$lno,file)]\n"
3629 $w_cmit insert end
"\n"
3630 $w_cmit insert end
$msg
3632 $w_cmit conf
-state disabled
3634 set blame_data
($w,highlight_line
) $lno
3635 set blame_data
($w,highlight_commit
) $cmit
3638 proc blame_copycommit
{w i pos
} {
3640 set lno
[lindex
[split [$i index
$pos] .
] 0]
3641 if {![catch
{set commit
$blame_data($w,line
$lno,commit
)}]} {
3650 ######################################################################
3655 #define mask_width 14
3656 #define mask_height 15
3657 static unsigned char mask_bits
[] = {
3658 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3659 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
3660 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
3663 image create bitmap file_plain
-background white
-foreground black
-data {
3664 #define plain_width 14
3665 #define plain_height 15
3666 static unsigned char plain_bits
[] = {
3667 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3668 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
3669 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3670 } -maskdata $filemask
3672 image create bitmap file_mod
-background white
-foreground blue
-data {
3673 #define mod_width 14
3674 #define mod_height 15
3675 static unsigned char mod_bits
[] = {
3676 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3677 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3678 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3679 } -maskdata $filemask
3681 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
3682 #define file_fulltick_width 14
3683 #define file_fulltick_height 15
3684 static unsigned char file_fulltick_bits
[] = {
3685 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
3686 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
3687 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3688 } -maskdata $filemask
3690 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
3691 #define parttick_width 14
3692 #define parttick_height 15
3693 static unsigned char parttick_bits
[] = {
3694 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
3695 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
3696 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3697 } -maskdata $filemask
3699 image create bitmap file_question
-background white
-foreground black
-data {
3700 #define file_question_width 14
3701 #define file_question_height 15
3702 static unsigned char file_question_bits
[] = {
3703 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
3704 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
3705 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
3706 } -maskdata $filemask
3708 image create bitmap file_removed
-background white
-foreground red
-data {
3709 #define file_removed_width 14
3710 #define file_removed_height 15
3711 static unsigned char file_removed_bits
[] = {
3712 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
3713 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
3714 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
3715 } -maskdata $filemask
3717 image create bitmap file_merge
-background white
-foreground blue
-data {
3718 #define file_merge_width 14
3719 #define file_merge_height 15
3720 static unsigned char file_merge_bits
[] = {
3721 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
3722 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
3723 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
3724 } -maskdata $filemask
3727 #define file_width 18
3728 #define file_height 18
3729 static unsigned char file_bits
[] = {
3730 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00,
3731 0x0c, 0x03, 0x00, 0x04, 0xfe, 0x00, 0x06, 0x80, 0x00, 0xff, 0x9f, 0x00,
3732 0x03, 0x98, 0x00, 0x02, 0x90, 0x00, 0x06, 0xb0, 0x00, 0x04, 0xa0, 0x00,
3733 0x0c, 0xe0, 0x00, 0x08, 0xc0, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
3734 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3736 image create bitmap file_dir
-background white
-foreground blue \
3737 -data $file_dir_data -maskdata $file_dir_data
3740 set file_uplevel_data
{
3742 #define up_height 15
3743 static unsigned char up_bits
[] = {
3744 0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f,
3745 0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
3746 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
3748 image create bitmap file_uplevel
-background white
-foreground red \
3749 -data $file_uplevel_data -maskdata $file_uplevel_data
3750 unset file_uplevel_data
3752 set ui_index .vpane.files.index.list
3753 set ui_workdir .vpane.files.workdir.list
3755 set all_icons
(_
$ui_index) file_plain
3756 set all_icons
(A
$ui_index) file_fulltick
3757 set all_icons
(M
$ui_index) file_fulltick
3758 set all_icons
(D
$ui_index) file_removed
3759 set all_icons
(U
$ui_index) file_merge
3761 set all_icons
(_
$ui_workdir) file_plain
3762 set all_icons
(M
$ui_workdir) file_mod
3763 set all_icons
(D
$ui_workdir) file_question
3764 set all_icons
(U
$ui_workdir) file_merge
3765 set all_icons
(O
$ui_workdir) file_plain
3767 set max_status_desc
0
3771 {_M
"Modified, not staged"}
3772 {M_
"Staged for commit"}
3773 {MM
"Portions staged for commit"}
3774 {MD
"Staged for commit, missing"}
3776 {_O
"Untracked, not staged"}
3777 {A_
"Staged for commit"}
3778 {AM
"Portions staged for commit"}
3779 {AD
"Staged for commit, missing"}
3782 {D_
"Staged for removal"}
3783 {DO
"Staged for removal, still present"}
3785 {U_
"Requires merge resolution"}
3786 {UU
"Requires merge resolution"}
3787 {UM
"Requires merge resolution"}
3788 {UD
"Requires merge resolution"}
3790 if {$max_status_desc < [string length
[lindex
$i 1]]} {
3791 set max_status_desc
[string length
[lindex
$i 1]]
3793 set all_descs
([lindex
$i 0]) [lindex
$i 1]
3797 ######################################################################
3801 proc bind_button3
{w cmd
} {
3802 bind $w <Any-Button-3
> $cmd
3804 bind $w <Control-Button-1
> $cmd
3808 proc scrollbar2many
{list mode args
} {
3809 foreach w
$list {eval $w $mode $args}
3812 proc many2scrollbar
{list mode sb top bottom
} {
3813 $sb set $top $bottom
3814 foreach w
$list {$w $mode moveto
$top}
3817 proc incr_font_size
{font
{amt
1}} {
3818 set sz
[font configure
$font -size]
3820 font configure
$font -size $sz
3821 font configure
${font}bold
-size $sz
3824 proc hook_failed_popup
{hook msg
} {
3829 label
$w.m.l1
-text "$hook hook failed:" \
3834 -background white
-borderwidth 1 \
3836 -width 80 -height 10 \
3838 -yscrollcommand [list
$w.m.sby
set]
3840 -text {You must correct the above errors before committing.
} \
3844 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3845 pack
$w.m.l1
-side top
-fill x
3846 pack
$w.m.l2
-side bottom
-fill x
3847 pack
$w.m.sby
-side right
-fill y
3848 pack
$w.m.t
-side left
-fill both
-expand 1
3849 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3851 $w.m.t insert
1.0 $msg
3852 $w.m.t conf
-state disabled
3854 button
$w.ok
-text OK \
3857 -command "destroy $w"
3858 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3860 bind $w <Visibility
> "grab $w; focus $w"
3861 bind $w <Key-Return
> "destroy $w"
3862 wm title
$w "[appname] ([reponame]): error"
3866 set next_console_id
0
3868 proc new_console
{short_title long_title
} {
3869 global next_console_id console_data
3870 set w .console
[incr next_console_id
]
3871 set console_data
($w) [list
$short_title $long_title]
3872 return [console_init
$w]
3875 proc console_init
{w
} {
3876 global console_cr console_data M1B
3878 set console_cr
($w) 1.0
3881 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
3886 -background white
-borderwidth 1 \
3888 -width 80 -height 10 \
3891 -yscrollcommand [list
$w.m.sby
set]
3892 label
$w.m.s
-text {Working... please
wait...
} \
3896 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3897 pack
$w.m.l1
-side top
-fill x
3898 pack
$w.m.s
-side bottom
-fill x
3899 pack
$w.m.sby
-side right
-fill y
3900 pack
$w.m.t
-side left
-fill both
-expand 1
3901 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3903 menu
$w.ctxm
-tearoff 0
3904 $w.ctxm add
command -label "Copy" \
3906 -command "tk_textCopy $w.m.t"
3907 $w.ctxm add
command -label "Select All" \
3909 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
3910 $w.ctxm add
command -label "Copy All" \
3913 $w.m.t tag add sel 0.0 end
3915 $w.m.t tag remove sel 0.0 end
3918 button
$w.ok
-text {Close
} \
3921 -command "destroy $w"
3922 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3924 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
3925 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
3926 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
3927 bind $w <Visibility
> "focus $w"
3928 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
3932 proc console_exec
{w cmd after
} {
3933 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
3934 # But most users need that so we have to relogin. :-(
3937 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
3940 # -- Tcl won't let us redirect both stdout and stderr to
3941 # the same pipe. So pass it through cat...
3943 set cmd
[concat |
$cmd |
& cat]
3945 set fd_f
[open
$cmd r
]
3946 fconfigure
$fd_f -blocking 0 -translation binary
3947 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
3950 proc console_read
{w fd after
} {
3955 if {![winfo exists
$w]} {console_init
$w}
3956 $w.m.t conf
-state normal
3958 set n
[string length
$buf]
3960 set cr
[string first
"\r" $buf $c]
3961 set lf
[string first
"\n" $buf $c]
3962 if {$cr < 0} {set cr
[expr {$n + 1}]}
3963 if {$lf < 0} {set lf
[expr {$n + 1}]}
3966 $w.m.t insert end
[string range
$buf $c $lf]
3967 set console_cr
($w) [$w.m.t index
{end
-1c}]
3971 $w.m.t delete
$console_cr($w) end
3972 $w.m.t insert end
"\n"
3973 $w.m.t insert end
[string range
$buf $c $cr]
3978 $w.m.t conf
-state disabled
3982 fconfigure
$fd -blocking 1
3984 if {[catch
{close
$fd}]} {
3989 uplevel
#0 $after $w $ok
3992 fconfigure
$fd -blocking 0
3995 proc console_chain
{cmdlist w
{ok
1}} {
3997 if {[llength
$cmdlist] == 0} {
4002 set cmd
[lindex
$cmdlist 0]
4003 set cmdlist
[lrange
$cmdlist 1 end
]
4005 if {[lindex
$cmd 0] eq
{console_exec
}} {
4008 [list console_chain
$cmdlist]
4010 uplevel
#0 $cmd $cmdlist $w $ok
4017 proc console_done
{args
} {
4018 global console_cr console_data
4020 switch
-- [llength
$args] {
4022 set w
[lindex
$args 0]
4023 set ok
[lindex
$args 1]
4026 set w
[lindex
$args 1]
4027 set ok
[lindex
$args 2]
4030 error
"wrong number of args: console_done ?ignored? w ok"
4035 if {[winfo exists
$w]} {
4036 $w.m.s conf
-background green
-text {Success
}
4037 $w.ok conf
-state normal
4040 if {![winfo exists
$w]} {
4043 $w.m.s conf
-background red
-text {Error
: Command Failed
}
4044 $w.ok conf
-state normal
4047 array
unset console_cr
$w
4048 array
unset console_data
$w
4051 ######################################################################
4055 set starting_gitk_msg
{Starting gitk... please
wait...
}
4057 proc do_gitk
{revs
} {
4058 global env ui_status_value starting_gitk_msg
4060 # -- Always start gitk through whatever we were loaded with. This
4061 # lets us bypass using shell process on Windows systems.
4063 set cmd
[info nameofexecutable
]
4064 lappend cmd
[gitexec gitk
]
4070 if {[catch
{eval exec $cmd &} err
]} {
4071 error_popup
"Failed to start gitk:\n\n$err"
4073 set ui_status_value
$starting_gitk_msg
4075 if {$ui_status_value eq
$starting_gitk_msg} {
4076 set ui_status_value
{Ready.
}
4083 set fd
[open
"| git count-objects -v" r
]
4084 while {[gets
$fd line
] > 0} {
4085 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
4086 set stats
($name) $value
4092 foreach p
[glob
-directory [gitdir objects pack
] \
4095 incr packed_sz
[file size
$p]
4097 if {$packed_sz > 0} {
4098 set stats
(size-pack
) [expr {$packed_sz / 1024}]
4103 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4105 label
$w.header
-text {Database Statistics
} \
4107 pack
$w.header
-side top
-fill x
4109 frame
$w.buttons
-border 1
4110 button
$w.buttons.close
-text Close \
4112 -command [list destroy
$w]
4113 button
$w.buttons.gc
-text {Compress Database
} \
4115 -command "destroy $w;do_gc"
4116 pack
$w.buttons.close
-side right
4117 pack
$w.buttons.gc
-side left
4118 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4120 frame
$w.stat
-borderwidth 1 -relief solid
4122 {count
{Number of loose objects
}}
4123 {size
{Disk space used by loose objects
} { KiB
}}
4124 {in-pack
{Number of packed objects
}}
4125 {packs
{Number of packs
}}
4126 {size-pack
{Disk space used by packed objects
} { KiB
}}
4127 {prune-packable
{Packed objects waiting
for pruning
}}
4128 {garbage
{Garbage files
}}
4130 set name
[lindex
$s 0]
4131 set label
[lindex
$s 1]
4132 if {[catch
{set value
$stats($name)}]} continue
4133 if {[llength
$s] > 2} {
4134 set value
"$value[lindex $s 2]"
4137 label
$w.stat.l_
$name -text "$label:" -anchor w
-font font_ui
4138 label
$w.stat.v_
$name -text $value -anchor w
-font font_ui
4139 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
4141 pack
$w.stat
-pady 10 -padx 10
4143 bind $w <Visibility
> "grab $w; focus $w"
4144 bind $w <Key-Escape
> [list destroy
$w]
4145 bind $w <Key-Return
> [list destroy
$w]
4146 wm title
$w "[appname] ([reponame]): Database Statistics"
4151 set w
[new_console
{gc
} {Compressing the object database
}]
4153 {console_exec
{git pack-refs
--prune}}
4154 {console_exec
{git reflog expire
--all}}
4155 {console_exec
{git repack
-a -d -l}}
4156 {console_exec
{git rerere gc
}}
4160 proc do_fsck_objects
{} {
4161 set w
[new_console
{fsck-objects
} \
4162 {Verifying the object database with fsck-objects
}]
4163 set cmd
[list git fsck-objects
]
4166 lappend cmd
--strict
4167 console_exec
$w $cmd console_done
4173 global ui_comm is_quitting repo_config commit_type
4175 if {$is_quitting} return
4178 if {[winfo exists
$ui_comm]} {
4179 # -- Stash our current commit buffer.
4181 set save
[gitdir GITGUI_MSG
]
4182 set msg
[string trim
[$ui_comm get
0.0 end
]]
4183 regsub
-all -line {[ \r\t]+$
} $msg {} msg
4184 if {(![string match amend
* $commit_type]
4185 ||
[$ui_comm edit modified
])
4188 set fd
[open
$save w
]
4189 puts
-nonewline $fd $msg
4193 catch
{file delete
$save}
4196 # -- Stash our current window geometry into this repository.
4198 set cfg_geometry
[list
]
4199 lappend cfg_geometry
[wm geometry .
]
4200 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
4201 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
4202 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
4205 if {$cfg_geometry ne
$rc_geometry} {
4206 catch
{git config gui.geometry
$cfg_geometry}
4214 rescan
{set ui_status_value
{Ready.
}}
4217 proc unstage_helper
{txt paths
} {
4218 global file_states current_diff_path
4220 if {![lock_index begin-update
]} return
4224 foreach path
$paths {
4225 switch
-glob -- [lindex
$file_states($path) 0] {
4229 lappend pathList
$path
4230 if {$path eq
$current_diff_path} {
4231 set after
{reshow_diff
;}
4236 if {$pathList eq
{}} {
4242 [concat
$after {set ui_status_value
{Ready.
}}]
4246 proc do_unstage_selection
{} {
4247 global current_diff_path selected_paths
4249 if {[array size selected_paths
] > 0} {
4251 {Unstaging selected files from commit
} \
4252 [array names selected_paths
]
4253 } elseif
{$current_diff_path ne
{}} {
4255 "Unstaging [short_path $current_diff_path] from commit" \
4256 [list
$current_diff_path]
4260 proc add_helper
{txt paths
} {
4261 global file_states current_diff_path
4263 if {![lock_index begin-update
]} return
4267 foreach path
$paths {
4268 switch
-glob -- [lindex
$file_states($path) 0] {
4273 lappend pathList
$path
4274 if {$path eq
$current_diff_path} {
4275 set after
{reshow_diff
;}
4280 if {$pathList eq
{}} {
4286 [concat
$after {set ui_status_value
{Ready to commit.
}}]
4290 proc do_add_selection
{} {
4291 global current_diff_path selected_paths
4293 if {[array size selected_paths
] > 0} {
4295 {Adding selected files
} \
4296 [array names selected_paths
]
4297 } elseif
{$current_diff_path ne
{}} {
4299 "Adding [short_path $current_diff_path]" \
4300 [list
$current_diff_path]
4304 proc do_add_all
{} {
4308 foreach path
[array names file_states
] {
4309 switch
-glob -- [lindex
$file_states($path) 0] {
4312 ?D
{lappend paths
$path}
4315 add_helper
{Adding all changed files
} $paths
4318 proc revert_helper
{txt paths
} {
4319 global file_states current_diff_path
4321 if {![lock_index begin-update
]} return
4325 foreach path
$paths {
4326 switch
-glob -- [lindex
$file_states($path) 0] {
4330 lappend pathList
$path
4331 if {$path eq
$current_diff_path} {
4332 set after
{reshow_diff
;}
4338 set n
[llength
$pathList]
4342 } elseif
{$n == 1} {
4343 set s
"[short_path [lindex $pathList]]"
4345 set s
"these $n files"
4348 set reply
[tk_dialog \
4350 "[appname] ([reponame])" \
4351 "Revert changes in $s?
4353 Any unadded changes will be permanently lost by the revert." \
4363 [concat
$after {set ui_status_value
{Ready.
}}]
4369 proc do_revert_selection
{} {
4370 global current_diff_path selected_paths
4372 if {[array size selected_paths
] > 0} {
4374 {Reverting selected files
} \
4375 [array names selected_paths
]
4376 } elseif
{$current_diff_path ne
{}} {
4378 "Reverting [short_path $current_diff_path]" \
4379 [list
$current_diff_path]
4383 proc do_signoff
{} {
4386 set me
[committer_ident
]
4387 if {$me eq
{}} return
4389 set sob
"Signed-off-by: $me"
4390 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
4391 if {$last ne
$sob} {
4392 $ui_comm edit separator
4394 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
4395 $ui_comm insert end
"\n"
4397 $ui_comm insert end
"\n$sob"
4398 $ui_comm edit separator
4403 proc do_select_commit_type
{} {
4404 global commit_type selected_commit_type
4406 if {$selected_commit_type eq
{new
}
4407 && [string match amend
* $commit_type]} {
4409 } elseif
{$selected_commit_type eq
{amend
}
4410 && ![string match amend
* $commit_type]} {
4413 # The amend request was rejected...
4415 if {![string match amend
* $commit_type]} {
4416 set selected_commit_type new
4426 global appvers copyright
4427 global tcl_patchLevel tk_patchLevel
4431 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4433 label
$w.header
-text "About [appname]" \
4435 pack
$w.header
-side top
-fill x
4438 button
$w.buttons.close
-text {Close
} \
4440 -command [list destroy
$w]
4441 pack
$w.buttons.close
-side right
4442 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4445 -text "git-gui - a commit creation tool for Git.
4453 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
4456 append v
"git-gui version $appvers\n"
4457 append v
"[git version]\n"
4459 if {$tcl_patchLevel eq
$tk_patchLevel} {
4460 append v
"Tcl/Tk version $tcl_patchLevel"
4462 append v
"Tcl version $tcl_patchLevel"
4463 append v
", Tk version $tk_patchLevel"
4474 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
4476 menu
$w.ctxm
-tearoff 0
4477 $w.ctxm add
command \
4482 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
4485 bind $w <Visibility
> "grab $w; focus $w"
4486 bind $w <Key-Escape
> "destroy $w"
4487 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
4488 wm title
$w "About [appname]"
4492 proc do_options
{} {
4493 global repo_config global_config font_descs
4494 global repo_config_new global_config_new
4496 array
unset repo_config_new
4497 array
unset global_config_new
4498 foreach name
[array names repo_config
] {
4499 set repo_config_new
($name) $repo_config($name)
4502 foreach name
[array names repo_config
] {
4504 gui.diffcontext
{continue}
4506 set repo_config_new
($name) $repo_config($name)
4508 foreach name
[array names global_config
] {
4509 set global_config_new
($name) $global_config($name)
4512 set w .options_editor
4514 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
4516 label
$w.header
-text "Options" \
4518 pack
$w.header
-side top
-fill x
4521 button
$w.buttons.restore
-text {Restore Defaults
} \
4523 -command do_restore_defaults
4524 pack
$w.buttons.restore
-side left
4525 button
$w.buttons.save
-text Save \
4527 -command [list do_save_config
$w]
4528 pack
$w.buttons.save
-side right
4529 button
$w.buttons.cancel
-text {Cancel
} \
4531 -command [list destroy
$w]
4532 pack
$w.buttons.cancel
-side right
-padx 5
4533 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
4535 labelframe
$w.repo
-text "[reponame] Repository" \
4537 labelframe
$w.global
-text {Global
(All Repositories
)} \
4539 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
4540 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
4544 {t user.name
{User Name
}}
4545 {t user.email
{Email Address
}}
4547 {b merge.summary
{Summarize Merge Commits
}}
4548 {i-1.
.5 merge.verbosity
{Merge Verbosity
}}
4550 {b gui.trustmtime
{Trust File Modification Timestamps
}}
4551 {i-1.
.99 gui.diffcontext
{Number of Diff Context Lines
}}
4552 {t gui.newbranchtemplate
{New Branch Name Template
}}
4554 set type [lindex
$option 0]
4555 set name
[lindex
$option 1]
4556 set text
[lindex
$option 2]
4558 foreach f
{repo global
} {
4559 switch
-glob -- $type {
4561 checkbutton
$w.
$f.
$optid -text $text \
4562 -variable ${f}_config_new
($name) \
4566 pack
$w.
$f.
$optid -side top
-anchor w
4569 regexp
-- {-(\d
+)\.\.
(\d
+)$
} $type _junk min max
4571 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4572 pack
$w.
$f.
$optid.l
-side left
-anchor w
-fill x
4573 spinbox
$w.
$f.
$optid.v \
4574 -textvariable ${f}_config_new
($name) \
4578 -width [expr {1 + [string length
$max]}] \
4580 bind $w.
$f.
$optid.v
<FocusIn
> {%W selection range
0 end
}
4581 pack
$w.
$f.
$optid.v
-side right
-anchor e
-padx 5
4582 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4586 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
4587 entry
$w.
$f.
$optid.v \
4591 -textvariable ${f}_config_new
($name) \
4593 pack
$w.
$f.
$optid.l
-side left
-anchor w
4594 pack
$w.
$f.
$optid.v
-side left
-anchor w \
4597 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
4603 set all_fonts
[lsort
[font families
]]
4604 foreach option
$font_descs {
4605 set name
[lindex
$option 0]
4606 set font
[lindex
$option 1]
4607 set text
[lindex
$option 2]
4609 set global_config_new
(gui.
$font^^family
) \
4610 [font configure
$font -family]
4611 set global_config_new
(gui.
$font^^size
) \
4612 [font configure
$font -size]
4614 frame
$w.global.
$name
4615 label
$w.global.
$name.l
-text "$text:" -font font_ui
4616 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
4617 eval tk_optionMenu
$w.global.
$name.family \
4618 global_config_new
(gui.
$font^^family
) \
4620 spinbox
$w.global.
$name.size \
4621 -textvariable global_config_new
(gui.
$font^^size
) \
4622 -from 2 -to 80 -increment 1 \
4625 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
4626 pack
$w.global.
$name.size
-side right
-anchor e
4627 pack
$w.global.
$name.family
-side right
-anchor e
4628 pack
$w.global.
$name -side top
-anchor w
-fill x
4631 bind $w <Visibility
> "grab $w; focus $w"
4632 bind $w <Key-Escape
> "destroy $w"
4633 wm title
$w "[appname] ([reponame]): Options"
4637 proc do_restore_defaults
{} {
4638 global font_descs default_config repo_config
4639 global repo_config_new global_config_new
4641 foreach name
[array names default_config
] {
4642 set repo_config_new
($name) $default_config($name)
4643 set global_config_new
($name) $default_config($name)
4646 foreach option
$font_descs {
4647 set name
[lindex
$option 0]
4648 set repo_config
(gui.
$name) $default_config(gui.
$name)
4652 foreach option
$font_descs {
4653 set name
[lindex
$option 0]
4654 set font
[lindex
$option 1]
4655 set global_config_new
(gui.
$font^^family
) \
4656 [font configure
$font -family]
4657 set global_config_new
(gui.
$font^^size
) \
4658 [font configure
$font -size]
4662 proc do_save_config
{w
} {
4663 if {[catch
{save_config
} err
]} {
4664 error_popup
"Failed to completely save options:\n\n$err"
4670 proc do_windows_shortcut
{} {
4673 set fn
[tk_getSaveFile \
4675 -title "[appname] ([reponame]): Create Desktop Icon" \
4676 -initialfile "Git [reponame].bat"]
4680 puts
$fd "@ECHO Entering [reponame]"
4681 puts
$fd "@ECHO Starting git-gui... please wait..."
4682 puts
$fd "@SET PATH=[file normalize [gitexec]];%PATH%"
4683 puts
$fd "@SET GIT_DIR=[file normalize [gitdir]]"
4684 puts
-nonewline $fd "@\"[info nameofexecutable]\""
4685 puts
$fd " \"[file normalize $argv0]\""
4688 error_popup
"Cannot write script:\n\n$err"
4693 proc do_cygwin_shortcut
{} {
4697 set desktop
[exec cygpath \
4705 set fn
[tk_getSaveFile \
4707 -title "[appname] ([reponame]): Create Desktop Icon" \
4708 -initialdir $desktop \
4709 -initialfile "Git [reponame].bat"]
4713 set sh
[exec cygpath \
4717 set me
[exec cygpath \
4721 set gd
[exec cygpath \
4725 set gw
[exec cygpath \
4728 [file dirname [gitdir
]]]
4729 regsub
-all ' $me "'\\''" me
4730 regsub -all ' $gd "'\\''" gd
4731 puts $fd "@ECHO Entering $gw"
4732 puts $fd "@ECHO Starting git-gui... please wait..."
4733 puts -nonewline $fd "@\"$sh\" --login -c \""
4734 puts -nonewline $fd "GIT_DIR='$gd'"
4735 puts -nonewline $fd " '$me'"
4739 error_popup "Cannot write script:\n\n$err"
4744 proc do_macosx_app {} {
4747 set fn [tk_getSaveFile \
4749 -title "[appname] ([reponame]): Create Desktop Icon" \
4750 -initialdir [file join $env(HOME) Desktop] \
4751 -initialfile "Git [reponame].app"]
4754 set Contents [file join $fn Contents]
4755 set MacOS [file join $Contents MacOS]
4756 set exe [file join $MacOS git-gui]
4760 set fd [open [file join $Contents Info.plist] w]
4761 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
4762 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4763 <plist version="1.0">
4765 <key>CFBundleDevelopmentRegion</key>
4766 <string>English</string>
4767 <key>CFBundleExecutable</key>
4768 <string>git-gui</string>
4769 <key>CFBundleIdentifier</key>
4770 <string>org.spearce.git-gui</string>
4771 <key>CFBundleInfoDictionaryVersion</key>
4772 <string>6.0</string>
4773 <key>CFBundlePackageType</key>
4774 <string>APPL</string>
4775 <key>CFBundleSignature</key>
4776 <string>????</string>
4777 <key>CFBundleVersion</key>
4778 <string>1.0</string>
4779 <key>NSPrincipalClass</key>
4780 <string>NSApplication</string>
4785 set fd [open $exe w]
4786 set gd [file normalize [gitdir]]
4787 set ep [file normalize [gitexec]]
4788 regsub -all ' $gd "'\\''" gd
4789 regsub
-all ' $ep "'\\''" ep
4790 puts $fd "#!/bin/sh"
4791 foreach name
[array names env
] {
4792 if {[string match GIT_
* $name]} {
4793 regsub
-all ' $env($name) "'\\''" v
4794 puts $fd "export $name='$v'"
4797 puts $fd "export PATH
='$ep':\
$PATH"
4798 puts $fd "export GIT_DIR
='$gd'"
4799 puts $fd "exec [file normalize
$argv0]"
4802 file attributes $exe -permissions u+x,g+x,o+x
4804 error_popup "Cannot
write icon
:\n\n$err"
4809 proc toggle_or_diff {w x y} {
4810 global file_states file_lists current_diff_path ui_index ui_workdir
4811 global last_clicked selected_paths
4813 set pos [split [$w index @$x,$y] .]
4814 set lno [lindex $pos 0]
4815 set col [lindex $pos 1]
4816 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4822 set last_clicked [list $w $lno]
4823 array unset selected_paths
4824 $ui_index tag remove in_sel 0.0 end
4825 $ui_workdir tag remove in_sel 0.0 end
4828 if {$current_diff_path eq $path} {
4829 set after {reshow_diff;}
4833 if {$w eq $ui_index} {
4835 "Unstaging
[short_path
$path] from commit
" \
4837 [concat $after {set ui_status_value {Ready.}}]
4838 } elseif {$w eq $ui_workdir} {
4840 "Adding
[short_path
$path]" \
4842 [concat $after {set ui_status_value {Ready.}}]
4845 show_diff $path $w $lno
4849 proc add_one_to_selection {w x y} {
4850 global file_lists last_clicked selected_paths
4852 set lno [lindex [split [$w index @$x,$y] .] 0]
4853 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4859 if {$last_clicked ne {}
4860 && [lindex $last_clicked 0] ne $w} {
4861 array unset selected_paths
4862 [lindex $last_clicked 0] tag remove in_sel 0.0 end
4865 set last_clicked [list $w $lno]
4866 if {[catch {set in_sel $selected_paths($path)}]} {
4870 unset selected_paths($path)
4871 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
4873 set selected_paths($path) 1
4874 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
4878 proc add_range_to_selection {w x y} {
4879 global file_lists last_clicked selected_paths
4881 if {[lindex $last_clicked 0] ne $w} {
4882 toggle_or_diff $w $x $y
4886 set lno [lindex [split [$w index @$x,$y] .] 0]
4887 set lc [lindex $last_clicked 1]
4896 foreach path [lrange $file_lists($w) \
4897 [expr {$begin - 1}] \
4898 [expr {$end - 1}]] {
4899 set selected_paths($path) 1
4901 $w tag add in_sel $begin.0 [expr {$end + 1}].0
4904 ######################################################################
4908 set cursor_ptr arrow
4909 font create font_diff -family Courier -size 10
4913 eval font configure font_ui [font actual [.dummy cget -font]]
4917 font create font_uibold
4918 font create font_diffbold
4923 } elseif {[is_MacOSX]} {
4931 proc apply_config {} {
4932 global repo_config font_descs
4934 foreach option $font_descs {
4935 set name [lindex $option 0]
4936 set font [lindex $option 1]
4938 foreach {cn cv} $repo_config(gui.$name) {
4939 font configure $font $cn $cv
4942 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
4944 foreach {cn cv} [font configure $font] {
4945 font configure ${font}bold $cn $cv
4947 font configure ${font}bold -weight bold
4951 set default_config(merge.summary) false
4952 set default_config(merge.verbosity) 2
4953 set default_config(user.name) {}
4954 set default_config(user.email) {}
4956 set default_config(gui.trustmtime) false
4957 set default_config(gui.diffcontext) 5
4958 set default_config(gui.newbranchtemplate) {}
4959 set default_config(gui.fontui) [font configure font_ui]
4960 set default_config(gui.fontdiff) [font configure font_diff]
4962 {fontui font_ui {Main Font}}
4963 {fontdiff font_diff {Diff/Console Font}}
4968 ######################################################################
4970 ## feature option selection
4972 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {
4977 if {$subcommand eq {gui.sh}} {
4980 if {$subcommand eq {gui} && [llength $argv] > 0} {
4981 set subcommand [lindex $argv 0]
4982 set argv [lrange $argv 1 end]
4985 enable_option multicommit
4986 enable_option branch
4987 enable_option transport
4989 switch -- $subcommand {
4991 disable_option multicommit
4992 disable_option branch
4993 disable_option transport
4996 enable_option singlecommit
4998 disable_option multicommit
4999 disable_option branch
5000 disable_option transport
5004 ######################################################################
5012 menu .mbar -tearoff 0
5013 .mbar add cascade -label Repository -menu .mbar.repository
5014 .mbar add cascade -label Edit -menu .mbar.edit
5015 if {[is_enabled branch]} {
5016 .mbar add cascade -label Branch -menu .mbar.branch
5018 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
5019 .mbar add cascade -label Commit -menu .mbar.commit
5021 if {[is_enabled transport]} {
5022 .mbar add cascade -label Merge -menu .mbar.merge
5023 .mbar add cascade -label Fetch -menu .mbar.fetch
5024 .mbar add cascade -label Push -menu .mbar.push
5026 . configure -menu .mbar
5028 # -- Repository Menu
5030 menu .mbar.repository
5032 .mbar.repository add command \
5033 -label {Browse Current Branch} \
5034 -command {new_browser $current_branch} \
5036 trace add variable current_branch write ".mbar.repository entryconf
[.mbar.repository index last
] -label \"Browse \
$current_branch\" ;#"
5037 .mbar.repository add separator
5039 .mbar.repository add
command \
5040 -label {Visualize Current Branch
} \
5041 -command {do_gitk
$current_branch} \
5043 trace add variable current_branch
write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#"
5044 .mbar.repository add
command \
5045 -label {Visualize All Branches
} \
5046 -command {do_gitk
--all} \
5048 .mbar.repository add separator
5050 if {[is_enabled multicommit
]} {
5051 .mbar.repository add
command -label {Database Statistics
} \
5055 .mbar.repository add
command -label {Compress Database
} \
5059 .mbar.repository add
command -label {Verify Database
} \
5060 -command do_fsck_objects \
5063 .mbar.repository add separator
5066 .mbar.repository add
command \
5067 -label {Create Desktop Icon
} \
5068 -command do_cygwin_shortcut \
5070 } elseif
{[is_Windows
]} {
5071 .mbar.repository add
command \
5072 -label {Create Desktop Icon
} \
5073 -command do_windows_shortcut \
5075 } elseif
{[is_MacOSX
]} {
5076 .mbar.repository add
command \
5077 -label {Create Desktop Icon
} \
5078 -command do_macosx_app \
5083 .mbar.repository add
command -label Quit \
5085 -accelerator $M1T-Q \
5091 .mbar.edit add
command -label Undo \
5092 -command {catch
{[focus
] edit undo
}} \
5093 -accelerator $M1T-Z \
5095 .mbar.edit add
command -label Redo \
5096 -command {catch
{[focus
] edit redo
}} \
5097 -accelerator $M1T-Y \
5099 .mbar.edit add separator
5100 .mbar.edit add
command -label Cut \
5101 -command {catch
{tk_textCut
[focus
]}} \
5102 -accelerator $M1T-X \
5104 .mbar.edit add
command -label Copy \
5105 -command {catch
{tk_textCopy
[focus
]}} \
5106 -accelerator $M1T-C \
5108 .mbar.edit add
command -label Paste \
5109 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
5110 -accelerator $M1T-V \
5112 .mbar.edit add
command -label Delete \
5113 -command {catch
{[focus
] delete sel.first sel.last
}} \
5116 .mbar.edit add separator
5117 .mbar.edit add
command -label {Select All
} \
5118 -command {catch
{[focus
] tag add sel
0.0 end
}} \
5119 -accelerator $M1T-A \
5124 if {[is_enabled branch
]} {
5127 .mbar.branch add
command -label {Create...
} \
5128 -command do_create_branch \
5129 -accelerator $M1T-N \
5131 lappend disable_on_lock
[list .mbar.branch entryconf \
5132 [.mbar.branch index last
] -state]
5134 .mbar.branch add
command -label {Delete...
} \
5135 -command do_delete_branch \
5137 lappend disable_on_lock
[list .mbar.branch entryconf \
5138 [.mbar.branch index last
] -state]
5143 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
5146 .mbar.commit add radiobutton \
5147 -label {New Commit
} \
5148 -command do_select_commit_type \
5149 -variable selected_commit_type \
5152 lappend disable_on_lock \
5153 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5155 .mbar.commit add radiobutton \
5156 -label {Amend Last Commit
} \
5157 -command do_select_commit_type \
5158 -variable selected_commit_type \
5161 lappend disable_on_lock \
5162 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5164 .mbar.commit add separator
5166 .mbar.commit add
command -label Rescan \
5167 -command do_rescan \
5170 lappend disable_on_lock \
5171 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5173 .mbar.commit add
command -label {Add To Commit
} \
5174 -command do_add_selection \
5176 lappend disable_on_lock \
5177 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5179 .mbar.commit add
command -label {Add Existing To Commit
} \
5180 -command do_add_all \
5181 -accelerator $M1T-I \
5183 lappend disable_on_lock \
5184 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5186 .mbar.commit add
command -label {Unstage From Commit
} \
5187 -command do_unstage_selection \
5189 lappend disable_on_lock \
5190 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5192 .mbar.commit add
command -label {Revert Changes
} \
5193 -command do_revert_selection \
5195 lappend disable_on_lock \
5196 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5198 .mbar.commit add separator
5200 .mbar.commit add
command -label {Sign Off
} \
5201 -command do_signoff \
5202 -accelerator $M1T-S \
5205 .mbar.commit add
command -label Commit \
5206 -command do_commit \
5207 -accelerator $M1T-Return \
5209 lappend disable_on_lock \
5210 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
5214 # -- Apple Menu (Mac OS X only)
5216 .mbar add cascade
-label Apple
-menu .mbar.apple
5219 .mbar.apple add
command -label "About [appname]" \
5222 .mbar.apple add
command -label "Options..." \
5223 -command do_options \
5228 .mbar.edit add separator
5229 .mbar.edit add
command -label {Options...
} \
5230 -command do_options \
5235 if {[file exists
/usr
/local
/miga
/lib
/gui-miga
]
5236 && [file exists .pvcsrc
]} {
5238 global ui_status_value
5239 if {![lock_index update
]} return
5240 set cmd
[list sh
--login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
5241 set miga_fd
[open
"|$cmd" r
]
5242 fconfigure
$miga_fd -blocking 0
5243 fileevent
$miga_fd readable
[list miga_done
$miga_fd]
5244 set ui_status_value
{Running miga...
}
5246 proc miga_done
{fd
} {
5251 rescan
[list
set ui_status_value
{Ready.
}]
5254 .mbar add cascade
-label Tools
-menu .mbar.tools
5256 .mbar.tools add
command -label "Migrate" \
5259 lappend disable_on_lock \
5260 [list .mbar.tools entryconf
[.mbar.tools index last
] -state]
5266 .mbar add cascade
-label Help
-menu .mbar.
help
5270 .mbar.
help add
command -label "About [appname]" \
5276 catch
{set browser
$repo_config(instaweb.browser
)}
5277 set doc_path
[file dirname [gitexec
]]
5278 set doc_path
[file join $doc_path Documentation index.html
]
5281 set doc_path
[exec cygpath
--windows $doc_path]
5284 if {$browser eq
{}} {
5287 } elseif
{[is_Cygwin
]} {
5288 set program_files
[file dirname [exec cygpath
--windir]]
5289 set program_files
[file join $program_files {Program Files
}]
5290 set firefox
[file join $program_files {Mozilla Firefox
} firefox.exe
]
5291 set ie
[file join $program_files {Internet Explorer
} IEXPLORE.EXE
]
5292 if {[file exists
$firefox]} {
5293 set browser
$firefox
5294 } elseif
{[file exists
$ie]} {
5297 unset program_files firefox ie
5301 if {[file isfile
$doc_path]} {
5302 set doc_url
"file:$doc_path"
5304 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
5307 if {$browser ne
{}} {
5308 .mbar.
help add
command -label {Online Documentation
} \
5309 -command [list
exec $browser $doc_url &] \
5312 unset browser doc_path doc_url
5314 # -- Standard bindings
5316 bind .
<Destroy
> do_quit
5317 bind all
<$M1B-Key-q> do_quit
5318 bind all
<$M1B-Key-Q> do_quit
5319 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
5320 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
5322 # -- Not a normal commit type invocation? Do that instead!
5324 switch
-- $subcommand {
5326 if {[llength
$argv] != 2} {
5327 puts stderr
"usage: $argv0 blame commit path"
5330 set current_branch
[lindex
$argv 0]
5331 show_blame
$current_branch [lindex
$argv 1]
5336 if {[llength
$argv] != 0} {
5337 puts
-nonewline stderr
"usage: $argv0"
5338 if {$subcommand ne
{gui
} && [appname
] ne
"git-$subcommand"} {
5339 puts
-nonewline stderr
" $subcommand"
5344 # fall through to setup UI for commits
5347 puts stderr
"usage: $argv0 \[{blame|citool}\]"
5358 -text {Current Branch
:} \
5363 -textvariable current_branch \
5367 pack .branch.l1
-side left
5368 pack .branch.cb
-side left
-fill x
5369 pack .branch
-side top
-fill x
5371 if {[is_enabled branch
]} {
5373 .mbar.merge add
command -label {Local Merge...
} \
5374 -command do_local_merge \
5376 lappend disable_on_lock \
5377 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5378 .mbar.merge add
command -label {Abort Merge...
} \
5379 -command do_reset_hard \
5381 lappend disable_on_lock \
5382 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
5388 .mbar.push add
command -label {Push...
} \
5389 -command do_push_anywhere \
5393 # -- Main Window Layout
5395 panedwindow .vpane
-orient vertical
5396 panedwindow .vpane.files
-orient horizontal
5397 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
5398 pack .vpane
-anchor n
-side top
-fill both
-expand 1
5400 # -- Index File List
5402 frame .vpane.files.index
-height 100 -width 200
5403 label .vpane.files.index.title
-text {Changes To Be Committed
} \
5406 text
$ui_index -background white
-borderwidth 0 \
5407 -width 20 -height 10 \
5410 -cursor $cursor_ptr \
5411 -xscrollcommand {.vpane.files.index.sx
set} \
5412 -yscrollcommand {.vpane.files.index.sy
set} \
5414 scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
5415 scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
5416 pack .vpane.files.index.title
-side top
-fill x
5417 pack .vpane.files.index.sx
-side bottom
-fill x
5418 pack .vpane.files.index.sy
-side right
-fill y
5419 pack
$ui_index -side left
-fill both
-expand 1
5420 .vpane.files add .vpane.files.index
-sticky nsew
5422 # -- Working Directory File List
5424 frame .vpane.files.workdir
-height 100 -width 200
5425 label .vpane.files.workdir.title
-text {Changed But Not Updated
} \
5428 text
$ui_workdir -background white
-borderwidth 0 \
5429 -width 20 -height 10 \
5432 -cursor $cursor_ptr \
5433 -xscrollcommand {.vpane.files.workdir.sx
set} \
5434 -yscrollcommand {.vpane.files.workdir.sy
set} \
5436 scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
5437 scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
5438 pack .vpane.files.workdir.title
-side top
-fill x
5439 pack .vpane.files.workdir.sx
-side bottom
-fill x
5440 pack .vpane.files.workdir.sy
-side right
-fill y
5441 pack
$ui_workdir -side left
-fill both
-expand 1
5442 .vpane.files add .vpane.files.workdir
-sticky nsew
5444 foreach i
[list
$ui_index $ui_workdir] {
5445 $i tag conf in_diff
-font font_uibold
5446 $i tag conf in_sel \
5447 -background [$i cget
-foreground] \
5448 -foreground [$i cget
-background]
5452 # -- Diff and Commit Area
5454 frame .vpane.lower
-height 300 -width 400
5455 frame .vpane.lower.commarea
5456 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
5457 pack .vpane.lower.commarea
-side top
-fill x
5458 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
5459 .vpane add .vpane.lower
-sticky nsew
5461 # -- Commit Area Buttons
5463 frame .vpane.lower.commarea.buttons
5464 label .vpane.lower.commarea.buttons.l
-text {} \
5468 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
5469 pack .vpane.lower.commarea.buttons
-side left
-fill y
5471 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
5472 -command do_rescan \
5474 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
5475 lappend disable_on_lock \
5476 {.vpane.lower.commarea.buttons.rescan conf
-state}
5478 button .vpane.lower.commarea.buttons.incall
-text {Add Existing
} \
5479 -command do_add_all \
5481 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
5482 lappend disable_on_lock \
5483 {.vpane.lower.commarea.buttons.incall conf
-state}
5485 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
5486 -command do_signoff \
5488 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
5490 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
5491 -command do_commit \
5493 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
5494 lappend disable_on_lock \
5495 {.vpane.lower.commarea.buttons.commit conf
-state}
5497 # -- Commit Message Buffer
5499 frame .vpane.lower.commarea.buffer
5500 frame .vpane.lower.commarea.buffer.header
5501 set ui_comm .vpane.lower.commarea.buffer.t
5502 set ui_coml .vpane.lower.commarea.buffer.header.l
5503 radiobutton .vpane.lower.commarea.buffer.header.new \
5504 -text {New Commit
} \
5505 -command do_select_commit_type \
5506 -variable selected_commit_type \
5509 lappend disable_on_lock \
5510 [list .vpane.lower.commarea.buffer.header.new conf
-state]
5511 radiobutton .vpane.lower.commarea.buffer.header.amend \
5512 -text {Amend Last Commit
} \
5513 -command do_select_commit_type \
5514 -variable selected_commit_type \
5517 lappend disable_on_lock \
5518 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
5523 proc trace_commit_type
{varname args
} {
5524 global ui_coml commit_type
5525 switch
-glob -- $commit_type {
5526 initial
{set txt
{Initial Commit Message
:}}
5527 amend
{set txt
{Amended Commit Message
:}}
5528 amend-initial
{set txt
{Amended Initial Commit Message
:}}
5529 amend-merge
{set txt
{Amended Merge Commit Message
:}}
5530 merge
{set txt
{Merge Commit Message
:}}
5531 * {set txt
{Commit Message
:}}
5533 $ui_coml conf
-text $txt
5535 trace add variable commit_type
write trace_commit_type
5536 pack
$ui_coml -side left
-fill x
5537 pack .vpane.lower.commarea.buffer.header.amend
-side right
5538 pack .vpane.lower.commarea.buffer.header.new
-side right
5540 text
$ui_comm -background white
-borderwidth 1 \
5543 -autoseparators true \
5545 -width 75 -height 9 -wrap none \
5547 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
5548 scrollbar .vpane.lower.commarea.buffer.sby \
5549 -command [list
$ui_comm yview
]
5550 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
5551 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
5552 pack
$ui_comm -side left
-fill y
5553 pack .vpane.lower.commarea.buffer
-side left
-fill y
5555 # -- Commit Message Buffer Context Menu
5557 set ctxm .vpane.lower.commarea.buffer.ctxm
5558 menu
$ctxm -tearoff 0
5562 -command {tk_textCut
$ui_comm}
5566 -command {tk_textCopy
$ui_comm}
5570 -command {tk_textPaste
$ui_comm}
5574 -command {$ui_comm delete sel.first sel.last
}
5577 -label {Select All
} \
5579 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
5584 $ui_comm tag add sel
0.0 end
5585 tk_textCopy
$ui_comm
5586 $ui_comm tag remove sel
0.0 end
5593 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
5597 set current_diff_path
{}
5598 set current_diff_side
{}
5599 set diff_actions
[list
]
5600 proc trace_current_diff_path
{varname args
} {
5601 global current_diff_path diff_actions file_states
5602 if {$current_diff_path eq
{}} {
5608 set p
$current_diff_path
5609 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
5611 set p
[escape_path
$p]
5615 .vpane.lower.
diff.header.status configure
-text $s
5616 .vpane.lower.
diff.header.
file configure
-text $f
5617 .vpane.lower.
diff.header.path configure
-text $p
5618 foreach w
$diff_actions {
5622 trace add variable current_diff_path
write trace_current_diff_path
5624 frame .vpane.lower.
diff.header
-background orange
5625 label .vpane.lower.
diff.header.status \
5626 -background orange \
5627 -width $max_status_desc \
5631 label .vpane.lower.
diff.header.
file \
5632 -background orange \
5636 label .vpane.lower.
diff.header.path \
5637 -background orange \
5641 pack .vpane.lower.
diff.header.status
-side left
5642 pack .vpane.lower.
diff.header.
file -side left
5643 pack .vpane.lower.
diff.header.path
-fill x
5644 set ctxm .vpane.lower.
diff.header.ctxm
5645 menu
$ctxm -tearoff 0
5654 -- $current_diff_path
5656 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5657 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
5661 frame .vpane.lower.
diff.body
5662 set ui_diff .vpane.lower.
diff.body.t
5663 text
$ui_diff -background white
-borderwidth 0 \
5664 -width 80 -height 15 -wrap none \
5666 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
5667 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
5669 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
5670 -command [list
$ui_diff xview
]
5671 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
5672 -command [list
$ui_diff yview
]
5673 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
5674 pack .vpane.lower.
diff.body.sby
-side right
-fill y
5675 pack
$ui_diff -side left
-fill both
-expand 1
5676 pack .vpane.lower.
diff.header
-side top
-fill x
5677 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
5679 $ui_diff tag conf d_cr
-elide true
5680 $ui_diff tag conf d_@
-foreground blue
-font font_diffbold
5681 $ui_diff tag conf d_
+ -foreground {#00a000}
5682 $ui_diff tag conf d_-
-foreground red
5684 $ui_diff tag conf d_
++ -foreground {#00a000}
5685 $ui_diff tag conf d_--
-foreground red
5686 $ui_diff tag conf d_
+s \
5687 -foreground {#00a000} \
5688 -background {#e2effa}
5689 $ui_diff tag conf d_-s \
5691 -background {#e2effa}
5692 $ui_diff tag conf d_s
+ \
5693 -foreground {#00a000} \
5695 $ui_diff tag conf d_s- \
5699 $ui_diff tag conf d
<<<<<<< \
5700 -foreground orange \
5702 $ui_diff tag conf d
======= \
5703 -foreground orange \
5705 $ui_diff tag conf d
>>>>>>> \
5706 -foreground orange \
5709 $ui_diff tag raise sel
5711 # -- Diff Body Context Menu
5713 set ctxm .vpane.lower.
diff.body.ctxm
5714 menu
$ctxm -tearoff 0
5718 -command reshow_diff
5719 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5723 -command {tk_textCopy
$ui_diff}
5724 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5726 -label {Select All
} \
5728 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
5729 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5734 $ui_diff tag add sel
0.0 end
5735 tk_textCopy
$ui_diff
5736 $ui_diff tag remove sel
0.0 end
5738 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5741 -label {Apply
/Reverse Hunk
} \
5743 -command {apply_hunk
$cursorX $cursorY}
5744 set ui_diff_applyhunk
[$ctxm index last
]
5745 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
5748 -label {Decrease Font Size
} \
5750 -command {incr_font_size font_diff
-1}
5751 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5753 -label {Increase Font Size
} \
5755 -command {incr_font_size font_diff
1}
5756 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5759 -label {Show Less Context
} \
5761 -command {if {$repo_config(gui.diffcontext
) >= 2} {
5762 incr repo_config
(gui.diffcontext
) -1
5765 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5767 -label {Show More Context
} \
5770 incr repo_config
(gui.diffcontext
)
5773 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
5775 $ctxm add
command -label {Options...
} \
5778 bind_button3
$ui_diff "
5781 if {\$ui_index eq \$current_diff_side} {
5782 $ctxm entryconf $ui_diff_applyhunk -label {Unstage Hunk From Commit}
5784 $ctxm entryconf $ui_diff_applyhunk -label {Stage Hunk For Commit}
5786 tk_popup $ctxm %X %Y
5788 unset ui_diff_applyhunk
5792 set ui_status_value
{Initializing...
}
5793 label .status
-textvariable ui_status_value \
5799 pack .status
-anchor w
-side bottom
-fill x
5804 set gm
$repo_config(gui.geometry
)
5805 wm geometry .
[lindex
$gm 0]
5806 .vpane sash place
0 \
5807 [lindex
[.vpane sash coord
0] 0] \
5809 .vpane.files sash place
0 \
5811 [lindex
[.vpane.files sash coord
0] 1]
5817 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
5818 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
5819 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
5820 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
5821 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
5822 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
5823 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
5824 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
5825 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
5826 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5827 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5829 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
5830 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
5831 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
5832 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
5833 bind $ui_diff <$M1B-Key-v> {break}
5834 bind $ui_diff <$M1B-Key-V> {break}
5835 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
5836 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
5837 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
5838 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
5839 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
5840 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
5841 bind $ui_diff <Button-1
> {focus
%W
}
5843 if {[is_enabled branch
]} {
5844 bind .
<$M1B-Key-n> do_create_branch
5845 bind .
<$M1B-Key-N> do_create_branch
5848 bind all
<Key-F5
> do_rescan
5849 bind all
<$M1B-Key-r> do_rescan
5850 bind all
<$M1B-Key-R> do_rescan
5851 bind .
<$M1B-Key-s> do_signoff
5852 bind .
<$M1B-Key-S> do_signoff
5853 bind .
<$M1B-Key-i> do_add_all
5854 bind .
<$M1B-Key-I> do_add_all
5855 bind .
<$M1B-Key-Return> do_commit
5856 foreach i
[list
$ui_index $ui_workdir] {
5857 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
5858 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
5859 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
5863 set file_lists
($ui_index) [list
]
5864 set file_lists
($ui_workdir) [list
]
5868 set MERGE_HEAD
[list
]
5871 set current_branch
{}
5872 set current_diff_path
{}
5873 set selected_commit_type new
5875 wm title .
"[appname] ([file normalize [file dirname [gitdir]]])"
5876 focus
-force $ui_comm
5878 # -- Warn the user about environmental problems. Cygwin's Tcl
5879 # does *not* pass its env array onto any processes it spawns.
5880 # This means that git processes get none of our environment.
5885 set msg
"Possible environment issues exist.
5887 The following environment variables are probably
5888 going to be ignored by any Git subprocess run
5892 foreach name
[array names env
] {
5893 switch
-regexp -- $name {
5894 {^GIT_INDEX_FILE$
} -
5895 {^GIT_OBJECT_DIRECTORY$
} -
5896 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
5898 {^GIT_EXTERNAL_DIFF$
} -
5902 {^GIT_CONFIG_LOCAL$
} -
5903 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
5904 append msg
" - $name\n"
5907 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
5908 append msg
" - $name\n"
5910 set suggest_user
$name
5914 if {$ignored_env > 0} {
5916 This is due to a known issue with the
5917 Tcl binary distributed by Cygwin."
5919 if {$suggest_user ne
{}} {
5922 A good replacement for $suggest_user
5923 is placing values for the user.name and
5924 user.email settings into your personal
5930 unset ignored_env msg suggest_user name
5933 # -- Only initialize complex UI if we are going to stay running.
5935 if {[is_enabled transport
]} {
5939 populate_branch_menu
5944 # -- Only suggest a gc run if we are going to stay running.
5946 if {[is_enabled multicommit
]} {
5947 set object_limit
2000
5948 if {[is_Windows
]} {set object_limit
200}
5949 regexp
{^
([0-9]+) objects
,} [git count-objects
] _junk objects_current
5950 if {$objects_current >= $object_limit} {
5952 "This repository currently has $objects_current loose objects.
5954 To maintain optimal performance it is strongly
5955 recommended that you compress the database
5956 when more than $object_limit loose objects exist.
5958 Compress the database now?"] eq
yes} {
5962 unset object_limit _junk objects_current
5965 lock_index begin-read