2 # Tcl ignores the next line -*- tcl -*- \
5 set appvers
{@@GIT_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
]
41 return [eval [concat
[list
file join $_gitdir] $args]]
49 ######################################################################
53 proc is_many_config
{name
} {
54 switch
-glob -- $name {
63 proc load_config
{include_global
} {
64 global repo_config global_config default_config
66 array
unset global_config
67 if {$include_global} {
69 set fd_rc
[open
"| git repo-config --global --list" r
]
70 while {[gets
$fd_rc line
] >= 0} {
71 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
72 if {[is_many_config
$name]} {
73 lappend global_config
($name) $value
75 set global_config
($name) $value
83 array
unset repo_config
85 set fd_rc
[open
"| git repo-config --list" r
]
86 while {[gets
$fd_rc line
] >= 0} {
87 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
88 if {[is_many_config
$name]} {
89 lappend repo_config
($name) $value
91 set repo_config
($name) $value
98 foreach name
[array names default_config
] {
99 if {[catch
{set v
$global_config($name)}]} {
100 set global_config
($name) $default_config($name)
102 if {[catch
{set v
$repo_config($name)}]} {
103 set repo_config
($name) $default_config($name)
108 proc save_config
{} {
109 global default_config font_descs
110 global repo_config global_config
111 global repo_config_new global_config_new
113 foreach option
$font_descs {
114 set name
[lindex
$option 0]
115 set font
[lindex
$option 1]
116 font configure
$font \
117 -family $global_config_new(gui.
$font^^family
) \
118 -size $global_config_new(gui.
$font^^size
)
119 font configure
${font}bold \
120 -family $global_config_new(gui.
$font^^family
) \
121 -size $global_config_new(gui.
$font^^size
)
122 set global_config_new
(gui.
$name) [font configure
$font]
123 unset global_config_new
(gui.
$font^^family
)
124 unset global_config_new
(gui.
$font^^size
)
127 foreach name
[array names default_config
] {
128 set value
$global_config_new($name)
129 if {$value ne
$global_config($name)} {
130 if {$value eq
$default_config($name)} {
131 catch
{exec git repo-config
--global --unset $name}
133 regsub
-all "\[{}\]" $value {"} value
134 exec git repo-config --global $name $value
136 set global_config($name) $value
137 if {$value eq $repo_config($name)} {
138 catch {exec git repo-config --unset $name}
139 set repo_config($name) $value
144 foreach name [array names default_config] {
145 set value $repo_config_new($name)
146 if {$value ne $repo_config($name)} {
147 if {$value eq $global_config($name)} {
148 catch {exec git repo-config --unset $name}
150 regsub -all "\
[{}\
]" $value {"} value
151 exec git repo-config
$name $value
153 set repo_config
($name) $value
158 proc error_popup
{msg
} {
160 if {[reponame
] ne
{}} {
161 append title
" ([reponame])"
163 set cmd
[list tk_messageBox \
166 -title "$title: error" \
168 if {[winfo ismapped .
]} {
169 lappend cmd
-parent .
174 proc warn_popup
{msg
} {
176 if {[reponame
] ne
{}} {
177 append title
" ([reponame])"
179 set cmd
[list tk_messageBox \
182 -title "$title: warning" \
184 if {[winfo ismapped .
]} {
185 lappend cmd
-parent .
190 proc info_popup
{msg
} {
192 if {[reponame
] ne
{}} {
193 append title
" ([reponame])"
203 proc ask_popup
{msg
} {
205 if {[reponame
] ne
{}} {
206 append title
" ([reponame])"
208 return [tk_messageBox \
216 ######################################################################
220 if { [catch
{set _gitdir
$env(GIT_DIR
)}]
221 && [catch
{set _gitdir
[exec git rev-parse
--git-dir]} err
]} {
222 catch
{wm withdraw .
}
223 error_popup
"Cannot find the git directory:\n\n$err"
226 if {![file isdirectory
$_gitdir]} {
227 catch
{wm withdraw .
}
228 error_popup
"Git directory not found:\n\n$_gitdir"
231 if {[lindex
[file split $_gitdir] end
] ne
{.git
}} {
232 catch
{wm withdraw .
}
233 error_popup
"Cannot use funny .git directory:\n\n$gitdir"
236 if {[catch
{cd [file dirname $_gitdir]} err
]} {
237 catch
{wm withdraw .
}
238 error_popup
"No working directory [file dirname $_gitdir]:\n\n$err"
241 set _reponame
[lindex
[file split \
242 [file normalize
[file dirname $_gitdir]]] \
246 if {[appname
] eq
{git-citool
}} {
250 ######################################################################
258 set disable_on_lock
[list
]
259 set index_lock_type none
261 proc lock_index
{type} {
262 global index_lock_type disable_on_lock
264 if {$index_lock_type eq
{none
}} {
265 set index_lock_type
$type
266 foreach w
$disable_on_lock {
267 uplevel
#0 $w disabled
270 } elseif
{$index_lock_type eq
"begin-$type"} {
271 set index_lock_type
$type
277 proc unlock_index
{} {
278 global index_lock_type disable_on_lock
280 set index_lock_type none
281 foreach w
$disable_on_lock {
286 ######################################################################
290 proc repository_state
{ctvar hdvar mhvar
} {
291 global current_branch
292 upvar
$ctvar ct
$hdvar hd
$mhvar mh
296 if {[catch
{set current_branch
[exec git symbolic-ref HEAD
]}]} {
297 set current_branch
{}
299 regsub ^refs
/((heads|tags|remotes
)/)? \
305 if {[catch
{set hd
[exec git rev-parse
--verify HEAD
]}]} {
311 set merge_head
[gitdir MERGE_HEAD
]
312 if {[file exists
$merge_head]} {
314 set fd_mh
[open
$merge_head r
]
315 while {[gets
$fd_mh line
] >= 0} {
326 global PARENT empty_tree
328 set p
[lindex
$PARENT 0]
332 if {$empty_tree eq
{}} {
333 set empty_tree
[exec git mktree
<< {}]
338 proc rescan
{after
{honor_trustmtime
1}} {
339 global HEAD PARENT MERGE_HEAD commit_type
340 global ui_index ui_workdir ui_status_value ui_comm
341 global rescan_active file_states
344 if {$rescan_active > 0 ||
![lock_index
read]} return
346 repository_state newType newHEAD newMERGE_HEAD
347 if {[string match amend
* $commit_type]
348 && $newType eq
{normal
}
349 && $newHEAD eq
$HEAD} {
353 set MERGE_HEAD
$newMERGE_HEAD
354 set commit_type
$newType
357 array
unset file_states
359 if {![$ui_comm edit modified
]
360 ||
[string trim
[$ui_comm get
0.0 end
]] eq
{}} {
361 if {[load_message GITGUI_MSG
]} {
362 } elseif
{[load_message MERGE_MSG
]} {
363 } elseif
{[load_message SQUASH_MSG
]} {
366 $ui_comm edit modified false
369 if {$honor_trustmtime && $repo_config(gui.trustmtime
) eq
{true
}} {
370 rescan_stage2
{} $after
373 set ui_status_value
{Refreshing
file status...
}
374 set cmd
[list git update-index
]
376 lappend cmd
--unmerged
377 lappend cmd
--ignore-missing
378 lappend cmd
--refresh
379 set fd_rf
[open
"| $cmd" r
]
380 fconfigure
$fd_rf -blocking 0 -translation binary
381 fileevent
$fd_rf readable \
382 [list rescan_stage2
$fd_rf $after]
386 proc rescan_stage2
{fd after
} {
387 global ui_status_value
388 global rescan_active buf_rdi buf_rdf buf_rlo
392 if {![eof
$fd]} return
396 set ls_others
[list | git ls-files
--others -z \
397 --exclude-per-directory=.gitignore
]
398 set info_exclude
[gitdir info exclude
]
399 if {[file readable
$info_exclude]} {
400 lappend ls_others
"--exclude-from=$info_exclude"
408 set ui_status_value
{Scanning
for modified files ...
}
409 set fd_di
[open
"| git diff-index --cached -z [PARENT]" r
]
410 set fd_df
[open
"| git diff-files -z" r
]
411 set fd_lo
[open
$ls_others r
]
413 fconfigure
$fd_di -blocking 0 -translation binary
-encoding binary
414 fconfigure
$fd_df -blocking 0 -translation binary
-encoding binary
415 fconfigure
$fd_lo -blocking 0 -translation binary
-encoding binary
416 fileevent
$fd_di readable
[list read_diff_index
$fd_di $after]
417 fileevent
$fd_df readable
[list read_diff_files
$fd_df $after]
418 fileevent
$fd_lo readable
[list read_ls_others
$fd_lo $after]
421 proc load_message
{file} {
425 if {[file isfile
$f]} {
426 if {[catch
{set fd
[open
$f r
]}]} {
429 set content
[string trim
[read $fd]]
431 regsub
-all -line {[ \r\t]+$
} $content {} content
432 $ui_comm delete
0.0 end
433 $ui_comm insert end
$content
439 proc read_diff_index
{fd after
} {
442 append buf_rdi
[read $fd]
444 set n
[string length
$buf_rdi]
446 set z1
[string first
"\0" $buf_rdi $c]
449 set z2
[string first
"\0" $buf_rdi $z1]
453 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
454 set p
[string range
$buf_rdi $z1 [expr {$z2 - 1}]]
456 [encoding convertfrom
$p] \
458 [list
[lindex
$i 0] [lindex
$i 2]] \
464 set buf_rdi
[string range
$buf_rdi $c end
]
469 rescan_done
$fd buf_rdi
$after
472 proc read_diff_files
{fd after
} {
475 append buf_rdf
[read $fd]
477 set n
[string length
$buf_rdf]
479 set z1
[string first
"\0" $buf_rdf $c]
482 set z2
[string first
"\0" $buf_rdf $z1]
486 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
487 set p
[string range
$buf_rdf $z1 [expr {$z2 - 1}]]
489 [encoding convertfrom
$p] \
492 [list
[lindex
$i 0] [lindex
$i 2]]
497 set buf_rdf
[string range
$buf_rdf $c end
]
502 rescan_done
$fd buf_rdf
$after
505 proc read_ls_others
{fd after
} {
508 append buf_rlo
[read $fd]
509 set pck
[split $buf_rlo "\0"]
510 set buf_rlo
[lindex
$pck end
]
511 foreach p
[lrange
$pck 0 end-1
] {
512 merge_state
[encoding convertfrom
$p] ?O
514 rescan_done
$fd buf_rlo
$after
517 proc rescan_done
{fd buf after
} {
519 global file_states repo_config
522 if {![eof
$fd]} return
525 if {[incr rescan_active
-1] > 0} return
534 proc prune_selection
{} {
535 global file_states selected_paths
537 foreach path
[array names selected_paths
] {
538 if {[catch
{set still_here
$file_states($path)}]} {
539 unset selected_paths
($path)
544 ######################################################################
549 global ui_diff current_diff_path current_diff_header
550 global ui_index ui_workdir
552 $ui_diff conf
-state normal
553 $ui_diff delete
0.0 end
554 $ui_diff conf
-state disabled
556 set current_diff_path
{}
557 set current_diff_header
{}
559 $ui_index tag remove in_diff
0.0 end
560 $ui_workdir tag remove in_diff
0.0 end
563 proc reshow_diff
{} {
564 global ui_status_value file_states file_lists
565 global current_diff_path current_diff_side
567 set p
$current_diff_path
569 ||
$current_diff_side eq
{}
570 ||
[catch
{set s
$file_states($p)}]
571 ||
[lsearch
-sorted $file_lists($current_diff_side) $p] == -1} {
574 show_diff
$p $current_diff_side
578 proc handle_empty_diff
{} {
579 global current_diff_path file_states file_lists
581 set path
$current_diff_path
582 set s
$file_states($path)
583 if {[lindex
$s 0] ne
{_M
}} return
585 info_popup
"No differences detected.
587 [short_path $path] has no changes.
589 The modification date of this file was updated
590 by another application, but the content within
591 the file was not changed.
593 A rescan will be automatically started to find
594 other files which may have the same state."
597 display_file
$path __
598 rescan
{set ui_status_value
{Ready.
}} 0
601 proc show_diff
{path w
{lno
{}}} {
602 global file_states file_lists
603 global is_3way_diff diff_active repo_config
604 global ui_diff ui_status_value ui_index ui_workdir
605 global current_diff_path current_diff_side current_diff_header
607 if {$diff_active ||
![lock_index
read]} return
610 if {$w eq
{} ||
$lno == {}} {
611 foreach w
[array names file_lists
] {
612 set lno
[lsearch
-sorted $file_lists($w) $path]
619 if {$w ne
{} && $lno >= 1} {
620 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
623 set s
$file_states($path)
627 set current_diff_path
$path
628 set current_diff_side
$w
629 set current_diff_header
{}
630 set ui_status_value
"Loading diff of [escape_path $path]..."
632 # - Git won't give us the diff, there's nothing to compare to!
635 set max_sz
[expr {128 * 1024}]
637 set fd
[open
$path r
]
638 set content
[read $fd $max_sz]
640 set sz
[file size
$path]
644 set ui_status_value
"Unable to display [escape_path $path]"
645 error_popup
"Error loading file:\n\n$err"
648 $ui_diff conf
-state normal
649 if {![catch
{set type [exec file $path]}]} {
650 set n
[string length
$path]
651 if {[string equal
-length $n $path $type]} {
652 set type [string range
$type $n end
]
653 regsub
{^
:?\s
*} $type {} type
655 $ui_diff insert end
"* $type\n" d_@
657 if {[string first
"\0" $content] != -1} {
658 $ui_diff insert end \
659 "* Binary file (not showing content)." \
663 $ui_diff insert end \
664 "* Untracked file is $sz bytes.
665 * Showing only first $max_sz bytes.
668 $ui_diff insert end
$content
670 $ui_diff insert end
"
671 * Untracked file clipped here by [appname].
672 * To see the entire file, use an external editor.
676 $ui_diff conf
-state disabled
679 set ui_status_value
{Ready.
}
684 if {$w eq
$ui_index} {
685 lappend cmd diff-index
687 } elseif
{$w eq
$ui_workdir} {
688 if {[string index
$m 0] eq
{U
}} {
691 lappend cmd diff-files
696 lappend cmd
--no-color
697 if {$repo_config(gui.diffcontext
) > 0} {
698 lappend cmd
"-U$repo_config(gui.diffcontext)"
700 if {$w eq
$ui_index} {
706 if {[catch
{set fd
[open
$cmd r
]} err
]} {
709 set ui_status_value
"Unable to display [escape_path $path]"
710 error_popup
"Error loading diff:\n\n$err"
718 fileevent
$fd readable
[list read_diff
$fd]
721 proc read_diff
{fd
} {
722 global ui_diff ui_status_value diff_active
723 global is_3way_diff current_diff_header
725 $ui_diff conf
-state normal
726 while {[gets
$fd line
] >= 0} {
727 # -- Cleanup uninteresting diff header lines.
729 if { [string match
{diff --git *} $line]
730 ||
[string match
{diff --cc *} $line]
731 ||
[string match
{diff --combined *} $line]
732 ||
[string match
{--- *} $line]
733 ||
[string match
{+++ *} $line]} {
734 append current_diff_header
$line "\n"
737 if {[string match
{index
*} $line]} continue
738 if {$line eq
{deleted
file mode
120000}} {
739 set line
"deleted symlink"
742 # -- Automatically detect if this is a 3 way diff.
744 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
746 if {[string match
{mode
*} $line]
747 ||
[string match
{new
file *} $line]
748 ||
[string match
{deleted
file *} $line]
749 ||
[string match
{Binary files
* and
* differ
} $line]
750 ||
$line eq
{\ No newline
at end of
file}
751 ||
[regexp
{^\
* Unmerged path
} $line]} {
753 } elseif
{$is_3way_diff} {
754 set op
[string range
$line 0 1]
764 if {[regexp
{^\
+\
+([<>]{7} |
={7})} $line _g op
]} {
765 set line
[string replace
$line 0 1 { }]
772 puts
"error: Unhandled 3 way diff marker: {$op}"
777 set op
[string index
$line 0]
783 if {[regexp
{^\
+([<>]{7} |
={7})} $line _g op
]} {
784 set line
[string replace
$line 0 0 { }]
791 puts
"error: Unhandled 2 way diff marker: {$op}"
796 $ui_diff insert end
$line $tags
797 if {[string index
$line end
] eq
"\r"} {
798 $ui_diff tag add d_cr
{end
- 2c
}
800 $ui_diff insert end
"\n" $tags
802 $ui_diff conf
-state disabled
808 set ui_status_value
{Ready.
}
810 if {[$ui_diff index end
] eq
{2.0}} {
816 proc apply_hunk
{x y
} {
817 global current_diff_path current_diff_header current_diff_side
818 global ui_diff ui_index file_states
820 if {$current_diff_path eq
{} ||
$current_diff_header eq
{}} return
821 if {![lock_index apply_hunk
]} return
823 set apply_cmd
{git apply
--cached --whitespace=nowarn
}
824 set mi
[lindex
$file_states($current_diff_path) 0]
825 if {$current_diff_side eq
$ui_index} {
827 lappend apply_cmd
--reverse
828 if {[string index
$mi 0] ne
{M
}} {
834 if {[string index
$mi 1] ne
{M
}} {
840 set s_lno
[lindex
[split [$ui_diff index @
$x,$y] .
] 0]
841 set s_lno
[$ui_diff search
-backwards -regexp ^@@
$s_lno.0 0.0]
847 set e_lno
[$ui_diff search
-forwards -regexp ^@@
"$s_lno + 1 lines" end
]
853 set p
[open
"| $apply_cmd" w
]
854 fconfigure
$p -translation binary
-encoding binary
855 puts
-nonewline $p $current_diff_header
856 puts
-nonewline $p [$ui_diff get
$s_lno $e_lno]
858 error_popup
"Failed to $mode selected hunk.\n\n$err"
863 $ui_diff conf
-state normal
864 $ui_diff delete
$s_lno $e_lno
865 $ui_diff conf
-state disabled
867 if {[$ui_diff get
1.0 end
] eq
"\n"} {
873 if {$current_diff_side eq
$ui_index} {
875 } elseif
{[string index
$mi 0] eq
{_
}} {
881 display_file
$current_diff_path $mi
887 ######################################################################
891 proc load_last_commit
{} {
892 global HEAD PARENT MERGE_HEAD commit_type ui_comm
895 if {[llength
$PARENT] == 0} {
896 error_popup
{There is nothing to amend.
898 You are about to create the initial commit.
899 There is no commit before this to amend.
904 repository_state curType curHEAD curMERGE_HEAD
905 if {$curType eq
{merge
}} {
906 error_popup
{Cannot amend
while merging.
908 You are currently
in the middle of a merge that
909 has not been fully completed. You cannot amend
910 the prior commit unless you first abort the
911 current merge activity.
919 set fd
[open
"| git cat-file commit $curHEAD" r
]
920 fconfigure
$fd -encoding binary
-translation lf
921 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
924 while {[gets
$fd line
] > 0} {
925 if {[string match
{parent
*} $line]} {
926 lappend parents
[string range
$line 7 end
]
927 } elseif
{[string match
{encoding
*} $line]} {
928 set enc
[string tolower
[string range
$line 9 end
]]
931 fconfigure
$fd -encoding $enc
932 set msg
[string trim
[read $fd]]
935 error_popup
"Error loading commit data for amend:\n\n$err"
941 set MERGE_HEAD
[list
]
942 switch
-- [llength
$parents] {
943 0 {set commit_type amend-initial
}
944 1 {set commit_type amend
}
945 default
{set commit_type amend-merge
}
948 $ui_comm delete
0.0 end
949 $ui_comm insert end
$msg
951 $ui_comm edit modified false
952 rescan
{set ui_status_value
{Ready.
}}
955 proc create_new_commit
{} {
956 global commit_type ui_comm
958 set commit_type normal
959 $ui_comm delete
0.0 end
961 $ui_comm edit modified false
962 rescan
{set ui_status_value
{Ready.
}}
965 set GIT_COMMITTER_IDENT
{}
967 proc committer_ident
{} {
968 global GIT_COMMITTER_IDENT
970 if {$GIT_COMMITTER_IDENT eq
{}} {
971 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
972 error_popup
"Unable to obtain your identity:\n\n$err"
975 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
976 $me me GIT_COMMITTER_IDENT
]} {
977 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
982 return $GIT_COMMITTER_IDENT
985 proc commit_tree
{} {
986 global HEAD commit_type file_states ui_comm repo_config
987 global ui_status_value pch_error
989 if {![lock_index update
]} return
990 if {[committer_ident
] eq
{}} return
992 # -- Our in memory state should match the repository.
994 repository_state curType curHEAD curMERGE_HEAD
995 if {[string match amend
* $commit_type]
996 && $curType eq
{normal
}
997 && $curHEAD eq
$HEAD} {
998 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
999 info_popup
{Last scanned state does not match repository state.
1001 Another Git program has modified this repository
1002 since the last scan. A rescan must be performed
1003 before another commit can be created.
1005 The rescan will be automatically started now.
1008 rescan
{set ui_status_value
{Ready.
}}
1012 # -- At least one file should differ in the index.
1015 foreach path
[array names file_states
] {
1016 switch
-glob -- [lindex
$file_states($path) 0] {
1020 M?
{set files_ready
1}
1022 error_popup
"Unmerged files cannot be committed.
1024 File [short_path $path] has merge conflicts.
1025 You must resolve them and add the file before committing.
1031 error_popup
"Unknown file state [lindex $s 0] detected.
1033 File [short_path $path] cannot be committed by this program.
1038 if {!$files_ready} {
1039 info_popup
{No changes to commit.
1041 You must add
at least
1 file before you can commit.
1047 # -- A message is required.
1049 set msg
[string trim
[$ui_comm get
1.0 end
]]
1050 regsub
-all -line {[ \t\r]+$
} $msg {} msg
1052 error_popup
{Please supply a commit message.
1054 A good commit message has the following format
:
1056 - First line
: Describe
in one sentance what you did.
1057 - Second line
: Blank
1058 - Remaining lines
: Describe why this change is good.
1064 # -- Run the pre-commit hook.
1066 set pchook
[gitdir hooks pre-commit
]
1068 # On Cygwin [file executable] might lie so we need to ask
1069 # the shell if the hook is executable. Yes that's annoying.
1071 if {[is_Windows
] && [file isfile
$pchook]} {
1072 set pchook
[list sh
-c [concat \
1073 "if test -x \"$pchook\";" \
1074 "then exec \"$pchook\" 2>&1;" \
1076 } elseif
{[file executable
$pchook]} {
1077 set pchook
[list
$pchook |
& cat]
1079 commit_writetree
$curHEAD $msg
1083 set ui_status_value
{Calling pre-commit hook...
}
1085 set fd_ph
[open
"| $pchook" r
]
1086 fconfigure
$fd_ph -blocking 0 -translation binary
1087 fileevent
$fd_ph readable \
1088 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
1091 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
1092 global pch_error ui_status_value
1094 append pch_error
[read $fd_ph]
1095 fconfigure
$fd_ph -blocking 1
1097 if {[catch
{close
$fd_ph}]} {
1098 set ui_status_value
{Commit declined by pre-commit hook.
}
1099 hook_failed_popup pre-commit
$pch_error
1102 commit_writetree
$curHEAD $msg
1107 fconfigure
$fd_ph -blocking 0
1110 proc commit_writetree
{curHEAD msg
} {
1111 global ui_status_value
1113 set ui_status_value
{Committing changes...
}
1114 set fd_wt
[open
"| git write-tree" r
]
1115 fileevent
$fd_wt readable \
1116 [list commit_committree
$fd_wt $curHEAD $msg]
1119 proc commit_committree
{fd_wt curHEAD msg
} {
1120 global HEAD PARENT MERGE_HEAD commit_type
1121 global single_commit all_heads current_branch
1122 global ui_status_value ui_comm selected_commit_type
1123 global file_states selected_paths rescan_active
1127 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1128 error_popup
"write-tree failed:\n\n$err"
1129 set ui_status_value
{Commit failed.
}
1134 # -- Build the message.
1136 set msg_p
[gitdir COMMIT_EDITMSG
]
1137 set msg_wt
[open
$msg_p w
]
1138 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1141 fconfigure
$msg_wt -encoding $enc -translation binary
1142 puts
-nonewline $msg_wt $msg
1145 # -- Create the commit.
1147 set cmd
[list git commit-tree
$tree_id]
1148 set parents
[concat
$PARENT $MERGE_HEAD]
1149 if {[llength
$parents] > 0} {
1150 foreach p
$parents {
1154 # git commit-tree writes to stderr during initial commit.
1155 lappend cmd
2>/dev
/null
1158 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1159 error_popup
"commit-tree failed:\n\n$err"
1160 set ui_status_value
{Commit failed.
}
1165 # -- Update the HEAD ref.
1168 if {$commit_type ne
{normal
}} {
1169 append reflogm
" ($commit_type)"
1171 set i
[string first
"\n" $msg]
1173 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1175 append reflogm
{: } $msg
1177 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1178 if {[catch
{eval exec $cmd} err
]} {
1179 error_popup
"update-ref failed:\n\n$err"
1180 set ui_status_value
{Commit failed.
}
1185 # -- Make sure our current branch exists.
1187 if {$commit_type eq
{initial
}} {
1188 lappend all_heads
$current_branch
1189 set all_heads
[lsort
-unique $all_heads]
1190 populate_branch_menu
1193 # -- Cleanup after ourselves.
1195 catch
{file delete
$msg_p}
1196 catch
{file delete
[gitdir MERGE_HEAD
]}
1197 catch
{file delete
[gitdir MERGE_MSG
]}
1198 catch
{file delete
[gitdir SQUASH_MSG
]}
1199 catch
{file delete
[gitdir GITGUI_MSG
]}
1201 # -- Let rerere do its thing.
1203 if {[file isdirectory
[gitdir rr-cache
]]} {
1204 catch
{exec git rerere
}
1207 # -- Run the post-commit hook.
1209 set pchook
[gitdir hooks post-commit
]
1210 if {[is_Windows
] && [file isfile
$pchook]} {
1211 set pchook
[list sh
-c [concat \
1212 "if test -x \"$pchook\";" \
1213 "then exec \"$pchook\";" \
1215 } elseif
{![file executable
$pchook]} {
1218 if {$pchook ne
{}} {
1219 catch
{exec $pchook &}
1222 $ui_comm delete
0.0 end
1224 $ui_comm edit modified false
1226 if {$single_commit} do_quit
1228 # -- Update in memory status
1230 set selected_commit_type new
1231 set commit_type normal
1234 set MERGE_HEAD
[list
]
1236 foreach path
[array names file_states
] {
1237 set s
$file_states($path)
1239 switch
-glob -- $m {
1247 unset file_states
($path)
1248 catch
{unset selected_paths
($path)}
1251 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1257 set file_states
($path) [list \
1258 _
[string index
$m 1] \
1269 set ui_status_value \
1270 "Changes committed as [string range $cmt_id 0 7]."
1273 ######################################################################
1277 proc fetch_from
{remote
} {
1278 set w
[new_console
"fetch $remote" \
1279 "Fetching new changes from $remote"]
1280 set cmd
[list git fetch
]
1282 console_exec
$w $cmd
1285 proc pull_remote
{remote branch
} {
1286 global HEAD commit_type file_states repo_config
1288 if {![lock_index update
]} return
1290 # -- Our in memory state should match the repository.
1292 repository_state curType curHEAD curMERGE_HEAD
1293 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1294 info_popup
{Last scanned state does not match repository state.
1296 Another Git program has modified this repository
1297 since the last scan. A rescan must be performed
1298 before a pull operation can be started.
1300 The rescan will be automatically started now.
1303 rescan
{set ui_status_value
{Ready.
}}
1307 # -- No differences should exist before a pull.
1309 if {[array size file_states
] != 0} {
1310 error_popup
{Uncommitted but modified files are present.
1312 You should not perform a pull with unmodified
1313 files
in your working directory as Git will be
1314 unable to recover from an incorrect merge.
1316 You should commit or revert all changes before
1317 starting a pull operation.
1323 set w
[new_console
"pull $remote $branch" \
1324 "Pulling new changes from branch $branch in $remote"]
1325 set cmd
[list git pull
]
1326 if {$repo_config(gui.pullsummary
) eq
{false
}} {
1327 lappend cmd
--no-summary
1331 console_exec
$w $cmd [list post_pull_remote
$remote $branch]
1334 proc post_pull_remote
{remote branch success
} {
1335 global HEAD PARENT MERGE_HEAD commit_type selected_commit_type
1336 global ui_status_value
1340 repository_state commit_type HEAD MERGE_HEAD
1342 set selected_commit_type new
1343 set ui_status_value
"Pulling $branch from $remote complete."
1345 rescan
[list
set ui_status_value \
1346 "Conflicts detected while pulling $branch from $remote."]
1350 proc push_to
{remote
} {
1351 set w
[new_console
"push $remote" \
1352 "Pushing changes to $remote"]
1353 set cmd
[list git push
]
1355 console_exec
$w $cmd
1358 ######################################################################
1362 proc mapicon
{w state path
} {
1365 if {[catch
{set r
$all_icons($state$w)}]} {
1366 puts
"error: no icon for $w state={$state} $path"
1372 proc mapdesc
{state path
} {
1375 if {[catch
{set r
$all_descs($state)}]} {
1376 puts
"error: no desc for state={$state} $path"
1382 proc escape_path
{path
} {
1383 regsub
-all "\n" $path "\\n" path
1387 proc short_path
{path
} {
1388 return [escape_path
[lindex
[file split $path] end
]]
1392 set null_sha1
[string repeat
0 40]
1394 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1395 global file_states next_icon_id null_sha1
1397 set s0
[string index
$new_state 0]
1398 set s1
[string index
$new_state 1]
1400 if {[catch
{set info
$file_states($path)}]} {
1402 set icon n
[incr next_icon_id
]
1404 set state
[lindex
$info 0]
1405 set icon
[lindex
$info 1]
1406 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1407 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1410 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1411 elseif
{$s0 eq
{_
}} {set s0 _
}
1413 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1414 elseif
{$s1 eq
{_
}} {set s1 _
}
1416 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1417 set head_info
[list
0 $null_sha1]
1418 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1419 && $head_info eq
{}} {
1420 set head_info
$index_info
1423 set file_states
($path) [list
$s0$s1 $icon \
1424 $head_info $index_info \
1429 proc display_file_helper
{w path icon_name old_m new_m
} {
1432 if {$new_m eq
{_
}} {
1433 set lno
[lsearch
-sorted $file_lists($w) $path]
1435 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1437 $w conf
-state normal
1438 $w delete
$lno.0 [expr {$lno + 1}].0
1439 $w conf
-state disabled
1441 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1442 lappend file_lists
($w) $path
1443 set file_lists
($w) [lsort
-unique $file_lists($w)]
1444 set lno
[lsearch
-sorted $file_lists($w) $path]
1446 $w conf
-state normal
1447 $w image create
$lno.0 \
1448 -align center
-padx 5 -pady 1 \
1450 -image [mapicon
$w $new_m $path]
1451 $w insert
$lno.1 "[escape_path $path]\n"
1452 $w conf
-state disabled
1453 } elseif
{$old_m ne
$new_m} {
1454 $w conf
-state normal
1455 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1456 $w conf
-state disabled
1460 proc display_file
{path state
} {
1461 global file_states selected_paths
1462 global ui_index ui_workdir
1464 set old_m
[merge_state
$path $state]
1465 set s
$file_states($path)
1466 set new_m
[lindex
$s 0]
1467 set icon_name
[lindex
$s 1]
1469 set o
[string index
$old_m 0]
1470 set n
[string index
$new_m 0]
1477 display_file_helper
$ui_index $path $icon_name $o $n
1479 if {[string index
$old_m 0] eq
{U
}} {
1482 set o
[string index
$old_m 1]
1484 if {[string index
$new_m 0] eq
{U
}} {
1487 set n
[string index
$new_m 1]
1489 display_file_helper
$ui_workdir $path $icon_name $o $n
1491 if {$new_m eq
{__
}} {
1492 unset file_states
($path)
1493 catch
{unset selected_paths
($path)}
1497 proc display_all_files_helper
{w path icon_name m
} {
1500 lappend file_lists
($w) $path
1501 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1502 $w image create end \
1503 -align center
-padx 5 -pady 1 \
1505 -image [mapicon
$w $m $path]
1506 $w insert end
"[escape_path $path]\n"
1509 proc display_all_files
{} {
1510 global ui_index ui_workdir
1511 global file_states file_lists
1514 $ui_index conf
-state normal
1515 $ui_workdir conf
-state normal
1517 $ui_index delete
0.0 end
1518 $ui_workdir delete
0.0 end
1521 set file_lists
($ui_index) [list
]
1522 set file_lists
($ui_workdir) [list
]
1524 foreach path
[lsort
[array names file_states
]] {
1525 set s
$file_states($path)
1527 set icon_name
[lindex
$s 1]
1529 set s
[string index
$m 0]
1530 if {$s ne
{U
} && $s ne
{_
}} {
1531 display_all_files_helper
$ui_index $path \
1535 if {[string index
$m 0] eq
{U
}} {
1538 set s
[string index
$m 1]
1541 display_all_files_helper
$ui_workdir $path \
1546 $ui_index conf
-state disabled
1547 $ui_workdir conf
-state disabled
1550 proc update_indexinfo
{msg pathList after
} {
1551 global update_index_cp ui_status_value
1553 if {![lock_index update
]} return
1555 set update_index_cp
0
1556 set pathList
[lsort
$pathList]
1557 set totalCnt
[llength
$pathList]
1558 set batch [expr {int
($totalCnt * .01) + 1}]
1559 if {$batch > 25} {set batch 25}
1561 set ui_status_value
[format \
1562 "$msg... %i/%i files (%.2f%%)" \
1566 set fd
[open
"| git update-index -z --index-info" w
]
1573 fileevent
$fd writable
[list \
1574 write_update_indexinfo \
1584 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1585 global update_index_cp ui_status_value
1586 global file_states current_diff_path
1588 if {$update_index_cp >= $totalCnt} {
1595 for {set i
$batch} \
1596 {$update_index_cp < $totalCnt && $i > 0} \
1598 set path
[lindex
$pathList $update_index_cp]
1599 incr update_index_cp
1601 set s
$file_states($path)
1602 switch
-glob -- [lindex
$s 0] {
1609 set info
[lindex
$s 2]
1610 if {$info eq
{}} continue
1612 puts
-nonewline $fd "$info\t[encoding convertto $path]\0"
1613 display_file
$path $new
1616 set ui_status_value
[format \
1617 "$msg... %i/%i files (%.2f%%)" \
1620 [expr {100.0 * $update_index_cp / $totalCnt}]]
1623 proc update_index
{msg pathList after
} {
1624 global update_index_cp ui_status_value
1626 if {![lock_index update
]} return
1628 set update_index_cp
0
1629 set pathList
[lsort
$pathList]
1630 set totalCnt
[llength
$pathList]
1631 set batch [expr {int
($totalCnt * .01) + 1}]
1632 if {$batch > 25} {set batch 25}
1634 set ui_status_value
[format \
1635 "$msg... %i/%i files (%.2f%%)" \
1639 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1646 fileevent
$fd writable
[list \
1647 write_update_index \
1657 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1658 global update_index_cp ui_status_value
1659 global file_states current_diff_path
1661 if {$update_index_cp >= $totalCnt} {
1668 for {set i
$batch} \
1669 {$update_index_cp < $totalCnt && $i > 0} \
1671 set path
[lindex
$pathList $update_index_cp]
1672 incr update_index_cp
1674 switch
-glob -- [lindex
$file_states($path) 0] {
1680 if {[file exists
$path]} {
1689 puts
-nonewline $fd "[encoding convertto $path]\0"
1690 display_file
$path $new
1693 set ui_status_value
[format \
1694 "$msg... %i/%i files (%.2f%%)" \
1697 [expr {100.0 * $update_index_cp / $totalCnt}]]
1700 proc checkout_index
{msg pathList after
} {
1701 global update_index_cp ui_status_value
1703 if {![lock_index update
]} return
1705 set update_index_cp
0
1706 set pathList
[lsort
$pathList]
1707 set totalCnt
[llength
$pathList]
1708 set batch [expr {int
($totalCnt * .01) + 1}]
1709 if {$batch > 25} {set batch 25}
1711 set ui_status_value
[format \
1712 "$msg... %i/%i files (%.2f%%)" \
1716 set cmd
[list git checkout-index
]
1722 set fd
[open
"| $cmd " w
]
1729 fileevent
$fd writable
[list \
1730 write_checkout_index \
1740 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1741 global update_index_cp ui_status_value
1742 global file_states current_diff_path
1744 if {$update_index_cp >= $totalCnt} {
1751 for {set i
$batch} \
1752 {$update_index_cp < $totalCnt && $i > 0} \
1754 set path
[lindex
$pathList $update_index_cp]
1755 incr update_index_cp
1756 switch
-glob -- [lindex
$file_states($path) 0] {
1760 puts
-nonewline $fd "[encoding convertto $path]\0"
1761 display_file
$path ?_
1766 set ui_status_value
[format \
1767 "$msg... %i/%i files (%.2f%%)" \
1770 [expr {100.0 * $update_index_cp / $totalCnt}]]
1773 ######################################################################
1775 ## branch management
1777 proc is_tracking_branch
{name
} {
1778 global tracking_branches
1780 if {![catch
{set info
$tracking_branches($name)}]} {
1783 foreach t
[array names tracking_branches
] {
1784 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1791 proc load_all_heads
{} {
1794 set all_heads
[list
]
1795 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1796 while {[gets
$fd line
] > 0} {
1797 if {[is_tracking_branch
$line]} continue
1798 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1799 lappend all_heads
$name
1803 set all_heads
[lsort
$all_heads]
1806 proc populate_branch_menu
{} {
1807 global all_heads disable_on_lock
1810 set last
[$m index last
]
1811 for {set i
0} {$i <= $last} {incr i
} {
1812 if {[$m type $i] eq
{separator
}} {
1815 foreach a
$disable_on_lock {
1816 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1820 set disable_on_lock
$new_dol
1826 foreach b
$all_heads {
1827 $m add radiobutton \
1829 -command [list switch_branch
$b] \
1830 -variable current_branch \
1833 lappend disable_on_lock \
1834 [list
$m entryconf
[$m index last
] -state]
1838 proc all_tracking_branches
{} {
1839 global tracking_branches
1841 set all_trackings
{}
1843 foreach name
[array names tracking_branches
] {
1844 if {[regsub
{/\
*$
} $name {} name
]} {
1847 regsub ^refs
/(heads|remotes
)/ $name {} name
1848 lappend all_trackings
$name
1853 set fd
[open
"| git for-each-ref --format=%(refname) $cmd" r
]
1854 while {[gets
$fd name
] > 0} {
1855 regsub ^refs
/(heads|remotes
)/ $name {} name
1856 lappend all_trackings
$name
1861 return [lsort
-unique $all_trackings]
1864 proc do_create_branch_action
{w
} {
1865 global all_heads null_sha1 repo_config
1866 global create_branch_checkout create_branch_revtype
1867 global create_branch_head create_branch_trackinghead
1868 global create_branch_name create_branch_revexp
1870 set newbranch
$create_branch_name
1871 if {$newbranch eq
{}
1872 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1876 -title [wm title
$w] \
1878 -message "Please supply a branch name."
1879 focus
$w.desc.name_t
1882 if {![catch
{exec git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1886 -title [wm title
$w] \
1888 -message "Branch '$newbranch' already exists."
1889 focus
$w.desc.name_t
1892 if {[catch
{exec git check-ref-format
"heads/$newbranch"}]} {
1896 -title [wm title
$w] \
1898 -message "We do not like '$newbranch' as a branch name."
1899 focus
$w.desc.name_t
1904 switch
-- $create_branch_revtype {
1905 head {set rev $create_branch_head}
1906 tracking
{set rev $create_branch_trackinghead}
1907 expression
{set rev $create_branch_revexp}
1909 if {[catch
{set cmt
[exec git rev-parse
--verify "${rev}^0"]}]} {
1913 -title [wm title
$w] \
1915 -message "Invalid starting revision: $rev"
1918 set cmd
[list git update-ref
]
1920 lappend cmd
"branch: Created from $rev"
1921 lappend cmd
"refs/heads/$newbranch"
1923 lappend cmd
$null_sha1
1924 if {[catch
{eval exec $cmd} err
]} {
1928 -title [wm title
$w] \
1930 -message "Failed to create '$newbranch'.\n\n$err"
1934 lappend all_heads
$newbranch
1935 set all_heads
[lsort
$all_heads]
1936 populate_branch_menu
1938 if {$create_branch_checkout} {
1939 switch_branch
$newbranch
1943 proc radio_selector
{varname value args
} {
1944 upvar
#0 $varname var
1948 trace add variable create_branch_head
write \
1949 [list radio_selector create_branch_revtype
head]
1950 trace add variable create_branch_trackinghead
write \
1951 [list radio_selector create_branch_revtype tracking
]
1953 trace add variable delete_branch_head
write \
1954 [list radio_selector delete_branch_checktype
head]
1955 trace add variable delete_branch_trackinghead
write \
1956 [list radio_selector delete_branch_checktype tracking
]
1958 proc do_create_branch
{} {
1959 global all_heads current_branch repo_config
1960 global create_branch_checkout create_branch_revtype
1961 global create_branch_head create_branch_trackinghead
1962 global create_branch_name create_branch_revexp
1964 set w .branch_editor
1966 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1968 label
$w.header
-text {Create New Branch
} \
1970 pack
$w.header
-side top
-fill x
1973 button
$w.buttons.create
-text Create \
1976 -command [list do_create_branch_action
$w]
1977 pack
$w.buttons.create
-side right
1978 button
$w.buttons.cancel
-text {Cancel
} \
1980 -command [list destroy
$w]
1981 pack
$w.buttons.cancel
-side right
-padx 5
1982 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1984 labelframe
$w.desc \
1985 -text {Branch Description
} \
1987 label
$w.desc.name_l
-text {Name
:} -font font_ui
1988 entry
$w.desc.name_t \
1992 -textvariable create_branch_name \
1996 if {%d
== 1 && [regexp
{[~^
:?
*\
[\
0- ]} %S
]} {return 0}
1999 grid
$w.desc.name_l
$w.desc.name_t
-sticky we
-padx {0 5}
2000 grid columnconfigure
$w.desc
1 -weight 1
2001 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
2003 labelframe
$w.from \
2004 -text {Starting Revision
} \
2006 radiobutton
$w.from.head_r \
2007 -text {Local Branch
:} \
2009 -variable create_branch_revtype \
2011 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
2012 grid
$w.from.head_r
$w.from.head_m
-sticky w
2013 set all_trackings
[all_tracking_branches
]
2014 if {$all_trackings ne
{}} {
2015 set create_branch_trackinghead
[lindex
$all_trackings 0]
2016 radiobutton
$w.from.tracking_r \
2017 -text {Tracking Branch
:} \
2019 -variable create_branch_revtype \
2021 eval tk_optionMenu
$w.from.tracking_m \
2022 create_branch_trackinghead \
2024 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
2026 radiobutton
$w.from.exp_r \
2027 -text {Revision Expression
:} \
2029 -variable create_branch_revtype \
2031 entry
$w.from.exp_t \
2035 -textvariable create_branch_revexp \
2039 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2040 if {%d
== 1 && [string length
%S
] > 0} {
2041 set create_branch_revtype expression
2045 grid
$w.from.exp_r
$w.from.exp_t
-sticky we
-padx {0 5}
2046 grid columnconfigure
$w.from
1 -weight 1
2047 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
2049 labelframe
$w.postActions \
2050 -text {Post Creation Actions
} \
2052 checkbutton
$w.postActions.checkout \
2053 -text {Checkout after creation
} \
2054 -variable create_branch_checkout \
2056 pack
$w.postActions.checkout
-anchor nw
2057 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
2059 set create_branch_checkout
1
2060 set create_branch_head
$current_branch
2061 set create_branch_revtype
head
2062 set create_branch_name
$repo_config(gui.newbranchtemplate
)
2063 set create_branch_revexp
{}
2065 bind $w <Visibility
> "
2067 $w.desc.name_t icursor end
2068 focus $w.desc.name_t
2070 bind $w <Key-Escape
> "destroy $w"
2071 bind $w <Key-Return
> "do_create_branch_action $w;break"
2072 wm title
$w "[appname] ([reponame]): Create Branch"
2076 proc do_delete_branch_action
{w
} {
2078 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2081 switch
-- $delete_branch_checktype {
2082 head {set check_rev
$delete_branch_head}
2083 tracking
{set check_rev
$delete_branch_trackinghead}
2084 always
{set check_rev
{:none
}}
2086 if {$check_rev eq
{:none
}} {
2088 } elseif
{[catch
{set check_cmt
[exec git rev-parse
--verify "${check_rev}^0"]}]} {
2092 -title [wm title
$w] \
2094 -message "Invalid check revision: $check_rev"
2098 set to_delete
[list
]
2099 set not_merged
[list
]
2100 foreach i
[$w.list.l curselection
] {
2101 set b
[$w.list.l get
$i]
2102 if {[catch
{set o
[exec git rev-parse
--verify $b]}]} continue
2103 if {$check_cmt ne
{}} {
2104 if {$b eq
$check_rev} continue
2105 if {[catch
{set m
[exec git merge-base
$o $check_cmt]}]} continue
2107 lappend not_merged
$b
2111 lappend to_delete
[list
$b $o]
2113 if {$not_merged ne
{}} {
2114 set msg
"The following branches are not completely merged into $check_rev:
2116 - [join $not_merged "\n - "]"
2120 -title [wm title
$w] \
2124 if {$to_delete eq
{}} return
2125 if {$delete_branch_checktype eq
{always
}} {
2126 set msg
{Recovering deleted branches is difficult.
2128 Delete the selected branches?
}
2129 if {[tk_messageBox \
2132 -title [wm title
$w] \
2134 -message $msg] ne
yes} {
2140 foreach i
$to_delete {
2143 if {[catch
{exec git update-ref
-d "refs/heads/$b" $o} err
]} {
2144 append failed
" - $b: $err\n"
2146 set x
[lsearch
-sorted $all_heads $b]
2148 set all_heads
[lreplace
$all_heads $x $x]
2153 if {$failed ne
{}} {
2157 -title [wm title
$w] \
2159 -message "Failed to delete branches:\n$failed"
2162 set all_heads
[lsort
$all_heads]
2163 populate_branch_menu
2167 proc do_delete_branch
{} {
2168 global all_heads tracking_branches current_branch
2169 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2171 set w .branch_editor
2173 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2175 label
$w.header
-text {Delete Local Branch
} \
2177 pack
$w.header
-side top
-fill x
2180 button
$w.buttons.create
-text Delete \
2182 -command [list do_delete_branch_action
$w]
2183 pack
$w.buttons.create
-side right
2184 button
$w.buttons.cancel
-text {Cancel
} \
2186 -command [list destroy
$w]
2187 pack
$w.buttons.cancel
-side right
-padx 5
2188 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2190 labelframe
$w.list \
2191 -text {Local Branches
} \
2196 -selectmode extended \
2198 foreach h
$all_heads {
2199 if {$h ne
$current_branch} {
2200 $w.list.l insert end
$h
2203 pack
$w.list.l
-fill both
-pady 5 -padx 5
2204 pack
$w.list
-fill both
-pady 5 -padx 5
2206 labelframe
$w.validate \
2207 -text {Delete Only If
} \
2209 radiobutton
$w.validate.head_r \
2210 -text {Merged Into Local Branch
:} \
2212 -variable delete_branch_checktype \
2214 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2215 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2216 set all_trackings
[all_tracking_branches
]
2217 if {$all_trackings ne
{}} {
2218 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2219 radiobutton
$w.validate.tracking_r \
2220 -text {Merged Into Tracking Branch
:} \
2222 -variable delete_branch_checktype \
2224 eval tk_optionMenu
$w.validate.tracking_m \
2225 delete_branch_trackinghead \
2227 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2229 radiobutton
$w.validate.always_r \
2230 -text {Always
(Do not perform merge checks
)} \
2232 -variable delete_branch_checktype \
2234 grid
$w.validate.always_r
-columnspan 2 -sticky w
2235 grid columnconfigure
$w.validate
1 -weight 1
2236 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2238 set delete_branch_head
$current_branch
2239 set delete_branch_checktype
head
2241 bind $w <Visibility
> "grab $w; focus $w"
2242 bind $w <Key-Escape
> "destroy $w"
2243 wm title
$w "[appname] ([reponame]): Delete Branch"
2247 proc switch_branch
{new_branch
} {
2248 global HEAD commit_type current_branch repo_config
2250 if {![lock_index switch
]} return
2252 # -- Our in memory state should match the repository.
2254 repository_state curType curHEAD curMERGE_HEAD
2255 if {[string match amend
* $commit_type]
2256 && $curType eq
{normal
}
2257 && $curHEAD eq
$HEAD} {
2258 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2259 info_popup
{Last scanned state does not match repository state.
2261 Another Git program has modified this repository
2262 since the last scan. A rescan must be performed
2263 before the current branch can be changed.
2265 The rescan will be automatically started now.
2268 rescan
{set ui_status_value
{Ready.
}}
2272 if {$repo_config(gui.trustmtime
) eq
{true
}} {
2273 switch_branch_stage2
{} $new_branch
2275 set ui_status_value
{Refreshing
file status...
}
2276 set cmd
[list git update-index
]
2278 lappend cmd
--unmerged
2279 lappend cmd
--ignore-missing
2280 lappend cmd
--refresh
2281 set fd_rf
[open
"| $cmd" r
]
2282 fconfigure
$fd_rf -blocking 0 -translation binary
2283 fileevent
$fd_rf readable \
2284 [list switch_branch_stage2
$fd_rf $new_branch]
2288 proc switch_branch_stage2
{fd_rf new_branch
} {
2289 global ui_status_value HEAD
2293 if {![eof
$fd_rf]} return
2297 set ui_status_value
"Updating working directory to '$new_branch'..."
2298 set cmd
[list git read-tree
]
2301 lappend cmd
--exclude-per-directory=.gitignore
2303 lappend cmd
$new_branch
2304 set fd_rt
[open
"| $cmd" r
]
2305 fconfigure
$fd_rt -blocking 0 -translation binary
2306 fileevent
$fd_rt readable \
2307 [list switch_branch_readtree_wait
$fd_rt $new_branch]
2310 proc switch_branch_readtree_wait
{fd_rt new_branch
} {
2311 global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
2312 global current_branch
2313 global ui_comm ui_status_value
2315 # -- We never get interesting output on stdout; only stderr.
2318 fconfigure
$fd_rt -blocking 1
2319 if {![eof
$fd_rt]} {
2320 fconfigure
$fd_rt -blocking 0
2324 # -- The working directory wasn't in sync with the index and
2325 # we'd have to overwrite something to make the switch. A
2326 # merge is required.
2328 if {[catch
{close
$fd_rt} err
]} {
2329 regsub
{^fatal
: } $err {} err
2330 warn_popup
"File level merge required.
2334 Staying on branch '$current_branch'."
2335 set ui_status_value
"Aborted checkout of '$new_branch' (file level merging is required)."
2340 # -- Update the symbolic ref. Core git doesn't even check for failure
2341 # here, it Just Works(tm). If it doesn't we are in some really ugly
2342 # state that is difficult to recover from within git-gui.
2344 if {[catch
{exec git symbolic-ref HEAD
"refs/heads/$new_branch"} err
]} {
2345 error_popup
"Failed to set current branch.
2347 This working directory is only partially switched.
2348 We successfully updated your files, but failed to
2349 update an internal Git file.
2351 This should not have occurred. [appname] will now
2359 # -- Update our repository state. If we were previously in amend mode
2360 # we need to toss the current buffer and do a full rescan to update
2361 # our file lists. If we weren't in amend mode our file lists are
2362 # accurate and we can avoid the rescan.
2365 set selected_commit_type new
2366 if {[string match amend
* $commit_type]} {
2367 $ui_comm delete
0.0 end
2369 $ui_comm edit modified false
2370 rescan
{set ui_status_value
"Checked out branch '$current_branch'."}
2372 repository_state commit_type HEAD MERGE_HEAD
2374 set ui_status_value
"Checked out branch '$current_branch'."
2378 ######################################################################
2380 ## remote management
2382 proc load_all_remotes
{} {
2384 global all_remotes tracking_branches
2386 set all_remotes
[list
]
2387 array
unset tracking_branches
2389 set rm_dir
[gitdir remotes
]
2390 if {[file isdirectory
$rm_dir]} {
2391 set all_remotes
[glob \
2395 -directory $rm_dir *]
2397 foreach name
$all_remotes {
2399 set fd
[open
[file join $rm_dir $name] r
]
2400 while {[gets
$fd line
] >= 0} {
2401 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2402 $line line src dst
]} continue
2403 if {![regexp ^refs
/ $dst]} {
2404 set dst
"refs/heads/$dst"
2406 set tracking_branches
($dst) [list
$name $src]
2413 foreach line
[array names repo_config remote.
*.url
] {
2414 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2415 lappend all_remotes
$name
2417 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2421 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2422 if {![regexp ^refs
/ $dst]} {
2423 set dst
"refs/heads/$dst"
2425 set tracking_branches
($dst) [list
$name $src]
2429 set all_remotes
[lsort
-unique $all_remotes]
2432 proc populate_fetch_menu
{m
} {
2433 global all_remotes repo_config
2435 foreach r
$all_remotes {
2437 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2438 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2443 set fd
[open
[gitdir remotes
$r] r
]
2444 while {[gets
$fd n
] >= 0} {
2445 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2456 -label "Fetch from $r..." \
2457 -command [list fetch_from
$r] \
2463 proc populate_push_menu
{m
} {
2464 global all_remotes repo_config
2466 foreach r
$all_remotes {
2468 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2469 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2474 set fd
[open
[gitdir remotes
$r] r
]
2475 while {[gets
$fd n
] >= 0} {
2476 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2487 -label "Push to $r..." \
2488 -command [list push_to
$r] \
2494 proc populate_pull_menu
{m
} {
2495 global repo_config all_remotes disable_on_lock
2497 foreach remote
$all_remotes {
2499 if {[array get repo_config remote.
$remote.url
] ne
{}} {
2500 if {[array get repo_config remote.
$remote.fetch
] ne
{}} {
2501 foreach line
$repo_config(remote.
$remote.fetch
) {
2502 if {[regexp
{^
([^
:]+):} $line line rb
]} {
2509 set fd
[open
[gitdir remotes
$remote] r
]
2510 while {[gets
$fd line
] >= 0} {
2511 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $line line rb
]} {
2519 foreach rb
$rb_list {
2520 regsub ^refs
/heads
/ $rb {} rb_short
2522 -label "Branch $rb_short from $remote..." \
2523 -command [list pull_remote
$remote $rb] \
2525 lappend disable_on_lock \
2526 [list
$m entryconf
[$m index last
] -state]
2531 ######################################################################
2536 #define mask_width 14
2537 #define mask_height 15
2538 static unsigned char mask_bits
[] = {
2539 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2540 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2541 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2544 image create bitmap file_plain
-background white
-foreground black
-data {
2545 #define plain_width 14
2546 #define plain_height 15
2547 static unsigned char plain_bits
[] = {
2548 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2549 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2550 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2551 } -maskdata $filemask
2553 image create bitmap file_mod
-background white
-foreground blue
-data {
2554 #define mod_width 14
2555 #define mod_height 15
2556 static unsigned char mod_bits
[] = {
2557 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2558 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2559 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2560 } -maskdata $filemask
2562 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
2563 #define file_fulltick_width 14
2564 #define file_fulltick_height 15
2565 static unsigned char file_fulltick_bits
[] = {
2566 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2567 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2568 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2569 } -maskdata $filemask
2571 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
2572 #define parttick_width 14
2573 #define parttick_height 15
2574 static unsigned char parttick_bits
[] = {
2575 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2576 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2577 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2578 } -maskdata $filemask
2580 image create bitmap file_question
-background white
-foreground black
-data {
2581 #define file_question_width 14
2582 #define file_question_height 15
2583 static unsigned char file_question_bits
[] = {
2584 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2585 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2586 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2587 } -maskdata $filemask
2589 image create bitmap file_removed
-background white
-foreground red
-data {
2590 #define file_removed_width 14
2591 #define file_removed_height 15
2592 static unsigned char file_removed_bits
[] = {
2593 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2594 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2595 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2596 } -maskdata $filemask
2598 image create bitmap file_merge
-background white
-foreground blue
-data {
2599 #define file_merge_width 14
2600 #define file_merge_height 15
2601 static unsigned char file_merge_bits
[] = {
2602 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2603 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2604 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2605 } -maskdata $filemask
2607 set ui_index .vpane.files.index.list
2608 set ui_workdir .vpane.files.workdir.list
2610 set all_icons
(_
$ui_index) file_plain
2611 set all_icons
(A
$ui_index) file_fulltick
2612 set all_icons
(M
$ui_index) file_fulltick
2613 set all_icons
(D
$ui_index) file_removed
2614 set all_icons
(U
$ui_index) file_merge
2616 set all_icons
(_
$ui_workdir) file_plain
2617 set all_icons
(M
$ui_workdir) file_mod
2618 set all_icons
(D
$ui_workdir) file_question
2619 set all_icons
(U
$ui_workdir) file_merge
2620 set all_icons
(O
$ui_workdir) file_plain
2622 set max_status_desc
0
2626 {_M
"Modified, not staged"}
2627 {M_
"Staged for commit"}
2628 {MM
"Portions staged for commit"}
2629 {MD
"Staged for commit, missing"}
2631 {_O
"Untracked, not staged"}
2632 {A_
"Staged for commit"}
2633 {AM
"Portions staged for commit"}
2634 {AD
"Staged for commit, missing"}
2637 {D_
"Staged for removal"}
2638 {DO
"Staged for removal, still present"}
2640 {U_
"Requires merge resolution"}
2641 {UU
"Requires merge resolution"}
2642 {UM
"Requires merge resolution"}
2643 {UD
"Requires merge resolution"}
2645 if {$max_status_desc < [string length
[lindex
$i 1]]} {
2646 set max_status_desc
[string length
[lindex
$i 1]]
2648 set all_descs
([lindex
$i 0]) [lindex
$i 1]
2652 ######################################################################
2657 global tcl_platform tk_library
2658 if {[tk windowingsystem
] eq
{aqua
}} {
2664 proc is_Windows
{} {
2666 if {$tcl_platform(platform
) eq
{windows
}} {
2672 proc bind_button3
{w cmd
} {
2673 bind $w <Any-Button-3
> $cmd
2675 bind $w <Control-Button-1
> $cmd
2679 proc incr_font_size
{font
{amt
1}} {
2680 set sz
[font configure
$font -size]
2682 font configure
$font -size $sz
2683 font configure
${font}bold
-size $sz
2686 proc hook_failed_popup
{hook msg
} {
2691 label
$w.m.l1
-text "$hook hook failed:" \
2696 -background white
-borderwidth 1 \
2698 -width 80 -height 10 \
2700 -yscrollcommand [list
$w.m.sby
set]
2702 -text {You must correct the above errors before committing.
} \
2706 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2707 pack
$w.m.l1
-side top
-fill x
2708 pack
$w.m.l2
-side bottom
-fill x
2709 pack
$w.m.sby
-side right
-fill y
2710 pack
$w.m.t
-side left
-fill both
-expand 1
2711 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2713 $w.m.t insert
1.0 $msg
2714 $w.m.t conf
-state disabled
2716 button
$w.ok
-text OK \
2719 -command "destroy $w"
2720 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2722 bind $w <Visibility
> "grab $w; focus $w"
2723 bind $w <Key-Return
> "destroy $w"
2724 wm title
$w "[appname] ([reponame]): error"
2728 set next_console_id
0
2730 proc new_console
{short_title long_title
} {
2731 global next_console_id console_data
2732 set w .console
[incr next_console_id
]
2733 set console_data
($w) [list
$short_title $long_title]
2734 return [console_init
$w]
2737 proc console_init
{w
} {
2738 global console_cr console_data M1B
2740 set console_cr
($w) 1.0
2743 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
2748 -background white
-borderwidth 1 \
2750 -width 80 -height 10 \
2753 -yscrollcommand [list
$w.m.sby
set]
2754 label
$w.m.s
-text {Working... please
wait...
} \
2758 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2759 pack
$w.m.l1
-side top
-fill x
2760 pack
$w.m.s
-side bottom
-fill x
2761 pack
$w.m.sby
-side right
-fill y
2762 pack
$w.m.t
-side left
-fill both
-expand 1
2763 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2765 menu
$w.ctxm
-tearoff 0
2766 $w.ctxm add
command -label "Copy" \
2768 -command "tk_textCopy $w.m.t"
2769 $w.ctxm add
command -label "Select All" \
2771 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
2772 $w.ctxm add
command -label "Copy All" \
2775 $w.m.t tag add sel 0.0 end
2777 $w.m.t tag remove sel 0.0 end
2780 button
$w.ok
-text {Close
} \
2783 -command "destroy $w"
2784 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2786 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
2787 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
2788 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
2789 bind $w <Visibility
> "focus $w"
2790 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
2794 proc console_exec
{w cmd
{after
{}}} {
2795 # -- Windows tosses the enviroment when we exec our child.
2796 # But most users need that so we have to relogin. :-(
2799 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
2802 # -- Tcl won't let us redirect both stdout and stderr to
2803 # the same pipe. So pass it through cat...
2805 set cmd
[concat |
$cmd |
& cat]
2807 set fd_f
[open
$cmd r
]
2808 fconfigure
$fd_f -blocking 0 -translation binary
2809 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
2812 proc console_read
{w fd after
} {
2813 global console_cr console_data
2817 if {![winfo exists
$w]} {console_init
$w}
2818 $w.m.t conf
-state normal
2820 set n
[string length
$buf]
2822 set cr
[string first
"\r" $buf $c]
2823 set lf
[string first
"\n" $buf $c]
2824 if {$cr < 0} {set cr
[expr {$n + 1}]}
2825 if {$lf < 0} {set lf
[expr {$n + 1}]}
2828 $w.m.t insert end
[string range
$buf $c $lf]
2829 set console_cr
($w) [$w.m.t index
{end
-1c}]
2833 $w.m.t delete
$console_cr($w) end
2834 $w.m.t insert end
"\n"
2835 $w.m.t insert end
[string range
$buf $c $cr]
2840 $w.m.t conf
-state disabled
2844 fconfigure
$fd -blocking 1
2846 if {[catch
{close
$fd}]} {
2847 if {![winfo exists
$w]} {console_init
$w}
2848 $w.m.s conf
-background red
-text {Error
: Command Failed
}
2849 $w.ok conf
-state normal
2851 } elseif
{[winfo exists
$w]} {
2852 $w.m.s conf
-background green
-text {Success
}
2853 $w.ok conf
-state normal
2856 array
unset console_cr
$w
2857 array
unset console_data
$w
2859 uplevel
#0 $after $ok
2863 fconfigure
$fd -blocking 0
2866 ######################################################################
2870 set starting_gitk_msg
{Starting gitk... please
wait...
}
2872 proc do_gitk
{revs
} {
2873 global ui_status_value starting_gitk_msg
2881 set cmd
"sh -c \"exec $cmd\""
2885 if {[catch
{eval exec $cmd} err
]} {
2886 error_popup
"Failed to start gitk:\n\n$err"
2888 set ui_status_value
$starting_gitk_msg
2890 if {$ui_status_value eq
$starting_gitk_msg} {
2891 set ui_status_value
{Ready.
}
2898 set fd
[open
"| git count-objects -v" r
]
2899 while {[gets
$fd line
] > 0} {
2900 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
2901 set stats
($name) $value
2907 foreach p
[glob
-directory [gitdir objects pack
] \
2910 incr packed_sz
[file size
$p]
2912 if {$packed_sz > 0} {
2913 set stats
(size-pack
) [expr {$packed_sz / 1024}]
2918 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2920 label
$w.header
-text {Database Statistics
} \
2922 pack
$w.header
-side top
-fill x
2924 frame
$w.buttons
-border 1
2925 button
$w.buttons.close
-text Close \
2927 -command [list destroy
$w]
2928 button
$w.buttons.gc
-text {Compress Database
} \
2930 -command "destroy $w;do_gc"
2931 pack
$w.buttons.close
-side right
2932 pack
$w.buttons.gc
-side left
2933 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2935 frame
$w.stat
-borderwidth 1 -relief solid
2937 {count
{Number of loose objects
}}
2938 {size
{Disk space used by loose objects
} { KiB
}}
2939 {in-pack
{Number of packed objects
}}
2940 {packs
{Number of packs
}}
2941 {size-pack
{Disk space used by packed objects
} { KiB
}}
2942 {prune-packable
{Packed objects waiting
for pruning
}}
2943 {garbage
{Garbage files
}}
2945 set name
[lindex
$s 0]
2946 set label
[lindex
$s 1]
2947 if {[catch
{set value
$stats($name)}]} continue
2948 if {[llength
$s] > 2} {
2949 set value
"$value[lindex $s 2]"
2952 label
$w.stat.l_
$name -text "$label:" -anchor w
-font font_ui
2953 label
$w.stat.v_
$name -text $value -anchor w
-font font_ui
2954 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
2956 pack
$w.stat
-pady 10 -padx 10
2958 bind $w <Visibility
> "grab $w; focus $w"
2959 bind $w <Key-Escape
> [list destroy
$w]
2960 bind $w <Key-Return
> [list destroy
$w]
2961 wm title
$w "[appname] ([reponame]): Database Statistics"
2966 set w
[new_console
{gc
} {Compressing the object database
}]
2967 console_exec
$w {git gc
}
2970 proc do_fsck_objects
{} {
2971 set w
[new_console
{fsck-objects
} \
2972 {Verifying the object database with fsck-objects
}]
2973 set cmd
[list git fsck-objects
]
2976 lappend cmd
--strict
2977 console_exec
$w $cmd
2983 global ui_comm is_quitting repo_config commit_type
2985 if {$is_quitting} return
2988 # -- Stash our current commit buffer.
2990 set save
[gitdir GITGUI_MSG
]
2991 set msg
[string trim
[$ui_comm get
0.0 end
]]
2992 regsub
-all -line {[ \r\t]+$
} $msg {} msg
2993 if {(![string match amend
* $commit_type]
2994 ||
[$ui_comm edit modified
])
2997 set fd
[open
$save w
]
2998 puts
-nonewline $fd $msg
3002 catch
{file delete
$save}
3005 # -- Stash our current window geometry into this repository.
3007 set cfg_geometry
[list
]
3008 lappend cfg_geometry
[wm geometry .
]
3009 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
3010 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
3011 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
3014 if {$cfg_geometry ne
$rc_geometry} {
3015 catch
{exec git repo-config gui.geometry
$cfg_geometry}
3022 rescan
{set ui_status_value
{Ready.
}}
3025 proc unstage_helper
{txt paths
} {
3026 global file_states current_diff_path
3028 if {![lock_index begin-update
]} return
3032 foreach path
$paths {
3033 switch
-glob -- [lindex
$file_states($path) 0] {
3037 lappend pathList
$path
3038 if {$path eq
$current_diff_path} {
3039 set after
{reshow_diff
;}
3044 if {$pathList eq
{}} {
3050 [concat
$after {set ui_status_value
{Ready.
}}]
3054 proc do_unstage_selection
{} {
3055 global current_diff_path selected_paths
3057 if {[array size selected_paths
] > 0} {
3059 {Unstaging selected files from commit
} \
3060 [array names selected_paths
]
3061 } elseif
{$current_diff_path ne
{}} {
3063 "Unstaging [short_path $current_diff_path] from commit" \
3064 [list
$current_diff_path]
3068 proc add_helper
{txt paths
} {
3069 global file_states current_diff_path
3071 if {![lock_index begin-update
]} return
3075 foreach path
$paths {
3076 switch
-glob -- [lindex
$file_states($path) 0] {
3081 lappend pathList
$path
3082 if {$path eq
$current_diff_path} {
3083 set after
{reshow_diff
;}
3088 if {$pathList eq
{}} {
3094 [concat
$after {set ui_status_value
{Ready to commit.
}}]
3098 proc do_add_selection
{} {
3099 global current_diff_path selected_paths
3101 if {[array size selected_paths
] > 0} {
3103 {Adding selected files
} \
3104 [array names selected_paths
]
3105 } elseif
{$current_diff_path ne
{}} {
3107 "Adding [short_path $current_diff_path]" \
3108 [list
$current_diff_path]
3112 proc do_add_all
{} {
3116 foreach path
[array names file_states
] {
3117 switch
-glob -- [lindex
$file_states($path) 0] {
3120 ?D
{lappend paths
$path}
3123 add_helper
{Adding all changed files
} $paths
3126 proc revert_helper
{txt paths
} {
3127 global file_states current_diff_path
3129 if {![lock_index begin-update
]} return
3133 foreach path
$paths {
3134 switch
-glob -- [lindex
$file_states($path) 0] {
3138 lappend pathList
$path
3139 if {$path eq
$current_diff_path} {
3140 set after
{reshow_diff
;}
3146 set n
[llength
$pathList]
3150 } elseif
{$n == 1} {
3151 set s
"[short_path [lindex $pathList]]"
3153 set s
"these $n files"
3156 set reply
[tk_dialog \
3158 "[appname] ([reponame])" \
3159 "Revert changes in $s?
3161 Any unadded changes will be permanently lost by the revert." \
3171 [concat
$after {set ui_status_value
{Ready.
}}]
3177 proc do_revert_selection
{} {
3178 global current_diff_path selected_paths
3180 if {[array size selected_paths
] > 0} {
3182 {Reverting selected files
} \
3183 [array names selected_paths
]
3184 } elseif
{$current_diff_path ne
{}} {
3186 "Reverting [short_path $current_diff_path]" \
3187 [list
$current_diff_path]
3191 proc do_signoff
{} {
3194 set me
[committer_ident
]
3195 if {$me eq
{}} return
3197 set sob
"Signed-off-by: $me"
3198 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
3199 if {$last ne
$sob} {
3200 $ui_comm edit separator
3202 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
3203 $ui_comm insert end
"\n"
3205 $ui_comm insert end
"\n$sob"
3206 $ui_comm edit separator
3211 proc do_select_commit_type
{} {
3212 global commit_type selected_commit_type
3214 if {$selected_commit_type eq
{new
}
3215 && [string match amend
* $commit_type]} {
3217 } elseif
{$selected_commit_type eq
{amend
}
3218 && ![string match amend
* $commit_type]} {
3221 # The amend request was rejected...
3223 if {![string match amend
* $commit_type]} {
3224 set selected_commit_type new
3234 global appvers copyright
3235 global tcl_patchLevel tk_patchLevel
3239 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3241 label
$w.header
-text "About [appname]" \
3243 pack
$w.header
-side top
-fill x
3246 button
$w.buttons.close
-text {Close
} \
3248 -command [list destroy
$w]
3249 pack
$w.buttons.close
-side right
3250 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3253 -text "[appname] - a commit creation tool for Git.
3261 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
3264 append v
"[appname] version $appvers\n"
3265 append v
"[exec git version]\n"
3267 if {$tcl_patchLevel eq
$tk_patchLevel} {
3268 append v
"Tcl/Tk version $tcl_patchLevel"
3270 append v
"Tcl version $tcl_patchLevel"
3271 append v
", Tk version $tk_patchLevel"
3282 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
3284 menu
$w.ctxm
-tearoff 0
3285 $w.ctxm add
command \
3290 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
3293 bind $w <Visibility
> "grab $w; focus $w"
3294 bind $w <Key-Escape
> "destroy $w"
3295 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
3296 wm title
$w "About [appname]"
3300 proc do_options
{} {
3301 global repo_config global_config font_descs
3302 global repo_config_new global_config_new
3304 array
unset repo_config_new
3305 array
unset global_config_new
3306 foreach name
[array names repo_config
] {
3307 set repo_config_new
($name) $repo_config($name)
3310 foreach name
[array names repo_config
] {
3312 gui.diffcontext
{continue}
3314 set repo_config_new
($name) $repo_config($name)
3316 foreach name
[array names global_config
] {
3317 set global_config_new
($name) $global_config($name)
3320 set w .options_editor
3322 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3324 label
$w.header
-text "[appname] Options" \
3326 pack
$w.header
-side top
-fill x
3329 button
$w.buttons.restore
-text {Restore Defaults
} \
3331 -command do_restore_defaults
3332 pack
$w.buttons.restore
-side left
3333 button
$w.buttons.save
-text Save \
3335 -command [list do_save_config
$w]
3336 pack
$w.buttons.save
-side right
3337 button
$w.buttons.cancel
-text {Cancel
} \
3339 -command [list destroy
$w]
3340 pack
$w.buttons.cancel
-side right
-padx 5
3341 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3343 labelframe
$w.repo
-text "[reponame] Repository" \
3345 labelframe
$w.global
-text {Global
(All Repositories
)} \
3347 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
3348 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
3351 {b pullsummary
{Show Pull Summary
}}
3352 {b trustmtime
{Trust File Modification Timestamps
}}
3353 {i diffcontext
{Number of Diff Context Lines
}}
3354 {t newbranchtemplate
{New Branch Name Template
}}
3356 set type [lindex
$option 0]
3357 set name
[lindex
$option 1]
3358 set text
[lindex
$option 2]
3359 foreach f
{repo global
} {
3362 checkbutton
$w.
$f.
$name -text $text \
3363 -variable ${f}_config_new
(gui.
$name) \
3367 pack
$w.
$f.
$name -side top
-anchor w
3371 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3372 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
3373 spinbox
$w.
$f.
$name.v \
3374 -textvariable ${f}_config_new
(gui.
$name) \
3375 -from 1 -to 99 -increment 1 \
3378 bind $w.
$f.
$name.v
<FocusIn
> {%W selection range
0 end
}
3379 pack
$w.
$f.
$name.v
-side right
-anchor e
-padx 5
3380 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3384 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3385 entry
$w.
$f.
$name.v \
3389 -textvariable ${f}_config_new
(gui.
$name) \
3391 pack
$w.
$f.
$name.l
-side left
-anchor w
3392 pack
$w.
$f.
$name.v
-side left
-anchor w \
3395 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3401 set all_fonts
[lsort
[font families
]]
3402 foreach option
$font_descs {
3403 set name
[lindex
$option 0]
3404 set font
[lindex
$option 1]
3405 set text
[lindex
$option 2]
3407 set global_config_new
(gui.
$font^^family
) \
3408 [font configure
$font -family]
3409 set global_config_new
(gui.
$font^^size
) \
3410 [font configure
$font -size]
3412 frame
$w.global.
$name
3413 label
$w.global.
$name.l
-text "$text:" -font font_ui
3414 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
3415 eval tk_optionMenu
$w.global.
$name.family \
3416 global_config_new
(gui.
$font^^family
) \
3418 spinbox
$w.global.
$name.size \
3419 -textvariable global_config_new
(gui.
$font^^size
) \
3420 -from 2 -to 80 -increment 1 \
3423 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
3424 pack
$w.global.
$name.size
-side right
-anchor e
3425 pack
$w.global.
$name.family
-side right
-anchor e
3426 pack
$w.global.
$name -side top
-anchor w
-fill x
3429 bind $w <Visibility
> "grab $w; focus $w"
3430 bind $w <Key-Escape
> "destroy $w"
3431 wm title
$w "[appname] ([reponame]): Options"
3435 proc do_restore_defaults
{} {
3436 global font_descs default_config repo_config
3437 global repo_config_new global_config_new
3439 foreach name
[array names default_config
] {
3440 set repo_config_new
($name) $default_config($name)
3441 set global_config_new
($name) $default_config($name)
3444 foreach option
$font_descs {
3445 set name
[lindex
$option 0]
3446 set repo_config
(gui.
$name) $default_config(gui.
$name)
3450 foreach option
$font_descs {
3451 set name
[lindex
$option 0]
3452 set font
[lindex
$option 1]
3453 set global_config_new
(gui.
$font^^family
) \
3454 [font configure
$font -family]
3455 set global_config_new
(gui.
$font^^size
) \
3456 [font configure
$font -size]
3460 proc do_save_config
{w
} {
3461 if {[catch
{save_config
} err
]} {
3462 error_popup
"Failed to completely save options:\n\n$err"
3468 proc do_windows_shortcut
{} {
3472 set desktop
[exec cygpath \
3480 set fn
[tk_getSaveFile \
3482 -title "[appname] ([reponame]): Create Desktop Icon" \
3483 -initialdir $desktop \
3484 -initialfile "Git [reponame].bat"]
3488 set sh
[exec cygpath \
3492 set me
[exec cygpath \
3496 set gd
[exec cygpath \
3500 set gw
[exec cygpath \
3503 [file dirname [gitdir
]]]
3504 regsub
-all ' $me "'\\''" me
3505 regsub -all ' $gd "'\\''" gd
3506 puts $fd "@ECHO Entering $gw"
3507 puts $fd "@ECHO Starting git-gui... please wait..."
3508 puts -nonewline $fd "@\"$sh\" --login -c \""
3509 puts -nonewline $fd "GIT_DIR='$gd'"
3510 puts -nonewline $fd " '$me'"
3514 error_popup "Cannot write script:\n\n$err"
3519 proc do_macosx_app {} {
3522 set fn [tk_getSaveFile \
3524 -title "[appname] ([reponame]): Create Desktop Icon" \
3525 -initialdir [file join $env(HOME) Desktop] \
3526 -initialfile "Git [reponame].app"]
3529 set Contents [file join $fn Contents]
3530 set MacOS [file join $Contents MacOS]
3531 set exe [file join $MacOS git-gui]
3535 set fd [open [file join $Contents Info.plist] w]
3536 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3537 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3538 <plist version="1.0">
3540 <key>CFBundleDevelopmentRegion</key>
3541 <string>English</string>
3542 <key>CFBundleExecutable</key>
3543 <string>git-gui</string>
3544 <key>CFBundleIdentifier</key>
3545 <string>org.spearce.git-gui</string>
3546 <key>CFBundleInfoDictionaryVersion</key>
3547 <string>6.0</string>
3548 <key>CFBundlePackageType</key>
3549 <string>APPL</string>
3550 <key>CFBundleSignature</key>
3551 <string>????</string>
3552 <key>CFBundleVersion</key>
3553 <string>1.0</string>
3554 <key>NSPrincipalClass</key>
3555 <string>NSApplication</string>
3560 set fd [open $exe w]
3561 set gd [file normalize [gitdir]]
3562 set ep [file normalize [exec git --exec-path]]
3563 regsub -all ' $gd "'\\''" gd
3564 regsub
-all ' $ep "'\\''" ep
3565 puts $fd "#!/bin/sh"
3566 foreach name
[array names env
] {
3567 if {[string match GIT_
* $name]} {
3568 regsub
-all ' $env($name) "'\\''" v
3569 puts $fd "export $name='$v'"
3572 puts $fd "export PATH
='$ep':\
$PATH"
3573 puts $fd "export GIT_DIR
='$gd'"
3574 puts $fd "exec [file normalize
$argv0]"
3577 file attributes $exe -permissions u+x,g+x,o+x
3579 error_popup "Cannot
write icon
:\n\n$err"
3584 proc toggle_or_diff {w x y} {
3585 global file_states file_lists current_diff_path ui_index ui_workdir
3586 global last_clicked selected_paths
3588 set pos [split [$w index @$x,$y] .]
3589 set lno [lindex $pos 0]
3590 set col [lindex $pos 1]
3591 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3597 set last_clicked [list $w $lno]
3598 array unset selected_paths
3599 $ui_index tag remove in_sel 0.0 end
3600 $ui_workdir tag remove in_sel 0.0 end
3603 if {$current_diff_path eq $path} {
3604 set after {reshow_diff;}
3608 if {$w eq $ui_index} {
3610 "Unstaging
[short_path
$path] from commit
" \
3612 [concat $after {set ui_status_value {Ready.}}]
3613 } elseif {$w eq $ui_workdir} {
3615 "Adding
[short_path
$path]" \
3617 [concat $after {set ui_status_value {Ready.}}]
3620 show_diff $path $w $lno
3624 proc add_one_to_selection {w x y} {
3625 global file_lists last_clicked selected_paths
3627 set lno [lindex [split [$w index @$x,$y] .] 0]
3628 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3634 if {$last_clicked ne {}
3635 && [lindex $last_clicked 0] ne $w} {
3636 array unset selected_paths
3637 [lindex $last_clicked 0] tag remove in_sel 0.0 end
3640 set last_clicked [list $w $lno]
3641 if {[catch {set in_sel $selected_paths($path)}]} {
3645 unset selected_paths($path)
3646 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
3648 set selected_paths($path) 1
3649 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3653 proc add_range_to_selection {w x y} {
3654 global file_lists last_clicked selected_paths
3656 if {[lindex $last_clicked 0] ne $w} {
3657 toggle_or_diff $w $x $y
3661 set lno [lindex [split [$w index @$x,$y] .] 0]
3662 set lc [lindex $last_clicked 1]
3671 foreach path [lrange $file_lists($w) \
3672 [expr {$begin - 1}] \
3673 [expr {$end - 1}]] {
3674 set selected_paths($path) 1
3676 $w tag add in_sel $begin.0 [expr {$end + 1}].0
3679 ######################################################################
3683 set cursor_ptr arrow
3684 font create font_diff -family Courier -size 10
3688 eval font configure font_ui [font actual [.dummy cget -font]]
3692 font create font_uibold
3693 font create font_diffbold
3698 } elseif {[is_MacOSX]} {
3706 proc apply_config {} {
3707 global repo_config font_descs
3709 foreach option $font_descs {
3710 set name [lindex $option 0]
3711 set font [lindex $option 1]
3713 foreach {cn cv} $repo_config(gui.$name) {
3714 font configure $font $cn $cv
3717 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
3719 foreach {cn cv} [font configure $font] {
3720 font configure ${font}bold $cn $cv
3722 font configure ${font}bold -weight bold
3726 set default_config(gui.trustmtime) false
3727 set default_config(gui.pullsummary) true
3728 set default_config(gui.diffcontext) 5
3729 set default_config(gui.newbranchtemplate) {}
3730 set default_config(gui.fontui) [font configure font_ui]
3731 set default_config(gui.fontdiff) [font configure font_diff]
3733 {fontui font_ui {Main Font}}
3734 {fontdiff font_diff {Diff/Console Font}}
3739 ######################################################################
3745 menu .mbar -tearoff 0
3746 .mbar add cascade -label Repository -menu .mbar.repository
3747 .mbar add cascade -label Edit -menu .mbar.edit
3748 if {!$single_commit} {
3749 .mbar add cascade -label Branch -menu .mbar.branch
3751 .mbar add cascade -label Commit -menu .mbar.commit
3752 if {!$single_commit} {
3753 .mbar add cascade -label Fetch -menu .mbar.fetch
3754 .mbar add cascade -label Pull -menu .mbar.pull
3755 .mbar add cascade -label Push -menu .mbar.push
3757 . configure -menu .mbar
3759 # -- Repository Menu
3761 menu .mbar.repository
3762 .mbar.repository add command \
3763 -label {Visualize Current Branch} \
3764 -command {do_gitk {}} \
3766 .mbar.repository add command \
3767 -label {Visualize All Branches} \
3768 -command {do_gitk {--all}} \
3770 .mbar.repository add separator
3772 if {!$single_commit} {
3773 .mbar.repository add command -label {Database Statistics} \
3777 .mbar.repository add command -label {Compress Database} \
3781 .mbar.repository add command -label {Verify Database} \
3782 -command do_fsck_objects \
3785 .mbar.repository add separator
3788 .mbar.repository add command \
3789 -label {Create Desktop Icon} \
3790 -command do_windows_shortcut \
3792 } elseif {[is_MacOSX]} {
3793 .mbar.repository add command \
3794 -label {Create Desktop Icon} \
3795 -command do_macosx_app \
3800 .mbar.repository add command -label Quit \
3802 -accelerator $M1T-Q \
3808 .mbar.edit add command -label Undo \
3809 -command {catch {[focus] edit undo}} \
3810 -accelerator $M1T-Z \
3812 .mbar.edit add command -label Redo \
3813 -command {catch {[focus] edit redo}} \
3814 -accelerator $M1T-Y \
3816 .mbar.edit add separator
3817 .mbar.edit add command -label Cut \
3818 -command {catch {tk_textCut [focus]}} \
3819 -accelerator $M1T-X \
3821 .mbar.edit add command -label Copy \
3822 -command {catch {tk_textCopy [focus]}} \
3823 -accelerator $M1T-C \
3825 .mbar.edit add command -label Paste \
3826 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
3827 -accelerator $M1T-V \
3829 .mbar.edit add command -label Delete \
3830 -command {catch {[focus] delete sel.first sel.last}} \
3833 .mbar.edit add separator
3834 .mbar.edit add command -label {Select All} \
3835 -command {catch {[focus] tag add sel 0.0 end}} \
3836 -accelerator $M1T-A \
3841 if {!$single_commit} {
3844 .mbar.branch add command -label {Create...} \
3845 -command do_create_branch \
3846 -accelerator $M1T-N \
3848 lappend disable_on_lock [list .mbar.branch entryconf \
3849 [.mbar.branch index last] -state]
3851 .mbar.branch add command -label {Delete...} \
3852 -command do_delete_branch \
3854 lappend disable_on_lock [list .mbar.branch entryconf \
3855 [.mbar.branch index last] -state]
3862 .mbar.commit add radiobutton \
3863 -label {New Commit} \
3864 -command do_select_commit_type \
3865 -variable selected_commit_type \
3868 lappend disable_on_lock \
3869 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3871 .mbar.commit add radiobutton \
3872 -label {Amend Last Commit} \
3873 -command do_select_commit_type \
3874 -variable selected_commit_type \
3877 lappend disable_on_lock \
3878 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3880 .mbar.commit add separator
3882 .mbar.commit add command -label Rescan \
3883 -command do_rescan \
3886 lappend disable_on_lock \
3887 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3889 .mbar.commit add command -label {Add To Commit} \
3890 -command do_add_selection \
3892 lappend disable_on_lock \
3893 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3895 .mbar.commit add command -label {Add All To Commit} \
3896 -command do_add_all \
3897 -accelerator $M1T-I \
3899 lappend disable_on_lock \
3900 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3902 .mbar.commit add command -label {Unstage From Commit} \
3903 -command do_unstage_selection \
3905 lappend disable_on_lock \
3906 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3908 .mbar.commit add command -label {Revert Changes} \
3909 -command do_revert_selection \
3911 lappend disable_on_lock \
3912 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3914 .mbar.commit add separator
3916 .mbar.commit add command -label {Sign Off} \
3917 -command do_signoff \
3918 -accelerator $M1T-S \
3921 .mbar.commit add command -label Commit \
3922 -command do_commit \
3923 -accelerator $M1T-Return \
3925 lappend disable_on_lock \
3926 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3928 # -- Transport menus
3930 if {!$single_commit} {
3937 # -- Apple Menu (Mac OS X only)
3939 .mbar add cascade -label Apple -menu .mbar.apple
3942 .mbar.apple add command -label "About
[appname
]" \
3945 .mbar.apple add command -label "[appname
] Options...
" \
3946 -command do_options \
3951 .mbar.edit add separator
3952 .mbar.edit add command -label {Options...} \
3953 -command do_options \
3958 if {[file exists /usr/local/miga/lib/gui-miga]
3959 && [file exists .pvcsrc]} {
3961 global ui_status_value
3962 if {![lock_index update]} return
3963 set cmd [list sh --login -c "/usr
/local
/miga
/lib
/gui-miga
\"[pwd]\""]
3964 set miga_fd [open "|
$cmd" r]
3965 fconfigure $miga_fd -blocking 0
3966 fileevent $miga_fd readable [list miga_done $miga_fd]
3967 set ui_status_value {Running miga...}
3969 proc miga_done {fd} {
3974 rescan [list set ui_status_value {Ready.}]
3977 .mbar add cascade -label Tools -menu .mbar.tools
3979 .mbar.tools add command -label "Migrate
" \
3982 lappend disable_on_lock \
3983 [list .mbar.tools entryconf [.mbar.tools index last] -state]
3988 .mbar add cascade -label Help -menu .mbar.help
3991 .mbar.help add command -label "About
[appname
]" \
4003 -text {Current Branch:} \
4008 -textvariable current_branch \
4012 pack .branch.l1 -side left
4013 pack .branch.cb -side left -fill x
4014 pack .branch -side top -fill x
4016 # -- Main Window Layout
4018 panedwindow .vpane -orient vertical
4019 panedwindow .vpane.files -orient horizontal
4020 .vpane add .vpane.files -sticky nsew -height 100 -width 200
4021 pack .vpane -anchor n -side top -fill both -expand 1
4023 # -- Index File List
4025 frame .vpane.files.index -height 100 -width 200
4026 label .vpane.files.index.title -text {Changes To Be Committed} \
4029 text $ui_index -background white -borderwidth 0 \
4030 -width 20 -height 10 \
4033 -cursor $cursor_ptr \
4034 -xscrollcommand {.vpane.files.index.sx set} \
4035 -yscrollcommand {.vpane.files.index.sy set} \
4037 scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
4038 scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
4039 pack .vpane.files.index.title -side top -fill x
4040 pack .vpane.files.index.sx -side bottom -fill x
4041 pack .vpane.files.index.sy -side right -fill y
4042 pack $ui_index -side left -fill both -expand 1
4043 .vpane.files add .vpane.files.index -sticky nsew
4045 # -- Working Directory File List
4047 frame .vpane.files.workdir -height 100 -width 200
4048 label .vpane.files.workdir.title -text {Changed But Not Updated} \
4051 text $ui_workdir -background white -borderwidth 0 \
4052 -width 20 -height 10 \
4055 -cursor $cursor_ptr \
4056 -xscrollcommand {.vpane.files.workdir.sx set} \
4057 -yscrollcommand {.vpane.files.workdir.sy set} \
4059 scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
4060 scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
4061 pack .vpane.files.workdir.title -side top -fill x
4062 pack .vpane.files.workdir.sx -side bottom -fill x
4063 pack .vpane.files.workdir.sy -side right -fill y
4064 pack $ui_workdir -side left -fill both -expand 1
4065 .vpane.files add .vpane.files.workdir -sticky nsew
4067 foreach i [list $ui_index $ui_workdir] {
4068 $i tag conf in_diff -font font_uibold
4069 $i tag conf in_sel \
4070 -background [$i cget -foreground] \
4071 -foreground [$i cget -background]
4075 # -- Diff and Commit Area
4077 frame .vpane.lower -height 300 -width 400
4078 frame .vpane.lower.commarea
4079 frame .vpane.lower.diff -relief sunken -borderwidth 1
4080 pack .vpane.lower.commarea -side top -fill x
4081 pack .vpane.lower.diff -side bottom -fill both -expand 1
4082 .vpane add .vpane.lower -sticky nsew
4084 # -- Commit Area Buttons
4086 frame .vpane.lower.commarea.buttons
4087 label .vpane.lower.commarea.buttons.l -text {} \
4091 pack .vpane.lower.commarea.buttons.l -side top -fill x
4092 pack .vpane.lower.commarea.buttons -side left -fill y
4094 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
4095 -command do_rescan \
4097 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
4098 lappend disable_on_lock \
4099 {.vpane.lower.commarea.buttons.rescan conf -state}
4101 button .vpane.lower.commarea.buttons.incall -text {Add All} \
4102 -command do_add_all \
4104 pack .vpane.lower.commarea.buttons.incall -side top -fill x
4105 lappend disable_on_lock \
4106 {.vpane.lower.commarea.buttons.incall conf -state}
4108 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
4109 -command do_signoff \
4111 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
4113 button .vpane.lower.commarea.buttons.commit -text {Commit} \
4114 -command do_commit \
4116 pack .vpane.lower.commarea.buttons.commit -side top -fill x
4117 lappend disable_on_lock \
4118 {.vpane.lower.commarea.buttons.commit conf -state}
4120 # -- Commit Message Buffer
4122 frame .vpane.lower.commarea.buffer
4123 frame .vpane.lower.commarea.buffer.header
4124 set ui_comm .vpane.lower.commarea.buffer.t
4125 set ui_coml .vpane.lower.commarea.buffer.header.l
4126 radiobutton .vpane.lower.commarea.buffer.header.new \
4127 -text {New Commit} \
4128 -command do_select_commit_type \
4129 -variable selected_commit_type \
4132 lappend disable_on_lock \
4133 [list .vpane.lower.commarea.buffer.header.new conf -state]
4134 radiobutton .vpane.lower.commarea.buffer.header.amend \
4135 -text {Amend Last Commit} \
4136 -command do_select_commit_type \
4137 -variable selected_commit_type \
4140 lappend disable_on_lock \
4141 [list .vpane.lower.commarea.buffer.header.amend conf -state]
4146 proc trace_commit_type {varname args} {
4147 global ui_coml commit_type
4148 switch -glob -- $commit_type {
4149 initial {set txt {Initial Commit Message:}}
4150 amend {set txt {Amended Commit Message:}}
4151 amend-initial {set txt {Amended Initial Commit Message:}}
4152 amend-merge {set txt {Amended Merge Commit Message:}}
4153 merge {set txt {Merge Commit Message:}}
4154 * {set txt {Commit Message:}}
4156 $ui_coml conf -text $txt
4158 trace add variable commit_type write trace_commit_type
4159 pack $ui_coml -side left -fill x
4160 pack .vpane.lower.commarea.buffer.header.amend -side right
4161 pack .vpane.lower.commarea.buffer.header.new -side right
4163 text $ui_comm -background white -borderwidth 1 \
4166 -autoseparators true \
4168 -width 75 -height 9 -wrap none \
4170 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
4171 scrollbar .vpane.lower.commarea.buffer.sby \
4172 -command [list $ui_comm yview]
4173 pack .vpane.lower.commarea.buffer.header -side top -fill x
4174 pack .vpane.lower.commarea.buffer.sby -side right -fill y
4175 pack $ui_comm -side left -fill y
4176 pack .vpane.lower.commarea.buffer -side left -fill y
4178 # -- Commit Message Buffer Context Menu
4180 set ctxm .vpane.lower.commarea.buffer.ctxm
4181 menu $ctxm -tearoff 0
4185 -command {tk_textCut $ui_comm}
4189 -command {tk_textCopy $ui_comm}
4193 -command {tk_textPaste $ui_comm}
4197 -command {$ui_comm delete sel.first sel.last}
4200 -label {Select All} \
4202 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
4207 $ui_comm tag add sel 0.0 end
4208 tk_textCopy $ui_comm
4209 $ui_comm tag remove sel 0.0 end
4216 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
4220 set current_diff_path {}
4221 set current_diff_side {}
4222 set diff_actions [list]
4223 proc trace_current_diff_path {varname args} {
4224 global current_diff_path diff_actions file_states
4225 if {$current_diff_path eq {}} {
4231 set p $current_diff_path
4232 set s [mapdesc [lindex $file_states($p) 0] $p]
4234 set p [escape_path $p]
4238 .vpane.lower.diff.header.status configure -text $s
4239 .vpane.lower.diff.header.file configure -text $f
4240 .vpane.lower.diff.header.path configure -text $p
4241 foreach w $diff_actions {
4245 trace add variable current_diff_path write trace_current_diff_path
4247 frame .vpane.lower.diff.header -background orange
4248 label .vpane.lower.diff.header.status \
4249 -background orange \
4250 -width $max_status_desc \
4254 label .vpane.lower.diff.header.file \
4255 -background orange \
4259 label .vpane.lower.diff.header.path \
4260 -background orange \
4264 pack .vpane.lower.diff.header.status -side left
4265 pack .vpane.lower.diff.header.file -side left
4266 pack .vpane.lower.diff.header.path -fill x
4267 set ctxm .vpane.lower.diff.header.ctxm
4268 menu $ctxm -tearoff 0
4277 -- $current_diff_path
4279 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4280 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
4284 frame .vpane.lower.diff.body
4285 set ui_diff .vpane.lower.diff.body.t
4286 text $ui_diff -background white -borderwidth 0 \
4287 -width 80 -height 15 -wrap none \
4289 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
4290 -yscrollcommand {.vpane.lower.diff.body.sby set} \
4292 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
4293 -command [list $ui_diff xview]
4294 scrollbar .vpane.lower.diff.body.sby -orient vertical \
4295 -command [list $ui_diff yview]
4296 pack .vpane.lower.diff.body.sbx -side bottom -fill x
4297 pack .vpane.lower.diff.body.sby -side right -fill y
4298 pack $ui_diff -side left -fill both -expand 1
4299 pack .vpane.lower.diff.header -side top -fill x
4300 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
4302 $ui_diff tag conf d_cr -elide true
4303 $ui_diff tag conf d_@ -foreground blue -font font_diffbold
4304 $ui_diff tag conf d_+ -foreground {#00a000}
4305 $ui_diff tag conf d_- -foreground red
4307 $ui_diff tag conf d_++ -foreground {#00a000}
4308 $ui_diff tag conf d_-- -foreground red
4309 $ui_diff tag conf d_+s \
4310 -foreground {#00a000} \
4311 -background {#e2effa}
4312 $ui_diff tag conf d_-s \
4314 -background {#e2effa}
4315 $ui_diff tag conf d_s+ \
4316 -foreground {#00a000} \
4318 $ui_diff tag conf d_s- \
4322 $ui_diff tag conf d<<<<<<< \
4323 -foreground orange \
4325 $ui_diff tag conf d======= \
4326 -foreground orange \
4328 $ui_diff tag conf d>>>>>>> \
4329 -foreground orange \
4332 $ui_diff tag raise sel
4334 # -- Diff Body Context Menu
4336 set ctxm .vpane.lower.diff.body.ctxm
4337 menu $ctxm -tearoff 0
4341 -command reshow_diff
4342 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4346 -command {tk_textCopy $ui_diff}
4347 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4349 -label {Select All} \
4351 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
4352 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4357 $ui_diff tag add sel 0.0 end
4358 tk_textCopy $ui_diff
4359 $ui_diff tag remove sel 0.0 end
4361 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4364 -label {Apply/Reverse Hunk} \
4366 -command {apply_hunk $cursorX $cursorY}
4367 set ui_diff_applyhunk [$ctxm index last]
4368 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
4371 -label {Decrease Font Size} \
4373 -command {incr_font_size font_diff -1}
4374 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4376 -label {Increase Font Size} \
4378 -command {incr_font_size font_diff 1}
4379 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4382 -label {Show Less Context} \
4384 -command {if {$repo_config(gui.diffcontext) >= 2} {
4385 incr repo_config(gui.diffcontext) -1
4388 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4390 -label {Show More Context} \
4393 incr repo_config(gui.diffcontext)
4396 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4398 $ctxm add command -label {Options...} \
4401 bind_button3 $ui_diff "
4404 if {\
$ui_index eq \
$current_diff_side} {
4405 $ctxm entryconf
$ui_diff_applyhunk -label {Unstage Hunk From Commit
}
4407 $ctxm entryconf
$ui_diff_applyhunk -label {Stage Hunk For Commit
}
4409 tk_popup
$ctxm %X
%Y
4411 unset ui_diff_applyhunk
4415 set ui_status_value {Initializing...}
4416 label .status -textvariable ui_status_value \
4422 pack .status -anchor w -side bottom -fill x
4427 set gm $repo_config(gui.geometry)
4428 wm geometry . [lindex $gm 0]
4429 .vpane sash place 0 \
4430 [lindex [.vpane sash coord 0] 0] \
4432 .vpane.files sash place 0 \
4434 [lindex [.vpane.files sash coord 0] 1]
4440 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
4441 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
4442 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
4443 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
4444 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
4445 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
4446 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
4447 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
4448 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
4449 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4450 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4452 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
4453 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
4454 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
4455 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
4456 bind $ui_diff <$M1B-Key-v> {break}
4457 bind $ui_diff <$M1B-Key-V> {break}
4458 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4459 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4460 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
4461 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
4462 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
4463 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
4464 bind $ui_diff <Button-1> {focus %W}
4466 if {!$single_commit} {
4467 bind . <$M1B-Key-n> do_create_branch
4468 bind . <$M1B-Key-N> do_create_branch
4471 bind . <Destroy> do_quit
4472 bind all <Key-F5> do_rescan
4473 bind all <$M1B-Key-r> do_rescan
4474 bind all <$M1B-Key-R> do_rescan
4475 bind . <$M1B-Key-s> do_signoff
4476 bind . <$M1B-Key-S> do_signoff
4477 bind . <$M1B-Key-i> do_add_all
4478 bind . <$M1B-Key-I> do_add_all
4479 bind . <$M1B-Key-Return> do_commit
4480 bind all <$M1B-Key-q> do_quit
4481 bind all <$M1B-Key-Q> do_quit
4482 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
4483 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
4484 foreach i [list $ui_index $ui_workdir] {
4485 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
4486 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
4487 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
4491 set file_lists($ui_index) [list]
4492 set file_lists($ui_workdir) [list]
4496 set MERGE_HEAD [list]
4499 set current_branch {}
4500 set current_diff_path {}
4501 set selected_commit_type new
4503 wm title . "[appname
] ([file normalize
[file dirname [gitdir
]]])"
4504 focus -force $ui_comm
4506 # -- Warn the user about environmental problems. Cygwin's Tcl
4507 # does *not* pass its env array onto any processes it spawns.
4508 # This means that git processes get none of our environment.
4513 set msg "Possible environment issues exist.
4515 The following environment variables are probably
4516 going to be ignored by any Git subprocess run
4520 foreach name [array names env] {
4521 switch -regexp -- $name {
4522 {^GIT_INDEX_FILE$} -
4523 {^GIT_OBJECT_DIRECTORY$} -
4524 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4526 {^GIT_EXTERNAL_DIFF$} -
4530 {^GIT_CONFIG_LOCAL$} -
4531 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4532 append msg " - $name\n"
4535 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4536 append msg " - $name\n"
4538 set suggest_user $name
4542 if {$ignored_env > 0} {
4544 This is due to a known issue with the
4545 Tcl binary distributed by Cygwin.
"
4547 if {$suggest_user ne {}} {
4550 A good replacement
for $suggest_user
4551 is placing values
for the user.name and
4552 user.email settings into your personal
4558 unset ignored_env msg suggest_user name
4561 # -- Only initialize complex UI if we are going to stay running.
4563 if {!$single_commit} {
4567 populate_branch_menu
4568 populate_fetch_menu .mbar.fetch
4569 populate_pull_menu .mbar.pull
4570 populate_push_menu .mbar.push
4573 # -- Only suggest a gc run if we are going to stay running.
4575 if {!$single_commit} {
4576 set object_limit 2000
4577 if {[is_Windows]} {set object_limit 200}
4578 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
4579 if {$objects_current >= $object_limit} {
4581 "This repository currently has
$objects_current loose objects.
4583 To maintain optimal performance it is strongly
4584 recommended that you
compress the database
4585 when
more than
$object_limit loose objects exist.
4587 Compress the database now?
"] eq yes} {
4591 unset object_limit _junk objects_current
4594 lock_index begin-read