2 # Tcl ignores the next line -*- tcl -*- \
6 Copyright ©
2006 Shawn Pearce
, Paul Mackerras.
10 This program is free software
; it may be used
, copied
, modified
11 and distributed under the terms of the GNU General Public Licence
,
12 either version
2, or
(at your option
) any later version.
}
14 set appname
[lindex
[file split $argv0] end
]
17 ######################################################################
21 proc is_many_config
{name
} {
22 switch
-glob -- $name {
31 proc load_config
{include_global
} {
32 global repo_config global_config default_config
34 array
unset global_config
35 if {$include_global} {
37 set fd_rc
[open
"| git repo-config --global --list" r
]
38 while {[gets
$fd_rc line
] >= 0} {
39 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
40 if {[is_many_config
$name]} {
41 lappend global_config
($name) $value
43 set global_config
($name) $value
51 array
unset repo_config
53 set fd_rc
[open
"| git repo-config --list" r
]
54 while {[gets
$fd_rc line
] >= 0} {
55 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
56 if {[is_many_config
$name]} {
57 lappend repo_config
($name) $value
59 set repo_config
($name) $value
66 foreach name
[array names default_config
] {
67 if {[catch
{set v
$global_config($name)}]} {
68 set global_config
($name) $default_config($name)
70 if {[catch
{set v
$repo_config($name)}]} {
71 set repo_config
($name) $default_config($name)
77 global default_config font_descs
78 global repo_config global_config
79 global repo_config_new global_config_new
81 foreach option
$font_descs {
82 set name
[lindex
$option 0]
83 set font
[lindex
$option 1]
84 font configure
$font \
85 -family $global_config_new(gui.
$font^^family
) \
86 -size $global_config_new(gui.
$font^^size
)
87 font configure
${font}bold \
88 -family $global_config_new(gui.
$font^^family
) \
89 -size $global_config_new(gui.
$font^^size
)
90 set global_config_new
(gui.
$name) [font configure
$font]
91 unset global_config_new
(gui.
$font^^family
)
92 unset global_config_new
(gui.
$font^^size
)
95 foreach name
[array names default_config
] {
96 set value
$global_config_new($name)
97 if {$value ne
$global_config($name)} {
98 if {$value eq
$default_config($name)} {
99 catch
{exec git repo-config
--global --unset $name}
101 regsub
-all "\[{}\]" $value {"} value
102 exec git repo-config --global $name $value
104 set global_config($name) $value
105 if {$value eq $repo_config($name)} {
106 catch {exec git repo-config --unset $name}
107 set repo_config($name) $value
112 foreach name [array names default_config] {
113 set value $repo_config_new($name)
114 if {$value ne $repo_config($name)} {
115 if {$value eq $global_config($name)} {
116 catch {exec git repo-config --unset $name}
118 regsub -all "\
[{}\
]" $value {"} value
119 exec git repo-config
$name $value
121 set repo_config
($name) $value
126 proc error_popup
{msg
} {
127 global gitdir appname
132 append title
[lindex \
133 [file split [file normalize
[file dirname $gitdir]]] \
137 set cmd
[list tk_messageBox \
140 -title "$title: error" \
142 if {[winfo ismapped .
]} {
143 lappend cmd
-parent .
148 proc warn_popup
{msg
} {
149 global gitdir appname
154 append title
[lindex \
155 [file split [file normalize
[file dirname $gitdir]]] \
159 set cmd
[list tk_messageBox \
162 -title "$title: warning" \
164 if {[winfo ismapped .
]} {
165 lappend cmd
-parent .
170 proc info_popup
{msg
} {
171 global gitdir appname
176 append title
[lindex \
177 [file split [file normalize
[file dirname $gitdir]]] \
189 ######################################################################
193 if { [catch
{set gitdir
$env(GIT_DIR
)}]
194 && [catch
{set gitdir
[exec git rev-parse
--git-dir]} err
]} {
195 catch
{wm withdraw .
}
196 error_popup
"Cannot find the git directory:\n\n$err"
199 if {![file isdirectory
$gitdir]} {
200 catch
{wm withdraw .
}
201 error_popup
"Git directory not found:\n\n$gitdir"
204 if {[lindex
[file split $gitdir] end
] ne
{.git
}} {
205 catch
{wm withdraw .
}
206 error_popup
"Cannot use funny .git directory:\n\n$gitdir"
209 if {[catch
{cd [file dirname $gitdir]} err
]} {
210 catch
{wm withdraw .
}
211 error_popup
"No working directory [file dirname $gitdir]:\n\n$err"
216 if {$appname eq
{git-citool
}} {
220 ######################################################################
228 set disable_on_lock
[list
]
229 set index_lock_type none
231 proc lock_index
{type} {
232 global index_lock_type disable_on_lock
234 if {$index_lock_type eq
{none
}} {
235 set index_lock_type
$type
236 foreach w
$disable_on_lock {
237 uplevel
#0 $w disabled
240 } elseif
{$index_lock_type eq
"begin-$type"} {
241 set index_lock_type
$type
247 proc unlock_index
{} {
248 global index_lock_type disable_on_lock
250 set index_lock_type none
251 foreach w
$disable_on_lock {
256 ######################################################################
260 proc repository_state
{ctvar hdvar mhvar
} {
261 global gitdir current_branch
262 upvar
$ctvar ct
$hdvar hd
$mhvar mh
266 if {[catch
{set current_branch
[exec git symbolic-ref HEAD
]}]} {
267 set current_branch
{}
269 regsub ^refs
/(heads|tags
)/ \
275 if {[catch
{set hd
[exec git rev-parse
--verify HEAD
]}]} {
281 set merge_head
[file join $gitdir MERGE_HEAD
]
282 if {[file exists
$merge_head]} {
284 set fd_mh
[open
$merge_head r
]
285 while {[gets
$fd_mh line
] >= 0} {
296 global PARENT empty_tree
298 set p
[lindex
$PARENT 0]
302 if {$empty_tree eq
{}} {
303 set empty_tree
[exec git mktree
<< {}]
308 proc rescan
{after
} {
309 global HEAD PARENT MERGE_HEAD commit_type
310 global ui_index ui_other ui_status_value ui_comm
311 global rescan_active file_states
314 if {$rescan_active > 0 ||
![lock_index
read]} return
316 repository_state newType newHEAD newMERGE_HEAD
317 if {[string match amend
* $commit_type]
318 && $newType eq
{normal
}
319 && $newHEAD eq
$HEAD} {
323 set MERGE_HEAD
$newMERGE_HEAD
324 set commit_type
$newType
327 array
unset file_states
329 if {![$ui_comm edit modified
]
330 ||
[string trim
[$ui_comm get
0.0 end
]] eq
{}} {
331 if {[load_message GITGUI_MSG
]} {
332 } elseif
{[load_message MERGE_MSG
]} {
333 } elseif
{[load_message SQUASH_MSG
]} {
336 $ui_comm edit modified false
339 if {$repo_config(gui.trustmtime
) eq
{true
}} {
340 rescan_stage2
{} $after
343 set ui_status_value
{Refreshing
file status...
}
344 set cmd
[list git update-index
]
346 lappend cmd
--unmerged
347 lappend cmd
--ignore-missing
348 lappend cmd
--refresh
349 set fd_rf
[open
"| $cmd" r
]
350 fconfigure
$fd_rf -blocking 0 -translation binary
351 fileevent
$fd_rf readable \
352 [list rescan_stage2
$fd_rf $after]
356 proc rescan_stage2
{fd after
} {
357 global gitdir ui_status_value
358 global rescan_active buf_rdi buf_rdf buf_rlo
362 if {![eof
$fd]} return
366 set ls_others
[list | git ls-files
--others -z \
367 --exclude-per-directory=.gitignore
]
368 set info_exclude
[file join $gitdir info exclude
]
369 if {[file readable
$info_exclude]} {
370 lappend ls_others
"--exclude-from=$info_exclude"
378 set ui_status_value
{Scanning
for modified files ...
}
379 set fd_di
[open
"| git diff-index --cached -z [PARENT]" r
]
380 set fd_df
[open
"| git diff-files -z" r
]
381 set fd_lo
[open
$ls_others r
]
383 fconfigure
$fd_di -blocking 0 -translation binary
384 fconfigure
$fd_df -blocking 0 -translation binary
385 fconfigure
$fd_lo -blocking 0 -translation binary
386 fileevent
$fd_di readable
[list read_diff_index
$fd_di $after]
387 fileevent
$fd_df readable
[list read_diff_files
$fd_df $after]
388 fileevent
$fd_lo readable
[list read_ls_others
$fd_lo $after]
391 proc load_message
{file} {
392 global gitdir ui_comm
394 set f
[file join $gitdir $file]
395 if {[file isfile
$f]} {
396 if {[catch
{set fd
[open
$f r
]}]} {
399 set content
[string trim
[read $fd]]
401 $ui_comm delete
0.0 end
402 $ui_comm insert end
$content
408 proc read_diff_index
{fd after
} {
411 append buf_rdi
[read $fd]
413 set n
[string length
$buf_rdi]
415 set z1
[string first
"\0" $buf_rdi $c]
418 set z2
[string first
"\0" $buf_rdi $z1]
422 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
424 [string range
$buf_rdi $z1 [expr {$z2 - 1}]] \
426 [list
[lindex
$i 0] [lindex
$i 2]] \
432 set buf_rdi
[string range
$buf_rdi $c end
]
437 rescan_done
$fd buf_rdi
$after
440 proc read_diff_files
{fd after
} {
443 append buf_rdf
[read $fd]
445 set n
[string length
$buf_rdf]
447 set z1
[string first
"\0" $buf_rdf $c]
450 set z2
[string first
"\0" $buf_rdf $z1]
454 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
456 [string range
$buf_rdf $z1 [expr {$z2 - 1}]] \
459 [list
[lindex
$i 0] [lindex
$i 2]]
464 set buf_rdf
[string range
$buf_rdf $c end
]
469 rescan_done
$fd buf_rdf
$after
472 proc read_ls_others
{fd after
} {
475 append buf_rlo
[read $fd]
476 set pck
[split $buf_rlo "\0"]
477 set buf_rlo
[lindex
$pck end
]
478 foreach p
[lrange
$pck 0 end-1
] {
481 rescan_done
$fd buf_rlo
$after
484 proc rescan_done
{fd buf after
} {
486 global file_states repo_config
489 if {![eof
$fd]} return
492 if {[incr rescan_active
-1] > 0} return
498 if {$repo_config(gui.partialinclude
) ne
{true
}} {
500 foreach path
[array names file_states
] {
501 switch
-- [lindex
$file_states($path) 0] {
503 MM
{lappend pathList
$path}
506 if {$pathList ne
{}} {
508 "Updating included files" \
510 [concat
{reshow_diff
;} $after]
519 proc prune_selection
{} {
520 global file_states selected_paths
522 foreach path
[array names selected_paths
] {
523 if {[catch
{set still_here
$file_states($path)}]} {
524 unset selected_paths
($path)
529 ######################################################################
534 global ui_diff current_diff ui_index ui_other
536 $ui_diff conf
-state normal
537 $ui_diff delete
0.0 end
538 $ui_diff conf
-state disabled
542 $ui_index tag remove in_diff
0.0 end
543 $ui_other tag remove in_diff
0.0 end
546 proc reshow_diff
{} {
547 global current_diff ui_status_value file_states
549 if {$current_diff eq
{}
550 ||
[catch
{set s
$file_states($current_diff)}]} {
553 show_diff
$current_diff
557 proc handle_empty_diff
{} {
558 global current_diff file_states file_lists
560 set path
$current_diff
561 set s
$file_states($path)
562 if {[lindex
$s 0] ne
{_M
}} return
564 info_popup
"No differences detected.
566 [short_path $path] has no changes.
568 The modification date of this file was updated
569 by another application and you currently have
570 the Trust File Modification Timestamps option
571 enabled, so Git did not automatically detect
572 that there are no content differences in this
575 This file will now be removed from the modified
576 files list, to prevent possible confusion.
578 if {[catch
{exec git update-index
-- $path} err
]} {
579 error_popup
"Failed to refresh index:\n\n$err"
583 set old_w
[mapcol
[lindex
$file_states($path) 0] $path]
584 set lno
[lsearch
-sorted $file_lists($old_w) $path]
586 set file_lists
($old_w) \
587 [lreplace
$file_lists($old_w) $lno $lno]
589 $old_w conf
-state normal
590 $old_w delete
$lno.0 [expr {$lno + 1}].0
591 $old_w conf
-state disabled
595 proc show_diff
{path
{w
{}} {lno
{}}} {
596 global file_states file_lists
597 global is_3way_diff diff_active repo_config
598 global ui_diff current_diff ui_status_value
600 if {$diff_active ||
![lock_index
read]} return
603 if {$w eq
{} ||
$lno == {}} {
604 foreach w
[array names file_lists
] {
605 set lno
[lsearch
-sorted $file_lists($w) $path]
612 if {$w ne
{} && $lno >= 1} {
613 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
616 set s
$file_states($path)
620 set current_diff
$path
621 set ui_status_value
"Loading diff of [escape_path $path]..."
623 set cmd
[list | git diff-index
]
624 lappend cmd
--no-color
625 if {$repo_config(gui.diffcontext
) > 0} {
626 lappend cmd
"-U$repo_config(gui.diffcontext)"
636 set fd
[open
$path r
]
637 set content
[read $fd]
642 set ui_status_value
"Unable to display [escape_path $path]"
643 error_popup
"Error loading file:\n\n$err"
646 $ui_diff conf
-state normal
647 $ui_diff insert end
$content
648 $ui_diff conf
-state disabled
651 set ui_status_value
{Ready.
}
660 if {[catch
{set fd
[open
$cmd r
]} err
]} {
663 set ui_status_value
"Unable to display [escape_path $path]"
664 error_popup
"Error loading diff:\n\n$err"
668 fconfigure
$fd -blocking 0 -translation auto
669 fileevent
$fd readable
[list read_diff
$fd]
672 proc read_diff
{fd
} {
673 global ui_diff ui_status_value is_3way_diff diff_active
676 $ui_diff conf
-state normal
677 while {[gets
$fd line
] >= 0} {
678 # -- Cleanup uninteresting diff header lines.
680 if {[string match
{diff --git *} $line]} continue
681 if {[string match
{diff --combined *} $line]} continue
682 if {[string match
{--- *} $line]} continue
683 if {[string match
{+++ *} $line]} continue
684 if {$line eq
{deleted
file mode
120000}} {
685 set line
"deleted symlink"
688 # -- Automatically detect if this is a 3 way diff.
690 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
692 # -- Reformat a 3 way diff, 'cause its too weird.
695 set op
[string range
$line 0 1]
698 {++} {set tags d_
+ ; set op
{ +}}
699 {--} {set tags d_-
; set op
{ -}}
700 { +} {set tags d_
++; set op
{++}}
701 { -} {set tags d_--
; set op
{--}}
702 {+ } {set tags d_-
+; set op
{-+}}
703 {- } {set tags d_
+-; set op
{+-}}
704 default
{set tags
{}}
706 set line
[string replace
$line 0 1 $op]
708 switch
-- [string index
$line 0] {
712 default
{set tags
{}}
715 $ui_diff insert end
$line $tags
716 $ui_diff insert end
"\n" $tags
718 $ui_diff conf
-state disabled
724 set ui_status_value
{Ready.
}
726 if {$repo_config(gui.trustmtime
) eq
{true
}
727 && [$ui_diff index end
] eq
{2.0}} {
733 ######################################################################
737 proc load_last_commit
{} {
738 global HEAD PARENT MERGE_HEAD commit_type ui_comm
740 if {[llength
$PARENT] == 0} {
741 error_popup
{There is nothing to amend.
743 You are about to create the initial commit.
744 There is no commit before this to amend.
749 repository_state curType curHEAD curMERGE_HEAD
750 if {$curType eq
{merge
}} {
751 error_popup
{Cannot amend
while merging.
753 You are currently
in the middle of a merge that
754 has not been fully completed. You cannot amend
755 the prior commit unless you first abort the
756 current merge activity.
764 set fd
[open
"| git cat-file commit $curHEAD" r
]
765 while {[gets
$fd line
] > 0} {
766 if {[string match
{parent
*} $line]} {
767 lappend parents
[string range
$line 7 end
]
770 set msg
[string trim
[read $fd]]
773 error_popup
"Error loading commit data for amend:\n\n$err"
779 set MERGE_HEAD
[list
]
780 switch
-- [llength
$parents] {
781 0 {set commit_type amend-initial
}
782 1 {set commit_type amend
}
783 default
{set commit_type amend-merge
}
786 $ui_comm delete
0.0 end
787 $ui_comm insert end
$msg
789 $ui_comm edit modified false
790 rescan
{set ui_status_value
{Ready.
}}
793 proc create_new_commit
{} {
794 global commit_type ui_comm
796 set commit_type normal
797 $ui_comm delete
0.0 end
799 $ui_comm edit modified false
800 rescan
{set ui_status_value
{Ready.
}}
803 set GIT_COMMITTER_IDENT
{}
805 proc committer_ident
{} {
806 global GIT_COMMITTER_IDENT
808 if {$GIT_COMMITTER_IDENT eq
{}} {
809 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
810 error_popup
"Unable to obtain your identity:\n\n$err"
813 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
814 $me me GIT_COMMITTER_IDENT
]} {
815 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
820 return $GIT_COMMITTER_IDENT
823 proc commit_tree
{} {
824 global HEAD commit_type file_states ui_comm repo_config
826 if {![lock_index update
]} return
827 if {[committer_ident
] eq
{}} return
829 # -- Our in memory state should match the repository.
831 repository_state curType curHEAD curMERGE_HEAD
832 if {[string match amend
* $commit_type]
833 && $curType eq
{normal
}
834 && $curHEAD eq
$HEAD} {
835 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
836 info_popup
{Last scanned state does not match repository state.
838 Another Git program has modified this repository
839 since the last scan. A rescan must be performed
840 before another commit can be created.
842 The rescan will be automatically started now.
845 rescan
{set ui_status_value
{Ready.
}}
849 # -- At least one file should differ in the index.
852 foreach path
[array names file_states
] {
853 switch
-glob -- [lindex
$file_states($path) 0] {
857 M?
{set files_ready
1; break}
859 error_popup
"Unmerged files cannot be committed.
861 File [short_path $path] has merge conflicts.
862 You must resolve them and include the file before committing.
868 error_popup
"Unknown file state [lindex $s 0] detected.
870 File [short_path $path] cannot be committed by this program.
876 error_popup
{No included files to commit.
878 You must include
at least
1 file before you can commit.
884 # -- A message is required.
886 set msg
[string trim
[$ui_comm get
1.0 end
]]
888 error_popup
{Please supply a commit message.
890 A good commit message has the following format
:
892 - First line
: Describe
in one sentance what you did.
894 - Remaining lines
: Describe why this change is good.
900 # -- Update included files if partialincludes are off.
902 if {$repo_config(gui.partialinclude
) ne
{true
}} {
904 foreach path
[array names file_states
] {
905 switch
-glob -- [lindex
$file_states($path) 0] {
907 M?
{lappend pathList
$path}
910 if {$pathList ne
{}} {
913 "Updating included files" \
915 [concat
{lock_index update
;} \
916 [list commit_prehook
$curHEAD $msg]]
921 commit_prehook
$curHEAD $msg
924 proc commit_prehook
{curHEAD msg
} {
925 global gitdir ui_status_value pch_error
927 set pchook
[file join $gitdir hooks pre-commit
]
929 # On Cygwin [file executable] might lie so we need to ask
930 # the shell if the hook is executable. Yes that's annoying.
932 if {[is_Windows
] && [file isfile
$pchook]} {
933 set pchook
[list sh
-c [concat \
934 "if test -x \"$pchook\";" \
935 "then exec \"$pchook\" 2>&1;" \
937 } elseif
{[file executable
$pchook]} {
938 set pchook
[list
$pchook |
& cat]
940 commit_writetree
$curHEAD $msg
944 set ui_status_value
{Calling pre-commit hook...
}
946 set fd_ph
[open
"| $pchook" r
]
947 fconfigure
$fd_ph -blocking 0 -translation binary
948 fileevent
$fd_ph readable \
949 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
952 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
953 global pch_error ui_status_value
955 append pch_error
[read $fd_ph]
956 fconfigure
$fd_ph -blocking 1
958 if {[catch
{close
$fd_ph}]} {
959 set ui_status_value
{Commit declined by pre-commit hook.
}
960 hook_failed_popup pre-commit
$pch_error
963 commit_writetree
$curHEAD $msg
968 fconfigure
$fd_ph -blocking 0
971 proc commit_writetree
{curHEAD msg
} {
972 global ui_status_value
974 set ui_status_value
{Committing changes...
}
975 set fd_wt
[open
"| git write-tree" r
]
976 fileevent
$fd_wt readable \
977 [list commit_committree
$fd_wt $curHEAD $msg]
980 proc commit_committree
{fd_wt curHEAD msg
} {
981 global HEAD PARENT MERGE_HEAD commit_type
982 global single_commit gitdir
983 global ui_status_value ui_comm selected_commit_type
984 global file_states selected_paths rescan_active
987 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
988 error_popup
"write-tree failed:\n\n$err"
989 set ui_status_value
{Commit failed.
}
994 # -- Create the commit.
996 set cmd
[list git commit-tree
$tree_id]
997 set parents
[concat
$PARENT $MERGE_HEAD]
998 if {[llength
$parents] > 0} {
1003 # git commit-tree writes to stderr during initial commit.
1004 lappend cmd
2>/dev
/null
1007 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1008 error_popup
"commit-tree failed:\n\n$err"
1009 set ui_status_value
{Commit failed.
}
1014 # -- Update the HEAD ref.
1017 if {$commit_type ne
{normal
}} {
1018 append reflogm
" ($commit_type)"
1020 set i
[string first
"\n" $msg]
1022 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1024 append reflogm
{: } $msg
1026 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1027 if {[catch
{eval exec $cmd} err
]} {
1028 error_popup
"update-ref failed:\n\n$err"
1029 set ui_status_value
{Commit failed.
}
1034 # -- Cleanup after ourselves.
1036 catch
{file delete
[file join $gitdir MERGE_HEAD
]}
1037 catch
{file delete
[file join $gitdir MERGE_MSG
]}
1038 catch
{file delete
[file join $gitdir SQUASH_MSG
]}
1039 catch
{file delete
[file join $gitdir GITGUI_MSG
]}
1041 # -- Let rerere do its thing.
1043 if {[file isdirectory
[file join $gitdir rr-cache
]]} {
1044 catch
{exec git rerere
}
1047 # -- Run the post-commit hook.
1049 set pchook
[file join $gitdir hooks post-commit
]
1050 if {[is_Windows
] && [file isfile
$pchook]} {
1051 set pchook
[list sh
-c [concat \
1052 "if test -x \"$pchook\";" \
1053 "then exec \"$pchook\";" \
1055 } elseif
{![file executable
$pchook]} {
1058 if {$pchook ne
{}} {
1059 catch
{exec $pchook &}
1062 $ui_comm delete
0.0 end
1064 $ui_comm edit modified false
1066 if {$single_commit} do_quit
1068 # -- Update in memory status
1070 set selected_commit_type new
1071 set commit_type normal
1074 set MERGE_HEAD
[list
]
1076 foreach path
[array names file_states
] {
1077 set s
$file_states($path)
1079 switch
-glob -- $m {
1087 unset file_states
($path)
1088 catch
{unset selected_paths
($path)}
1091 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1098 set file_states
($path) [list \
1099 _
[string index
$m 1] \
1110 set ui_status_value \
1111 "Changes committed as [string range $cmt_id 0 7]."
1114 ######################################################################
1118 proc fetch_from
{remote
} {
1119 set w
[new_console
"fetch $remote" \
1120 "Fetching new changes from $remote"]
1121 set cmd
[list git fetch
]
1123 console_exec
$w $cmd
1126 proc pull_remote
{remote branch
} {
1127 global HEAD commit_type file_states repo_config
1129 if {![lock_index update
]} return
1131 # -- Our in memory state should match the repository.
1133 repository_state curType curHEAD curMERGE_HEAD
1134 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1135 info_popup
{Last scanned state does not match repository state.
1137 Another Git program has modified this repository
1138 since the last scan. A rescan must be performed
1139 before a pull operation can be started.
1141 The rescan will be automatically started now.
1144 rescan
{set ui_status_value
{Ready.
}}
1148 # -- No differences should exist before a pull.
1150 if {[array size file_states
] != 0} {
1151 error_popup
{Uncommitted but modified files are present.
1153 You should not perform a pull with unmodified
1154 files
in your working directory as Git will be
1155 unable to recover from an incorrect merge.
1157 You should commit or revert all changes before
1158 starting a pull operation.
1164 set w
[new_console
"pull $remote $branch" \
1165 "Pulling new changes from branch $branch in $remote"]
1166 set cmd
[list git pull
]
1167 if {$repo_config(gui.pullsummary
) eq
{false
}} {
1168 lappend cmd
--no-summary
1172 console_exec
$w $cmd [list post_pull_remote
$remote $branch]
1175 proc post_pull_remote
{remote branch success
} {
1176 global HEAD PARENT MERGE_HEAD commit_type selected_commit_type
1177 global ui_status_value
1181 repository_state commit_type HEAD MERGE_HEAD
1183 set selected_commit_type new
1184 set ui_status_value
"Pulling $branch from $remote complete."
1186 rescan
[list
set ui_status_value \
1187 "Conflicts detected while pulling $branch from $remote."]
1191 proc push_to
{remote
} {
1192 set w
[new_console
"push $remote" \
1193 "Pushing changes to $remote"]
1194 set cmd
[list git push
]
1196 console_exec
$w $cmd
1199 ######################################################################
1203 proc mapcol
{state path
} {
1204 global all_cols ui_other
1206 if {[catch
{set r
$all_cols($state)}]} {
1207 puts
"error: no column for state={$state} $path"
1213 proc mapicon
{state path
} {
1216 if {[catch
{set r
$all_icons($state)}]} {
1217 puts
"error: no icon for state={$state} $path"
1223 proc mapdesc
{state path
} {
1226 if {[catch
{set r
$all_descs($state)}]} {
1227 puts
"error: no desc for state={$state} $path"
1233 proc escape_path
{path
} {
1234 regsub
-all "\n" $path "\\n" path
1238 proc short_path
{path
} {
1239 return [escape_path
[lindex
[file split $path] end
]]
1243 set null_sha1
[string repeat
0 40]
1245 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1246 global file_states next_icon_id null_sha1
1248 set s0
[string index
$new_state 0]
1249 set s1
[string index
$new_state 1]
1251 if {[catch
{set info
$file_states($path)}]} {
1253 set icon n
[incr next_icon_id
]
1255 set state
[lindex
$info 0]
1256 set icon
[lindex
$info 1]
1257 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1258 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1261 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1262 elseif
{$s0 eq
{_
}} {set s0 _
}
1264 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1265 elseif
{$s1 eq
{_
}} {set s1 _
}
1267 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1268 set head_info
[list
0 $null_sha1]
1269 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1270 && $head_info eq
{}} {
1271 set head_info
$index_info
1274 set file_states
($path) [list
$s0$s1 $icon \
1275 $head_info $index_info \
1280 proc display_file
{path state
} {
1281 global file_states file_lists selected_paths
1283 set old_m
[merge_state
$path $state]
1284 set s
$file_states($path)
1285 set new_m
[lindex
$s 0]
1286 set new_w
[mapcol
$new_m $path]
1287 set old_w
[mapcol
$old_m $path]
1288 set new_icon
[mapicon
$new_m $path]
1290 if {$new_m eq
{__
}} {
1291 set lno
[lsearch
-sorted $file_lists($old_w) $path]
1293 set file_lists
($old_w) \
1294 [lreplace
$file_lists($old_w) $lno $lno]
1296 $old_w conf
-state normal
1297 $old_w delete
$lno.0 [expr {$lno + 1}].0
1298 $old_w conf
-state disabled
1300 unset file_states
($path)
1301 catch
{unset selected_paths
($path)}
1305 if {$new_w ne
$old_w} {
1306 set lno
[lsearch
-sorted $file_lists($old_w) $path]
1308 set file_lists
($old_w) \
1309 [lreplace
$file_lists($old_w) $lno $lno]
1311 $old_w conf
-state normal
1312 $old_w delete
$lno.0 [expr {$lno + 1}].0
1313 $old_w conf
-state disabled
1316 lappend file_lists
($new_w) $path
1317 set file_lists
($new_w) [lsort
$file_lists($new_w)]
1318 set lno
[lsearch
-sorted $file_lists($new_w) $path]
1320 $new_w conf
-state normal
1321 $new_w image create
$lno.0 \
1322 -align center
-padx 5 -pady 1 \
1323 -name [lindex
$s 1] \
1325 $new_w insert
$lno.1 "[escape_path $path]\n"
1326 if {[catch
{set in_sel
$selected_paths($path)}]} {
1330 $new_w tag add in_sel
$lno.0 [expr {$lno + 1}].0
1332 $new_w conf
-state disabled
1333 } elseif
{$new_icon ne
[mapicon
$old_m $path]} {
1334 $new_w conf
-state normal
1335 $new_w image conf
[lindex
$s 1] -image $new_icon
1336 $new_w conf
-state disabled
1340 proc display_all_files
{} {
1341 global ui_index ui_other
1342 global file_states file_lists
1343 global last_clicked selected_paths
1345 $ui_index conf
-state normal
1346 $ui_other conf
-state normal
1348 $ui_index delete
0.0 end
1349 $ui_other delete
0.0 end
1352 set file_lists
($ui_index) [list
]
1353 set file_lists
($ui_other) [list
]
1355 foreach path
[lsort
[array names file_states
]] {
1356 set s
$file_states($path)
1358 set w
[mapcol
$m $path]
1359 lappend file_lists
($w) $path
1360 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1361 $w image create end \
1362 -align center
-padx 5 -pady 1 \
1363 -name [lindex
$s 1] \
1364 -image [mapicon
$m $path]
1365 $w insert end
"[escape_path $path]\n"
1366 if {[catch
{set in_sel
$selected_paths($path)}]} {
1370 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
1374 $ui_index conf
-state disabled
1375 $ui_other conf
-state disabled
1378 proc update_indexinfo
{msg pathList after
} {
1379 global update_index_cp ui_status_value
1381 if {![lock_index update
]} return
1383 set update_index_cp
0
1384 set pathList
[lsort
$pathList]
1385 set totalCnt
[llength
$pathList]
1386 set batch [expr {int
($totalCnt * .01) + 1}]
1387 if {$batch > 25} {set batch 25}
1389 set ui_status_value
[format \
1390 "$msg... %i/%i files (%.2f%%)" \
1394 set fd
[open
"| git update-index -z --index-info" w
]
1400 fileevent
$fd writable
[list \
1401 write_update_indexinfo \
1411 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1412 global update_index_cp ui_status_value
1413 global file_states current_diff
1415 if {$update_index_cp >= $totalCnt} {
1422 for {set i
$batch} \
1423 {$update_index_cp < $totalCnt && $i > 0} \
1425 set path
[lindex
$pathList $update_index_cp]
1426 incr update_index_cp
1428 set s
$file_states($path)
1429 switch
-glob -- [lindex
$s 0] {
1435 set info
[lindex
$s 2]
1436 if {$info eq
{}} continue
1438 puts
-nonewline $fd $info
1439 puts
-nonewline $fd "\t"
1440 puts
-nonewline $fd $path
1441 puts
-nonewline $fd "\0"
1442 display_file
$path $new
1445 set ui_status_value
[format \
1446 "$msg... %i/%i files (%.2f%%)" \
1449 [expr {100.0 * $update_index_cp / $totalCnt}]]
1452 proc update_index
{msg pathList after
} {
1453 global update_index_cp ui_status_value
1455 if {![lock_index update
]} return
1457 set update_index_cp
0
1458 set pathList
[lsort
$pathList]
1459 set totalCnt
[llength
$pathList]
1460 set batch [expr {int
($totalCnt * .01) + 1}]
1461 if {$batch > 25} {set batch 25}
1463 set ui_status_value
[format \
1464 "$msg... %i/%i files (%.2f%%)" \
1468 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1474 fileevent
$fd writable
[list \
1475 write_update_index \
1485 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1486 global update_index_cp ui_status_value
1487 global file_states current_diff
1489 if {$update_index_cp >= $totalCnt} {
1496 for {set i
$batch} \
1497 {$update_index_cp < $totalCnt && $i > 0} \
1499 set path
[lindex
$pathList $update_index_cp]
1500 incr update_index_cp
1502 switch
-glob -- [lindex
$file_states($path) 0] {
1518 puts
-nonewline $fd $path
1519 puts
-nonewline $fd "\0"
1520 display_file
$path $new
1523 set ui_status_value
[format \
1524 "$msg... %i/%i files (%.2f%%)" \
1527 [expr {100.0 * $update_index_cp / $totalCnt}]]
1530 proc checkout_index
{msg pathList after
} {
1531 global update_index_cp ui_status_value
1533 if {![lock_index update
]} return
1535 set update_index_cp
0
1536 set pathList
[lsort
$pathList]
1537 set totalCnt
[llength
$pathList]
1538 set batch [expr {int
($totalCnt * .01) + 1}]
1539 if {$batch > 25} {set batch 25}
1541 set ui_status_value
[format \
1542 "$msg... %i/%i files (%.2f%%)" \
1546 set cmd
[list git checkout-index
]
1552 set fd
[open
"| $cmd " w
]
1558 fileevent
$fd writable
[list \
1559 write_checkout_index \
1569 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1570 global update_index_cp ui_status_value
1571 global file_states current_diff
1573 if {$update_index_cp >= $totalCnt} {
1580 for {set i
$batch} \
1581 {$update_index_cp < $totalCnt && $i > 0} \
1583 set path
[lindex
$pathList $update_index_cp]
1584 incr update_index_cp
1586 switch
-glob -- [lindex
$file_states($path) 0] {
1596 puts
-nonewline $fd $path
1597 puts
-nonewline $fd "\0"
1598 display_file
$path $new
1601 set ui_status_value
[format \
1602 "$msg... %i/%i files (%.2f%%)" \
1605 [expr {100.0 * $update_index_cp / $totalCnt}]]
1608 ######################################################################
1610 ## remote management
1612 proc load_all_remotes
{} {
1613 global gitdir all_remotes repo_config
1615 set all_remotes
[list
]
1616 set rm_dir
[file join $gitdir remotes
]
1617 if {[file isdirectory
$rm_dir]} {
1618 set all_remotes
[concat
$all_remotes [glob \
1622 -directory $rm_dir *]]
1625 foreach line
[array names repo_config remote.
*.url
] {
1626 if {[regexp ^remote\.
(.
*)\.url\$
$line line name
]} {
1627 lappend all_remotes
$name
1631 set all_remotes
[lsort
-unique $all_remotes]
1634 proc populate_fetch_menu
{m
} {
1635 global gitdir all_remotes repo_config
1637 foreach r
$all_remotes {
1639 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
1640 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
1645 set fd
[open
[file join $gitdir remotes
$r] r
]
1646 while {[gets
$fd n
] >= 0} {
1647 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
1658 -label "Fetch from $r..." \
1659 -command [list fetch_from
$r] \
1665 proc populate_push_menu
{m
} {
1666 global gitdir all_remotes repo_config
1668 foreach r
$all_remotes {
1670 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
1671 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
1676 set fd
[open
[file join $gitdir remotes
$r] r
]
1677 while {[gets
$fd n
] >= 0} {
1678 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
1689 -label "Push to $r..." \
1690 -command [list push_to
$r] \
1696 proc populate_pull_menu
{m
} {
1697 global gitdir repo_config all_remotes disable_on_lock
1699 foreach remote
$all_remotes {
1701 if {[array get repo_config remote.
$remote.url
] ne
{}} {
1702 if {[array get repo_config remote.
$remote.fetch
] ne
{}} {
1703 regexp
{^
([^
:]+):} \
1704 [lindex
$repo_config(remote.
$remote.fetch
) 0] \
1709 set fd
[open
[file join $gitdir remotes
$remote] r
]
1710 while {[gets
$fd line
] >= 0} {
1711 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $line line rb
]} {
1720 regsub ^refs
/heads
/ $rb {} rb_short
1721 if {$rb_short ne
{}} {
1723 -label "Branch $rb_short from $remote..." \
1724 -command [list pull_remote
$remote $rb] \
1726 lappend disable_on_lock \
1727 [list
$m entryconf
[$m index last
] -state]
1732 ######################################################################
1737 #define mask_width 14
1738 #define mask_height 15
1739 static unsigned char mask_bits
[] = {
1740 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1741 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1742 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1745 image create bitmap file_plain
-background white
-foreground black
-data {
1746 #define plain_width 14
1747 #define plain_height 15
1748 static unsigned char plain_bits
[] = {
1749 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1750 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1751 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1752 } -maskdata $filemask
1754 image create bitmap file_mod
-background white
-foreground blue
-data {
1755 #define mod_width 14
1756 #define mod_height 15
1757 static unsigned char mod_bits
[] = {
1758 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1759 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1760 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1761 } -maskdata $filemask
1763 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
1764 #define file_fulltick_width 14
1765 #define file_fulltick_height 15
1766 static unsigned char file_fulltick_bits
[] = {
1767 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1768 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1769 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1770 } -maskdata $filemask
1772 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
1773 #define parttick_width 14
1774 #define parttick_height 15
1775 static unsigned char parttick_bits
[] = {
1776 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1777 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
1778 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1779 } -maskdata $filemask
1781 image create bitmap file_question
-background white
-foreground black
-data {
1782 #define file_question_width 14
1783 #define file_question_height 15
1784 static unsigned char file_question_bits
[] = {
1785 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1786 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1787 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1788 } -maskdata $filemask
1790 image create bitmap file_removed
-background white
-foreground red
-data {
1791 #define file_removed_width 14
1792 #define file_removed_height 15
1793 static unsigned char file_removed_bits
[] = {
1794 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1795 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1796 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1797 } -maskdata $filemask
1799 image create bitmap file_merge
-background white
-foreground blue
-data {
1800 #define file_merge_width 14
1801 #define file_merge_height 15
1802 static unsigned char file_merge_bits
[] = {
1803 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1804 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1805 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1806 } -maskdata $filemask
1808 set ui_index .vpane.files.index.list
1809 set ui_other .vpane.files.other.list
1810 set max_status_desc
0
1812 {__ i plain
"Unmodified"}
1813 {_M i mod
"Modified"}
1814 {M_ i fulltick
"Included in commit"}
1815 {MM i parttick
"Partially included"}
1816 {MD i question
"Included (but gone)"}
1818 {_O o plain
"Untracked"}
1819 {A_ o fulltick
"Added by commit"}
1820 {AM o parttick
"Partially added"}
1821 {AD o question
"Added (but gone)"}
1823 {_D i question
"Missing"}
1824 {DD i removed
"Removed by commit"}
1825 {DO i removed
"Removed (still exists)"}
1826 {DM i removed
"Removed (but modified)"}
1828 {UD i merge
"Merge conflicts"}
1829 {UM i merge
"Merge conflicts"}
1830 {U_ i merge
"Merge conflicts"}
1832 if {$max_status_desc < [string length
[lindex
$i 3]]} {
1833 set max_status_desc
[string length
[lindex
$i 3]]
1835 if {[lindex
$i 1] eq
{i
}} {
1836 set all_cols
([lindex
$i 0]) $ui_index
1838 set all_cols
([lindex
$i 0]) $ui_other
1840 set all_icons
([lindex
$i 0]) file_
[lindex
$i 2]
1841 set all_descs
([lindex
$i 0]) [lindex
$i 3]
1845 ######################################################################
1850 global tcl_platform tk_library
1851 if {[tk windowingsystem
] eq
{aqua
}} {
1857 proc is_Windows
{} {
1859 if {$tcl_platform(platform
) eq
{windows
}} {
1865 proc bind_button3
{w cmd
} {
1866 bind $w <Any-Button-3
> $cmd
1868 bind $w <Control-Button-1
> $cmd
1872 proc incr_font_size
{font
{amt
1}} {
1873 set sz
[font configure
$font -size]
1875 font configure
$font -size $sz
1876 font configure
${font}bold
-size $sz
1879 proc hook_failed_popup
{hook msg
} {
1880 global gitdir appname
1886 label
$w.m.l1
-text "$hook hook failed:" \
1891 -background white
-borderwidth 1 \
1893 -width 80 -height 10 \
1895 -yscrollcommand [list
$w.m.sby
set]
1897 -text {You must correct the above errors before committing.
} \
1901 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
1902 pack
$w.m.l1
-side top
-fill x
1903 pack
$w.m.l2
-side bottom
-fill x
1904 pack
$w.m.sby
-side right
-fill y
1905 pack
$w.m.t
-side left
-fill both
-expand 1
1906 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
1908 $w.m.t insert
1.0 $msg
1909 $w.m.t conf
-state disabled
1911 button
$w.ok
-text OK \
1914 -command "destroy $w"
1915 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
1917 bind $w <Visibility
> "grab $w; focus $w"
1918 bind $w <Key-Return
> "destroy $w"
1919 wm title
$w "$appname ([lindex [file split \
1920 [file normalize [file dirname $gitdir]]] \
1925 set next_console_id
0
1927 proc new_console
{short_title long_title
} {
1928 global next_console_id console_data
1929 set w .console
[incr next_console_id
]
1930 set console_data
($w) [list
$short_title $long_title]
1931 return [console_init
$w]
1934 proc console_init
{w
} {
1935 global console_cr console_data
1936 global gitdir appname M1B
1938 set console_cr
($w) 1.0
1941 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
1946 -background white
-borderwidth 1 \
1948 -width 80 -height 10 \
1951 -yscrollcommand [list
$w.m.sby
set]
1952 label
$w.m.s
-text {Working... please
wait...
} \
1956 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
1957 pack
$w.m.l1
-side top
-fill x
1958 pack
$w.m.s
-side bottom
-fill x
1959 pack
$w.m.sby
-side right
-fill y
1960 pack
$w.m.t
-side left
-fill both
-expand 1
1961 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
1963 menu
$w.ctxm
-tearoff 0
1964 $w.ctxm add
command -label "Copy" \
1966 -command "tk_textCopy $w.m.t"
1967 $w.ctxm add
command -label "Select All" \
1969 -command "$w.m.t tag add sel 0.0 end"
1970 $w.ctxm add
command -label "Copy All" \
1973 $w.m.t tag add sel 0.0 end
1975 $w.m.t tag remove sel 0.0 end
1978 button
$w.ok
-text {Close
} \
1981 -command "destroy $w"
1982 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
1984 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
1985 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
1986 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
1987 bind $w <Visibility
> "focus $w"
1988 wm title
$w "$appname ([lindex [file split \
1989 [file normalize [file dirname $gitdir]]] \
1990 end]): [lindex $console_data($w) 0]"
1994 proc console_exec
{w cmd
{after
{}}} {
1995 # -- Windows tosses the enviroment when we exec our child.
1996 # But most users need that so we have to relogin. :-(
1999 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
2002 # -- Tcl won't let us redirect both stdout and stderr to
2003 # the same pipe. So pass it through cat...
2005 set cmd
[concat |
$cmd |
& cat]
2007 set fd_f
[open
$cmd r
]
2008 fconfigure
$fd_f -blocking 0 -translation binary
2009 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
2012 proc console_read
{w fd after
} {
2013 global console_cr console_data
2017 if {![winfo exists
$w]} {console_init
$w}
2018 $w.m.t conf
-state normal
2020 set n
[string length
$buf]
2022 set cr
[string first
"\r" $buf $c]
2023 set lf
[string first
"\n" $buf $c]
2024 if {$cr < 0} {set cr
[expr {$n + 1}]}
2025 if {$lf < 0} {set lf
[expr {$n + 1}]}
2028 $w.m.t insert end
[string range
$buf $c $lf]
2029 set console_cr
($w) [$w.m.t index
{end
-1c}]
2033 $w.m.t delete
$console_cr($w) end
2034 $w.m.t insert end
"\n"
2035 $w.m.t insert end
[string range
$buf $c $cr]
2040 $w.m.t conf
-state disabled
2044 fconfigure
$fd -blocking 1
2046 if {[catch
{close
$fd}]} {
2047 if {![winfo exists
$w]} {console_init
$w}
2048 $w.m.s conf
-background red
-text {Error
: Command Failed
}
2049 $w.ok conf
-state normal
2051 } elseif
{[winfo exists
$w]} {
2052 $w.m.s conf
-background green
-text {Success
}
2053 $w.ok conf
-state normal
2056 array
unset console_cr
$w
2057 array
unset console_data
$w
2059 uplevel
#0 $after $ok
2063 fconfigure
$fd -blocking 0
2066 ######################################################################
2070 set starting_gitk_msg
{Please
wait... Starting gitk...
}
2072 proc do_gitk
{revs
} {
2073 global ui_status_value starting_gitk_msg
2081 set cmd
"sh -c \"exec $cmd\""
2085 if {[catch
{eval exec $cmd} err
]} {
2086 error_popup
"Failed to start gitk:\n\n$err"
2088 set ui_status_value
$starting_gitk_msg
2090 if {$ui_status_value eq
$starting_gitk_msg} {
2091 set ui_status_value
{Ready.
}
2098 set w
[new_console
{repack
} \
2099 {Repacking the object database
}]
2100 set cmd
[list git repack
]
2103 console_exec
$w $cmd
2106 proc do_fsck_objects
{} {
2107 set w
[new_console
{fsck-objects
} \
2108 {Verifying the object database with fsck-objects
}]
2109 set cmd
[list git fsck-objects
]
2112 lappend cmd
--strict
2113 console_exec
$w $cmd
2119 global gitdir ui_comm is_quitting repo_config commit_type
2121 if {$is_quitting} return
2124 # -- Stash our current commit buffer.
2126 set save
[file join $gitdir GITGUI_MSG
]
2127 set msg
[string trim
[$ui_comm get
0.0 end
]]
2128 if {![string match amend
* $commit_type]
2129 && [$ui_comm edit modified
]
2132 set fd
[open
$save w
]
2133 puts
$fd [string trim
[$ui_comm get
0.0 end
]]
2137 catch
{file delete
$save}
2140 # -- Stash our current window geometry into this repository.
2142 set cfg_geometry
[list
]
2143 lappend cfg_geometry
[wm geometry .
]
2144 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
2145 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
2146 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
2149 if {$cfg_geometry ne
$rc_geometry} {
2150 catch
{exec git repo-config gui.geometry
$cfg_geometry}
2157 rescan
{set ui_status_value
{Ready.
}}
2160 proc remove_helper
{txt paths
} {
2161 global file_states current_diff
2163 if {![lock_index begin-update
]} return
2167 foreach path
$paths {
2168 switch
-glob -- [lindex
$file_states($path) 0] {
2172 lappend pathList
$path
2173 if {$path eq
$current_diff} {
2174 set after
{reshow_diff
;}
2179 if {$pathList eq
{}} {
2185 [concat
$after {set ui_status_value
{Ready.
}}]
2189 proc do_remove_selection
{} {
2190 global current_diff selected_paths
2192 if {[array size selected_paths
] > 0} {
2194 {Removing selected files from commit
} \
2195 [array names selected_paths
]
2196 } elseif
{$current_diff ne
{}} {
2198 "Removing [short_path $current_diff] from commit" \
2199 [list
$current_diff]
2203 proc include_helper
{txt paths
} {
2204 global file_states current_diff
2206 if {![lock_index begin-update
]} return
2210 foreach path
$paths {
2211 switch
-glob -- [lindex
$file_states($path) 0] {
2220 lappend pathList
$path
2221 if {$path eq
$current_diff} {
2222 set after
{reshow_diff
;}
2227 if {$pathList eq
{}} {
2233 [concat
$after {set ui_status_value
{Ready to commit.
}}]
2237 proc do_include_selection
{} {
2238 global current_diff selected_paths
2240 if {[array size selected_paths
] > 0} {
2242 {Including selected files
} \
2243 [array names selected_paths
]
2244 } elseif
{$current_diff ne
{}} {
2246 "Including [short_path $current_diff]" \
2247 [list
$current_diff]
2251 proc do_include_all
{} {
2255 foreach path
[array names file_states
] {
2256 switch
-- [lindex
$file_states($path) 0] {
2262 _D
{lappend paths
$path}
2266 {Including all modified files
} \
2270 proc revert_helper
{txt paths
} {
2271 global file_states current_diff
2273 if {![lock_index begin-update
]} return
2277 foreach path
$paths {
2278 switch
-glob -- [lindex
$file_states($path) 0] {
2285 lappend pathList
$path
2286 if {$path eq
$current_diff} {
2287 set after
{reshow_diff
;}
2293 set n
[llength
$pathList]
2297 } elseif
{$n == 1} {
2298 set s
"[short_path [lindex $pathList]]"
2300 set s
"these $n files"
2303 set reply
[tk_dialog \
2306 "Revert unincluded changes in $s?
2308 Any unincluded changes will be permanently lost by the revert." \
2318 [concat
$after {set ui_status_value
{Ready.
}}]
2324 proc do_revert_selection
{} {
2325 global current_diff selected_paths
2327 if {[array size selected_paths
] > 0} {
2329 {Reverting selected files
} \
2330 [array names selected_paths
]
2331 } elseif
{$current_diff ne
{}} {
2333 "Reverting [short_path $current_diff]" \
2334 [list
$current_diff]
2338 proc do_signoff
{} {
2341 set me
[committer_ident
]
2342 if {$me eq
{}} return
2344 set sob
"Signed-off-by: $me"
2345 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
2346 if {$last ne
$sob} {
2347 $ui_comm edit separator
2349 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
2350 $ui_comm insert end
"\n"
2352 $ui_comm insert end
"\n$sob"
2353 $ui_comm edit separator
2358 proc do_select_commit_type
{} {
2359 global commit_type selected_commit_type
2361 if {$selected_commit_type eq
{new
}
2362 && [string match amend
* $commit_type]} {
2364 } elseif
{$selected_commit_type eq
{amend
}
2365 && ![string match amend
* $commit_type]} {
2368 # The amend request was rejected...
2370 if {![string match amend
* $commit_type]} {
2371 set selected_commit_type new
2381 global appname copyright
2382 global tcl_patchLevel tk_patchLevel
2386 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2388 label
$w.header
-text "About $appname" \
2390 pack
$w.header
-side top
-fill x
2393 button
$w.buttons.close
-text {Close
} \
2395 -command [list destroy
$w]
2396 pack
$w.buttons.close
-side right
2397 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2400 -text "$appname - a commit creation tool for Git.
2408 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
2410 set v
[exec git
--version]
2412 if {$tcl_patchLevel eq
$tk_patchLevel} {
2413 append v
"Tcl/Tk version $tcl_patchLevel"
2415 append v
"Tcl version $tcl_patchLevel"
2416 append v
", Tk version $tk_patchLevel"
2427 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
2429 bind $w <Visibility
> "grab $w; focus $w"
2430 bind $w <Key-Escape
> "destroy $w"
2431 wm title
$w "About $appname"
2435 proc do_options
{} {
2436 global appname gitdir font_descs
2437 global repo_config global_config
2438 global repo_config_new global_config_new
2440 array
unset repo_config_new
2441 array
unset global_config_new
2442 foreach name
[array names repo_config
] {
2443 set repo_config_new
($name) $repo_config($name)
2446 foreach name
[array names repo_config
] {
2448 gui.diffcontext
{continue}
2450 set repo_config_new
($name) $repo_config($name)
2452 foreach name
[array names global_config
] {
2453 set global_config_new
($name) $global_config($name)
2455 set reponame
[lindex
[file split \
2456 [file normalize
[file dirname $gitdir]]] \
2459 set w .options_editor
2461 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2463 label
$w.header
-text "$appname Options" \
2465 pack
$w.header
-side top
-fill x
2468 button
$w.buttons.restore
-text {Restore Defaults
} \
2470 -command do_restore_defaults
2471 pack
$w.buttons.restore
-side left
2472 button
$w.buttons.save
-text Save \
2474 -command [list do_save_config
$w]
2475 pack
$w.buttons.save
-side right
2476 button
$w.buttons.cancel
-text {Cancel
} \
2478 -command [list destroy
$w]
2479 pack
$w.buttons.cancel
-side right
2480 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2482 labelframe
$w.repo
-text "$reponame Repository" \
2484 -relief raised
-borderwidth 2
2485 labelframe
$w.global
-text {Global
(All Repositories
)} \
2487 -relief raised
-borderwidth 2
2488 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
2489 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
2492 {b partialinclude
{Allow Partially Included Files
}}
2493 {b pullsummary
{Show Pull Summary
}}
2494 {b trustmtime
{Trust File Modification Timestamps
}}
2495 {i diffcontext
{Number of Diff Context Lines
}}
2497 set type [lindex
$option 0]
2498 set name
[lindex
$option 1]
2499 set text
[lindex
$option 2]
2500 foreach f
{repo global
} {
2503 checkbutton
$w.
$f.
$name -text $text \
2504 -variable ${f}_config_new
(gui.
$name) \
2508 pack
$w.
$f.
$name -side top
-anchor w
2512 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
2513 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
2514 spinbox
$w.
$f.
$name.v \
2515 -textvariable ${f}_config_new
(gui.
$name) \
2516 -from 1 -to 99 -increment 1 \
2519 pack
$w.
$f.
$name.v
-side right
-anchor e
2520 pack
$w.
$f.
$name -side top
-anchor w
-fill x
2526 set all_fonts
[lsort
[font families
]]
2527 foreach option
$font_descs {
2528 set name
[lindex
$option 0]
2529 set font
[lindex
$option 1]
2530 set text
[lindex
$option 2]
2532 set global_config_new
(gui.
$font^^family
) \
2533 [font configure
$font -family]
2534 set global_config_new
(gui.
$font^^size
) \
2535 [font configure
$font -size]
2537 frame
$w.global.
$name
2538 label
$w.global.
$name.l
-text "$text:" -font font_ui
2539 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
2540 eval tk_optionMenu
$w.global.
$name.family \
2541 global_config_new
(gui.
$font^^family
) \
2543 spinbox
$w.global.
$name.size \
2544 -textvariable global_config_new
(gui.
$font^^size
) \
2545 -from 2 -to 80 -increment 1 \
2548 pack
$w.global.
$name.size
-side right
-anchor e
2549 pack
$w.global.
$name.family
-side right
-anchor e
2550 pack
$w.global.
$name -side top
-anchor w
-fill x
2553 bind $w <Visibility
> "grab $w; focus $w"
2554 bind $w <Key-Escape
> "destroy $w"
2555 wm title
$w "$appname ($reponame): Options"
2559 proc do_restore_defaults
{} {
2560 global font_descs default_config repo_config
2561 global repo_config_new global_config_new
2563 foreach name
[array names default_config
] {
2564 set repo_config_new
($name) $default_config($name)
2565 set global_config_new
($name) $default_config($name)
2568 foreach option
$font_descs {
2569 set name
[lindex
$option 0]
2570 set repo_config
(gui.
$name) $default_config(gui.
$name)
2574 foreach option
$font_descs {
2575 set name
[lindex
$option 0]
2576 set font
[lindex
$option 1]
2577 set global_config_new
(gui.
$font^^family
) \
2578 [font configure
$font -family]
2579 set global_config_new
(gui.
$font^^size
) \
2580 [font configure
$font -size]
2584 proc do_save_config
{w
} {
2585 if {[catch
{save_config
} err
]} {
2586 error_popup
"Failed to completely save options:\n\n$err"
2592 proc do_windows_shortcut
{} {
2593 global gitdir appname argv0
2595 set reponame
[lindex
[file split \
2596 [file normalize
[file dirname $gitdir]]] \
2600 set desktop
[exec cygpath \
2608 set fn
[tk_getSaveFile \
2610 -title "$appname ($reponame): Create Desktop Icon" \
2611 -initialdir $desktop \
2612 -initialfile "Git $reponame.bat"]
2616 set sh
[exec cygpath \
2621 set me
[exec cygpath \
2625 set gd
[exec cygpath \
2629 regsub
-all ' $me "'\\''" me
2630 regsub -all ' $gd "'\\''" gd
2631 puts -nonewline $fd "\"$sh\" --login -c \""
2632 puts -nonewline $fd "GIT_DIR='$gd'"
2633 puts -nonewline $fd " '$me'"
2637 error_popup "Cannot write script:\n\n$err"
2642 proc do_macosx_app {} {
2643 global gitdir appname argv0 env
2645 set reponame [lindex [file split \
2646 [file normalize [file dirname $gitdir]]] \
2649 set fn [tk_getSaveFile \
2651 -title "$appname ($reponame): Create Desktop Icon" \
2652 -initialdir [file join $env(HOME) Desktop] \
2653 -initialfile "Git $reponame.app"]
2656 set Contents [file join $fn Contents]
2657 set MacOS [file join $Contents MacOS]
2658 set exe [file join $MacOS git-gui]
2662 set fd [open [file join $Contents Info.plist] w]
2663 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
2664 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2665 <plist version="1.0">
2667 <key>CFBundleDevelopmentRegion</key>
2668 <string>English</string>
2669 <key>CFBundleExecutable</key>
2670 <string>git-gui</string>
2671 <key>CFBundleIdentifier</key>
2672 <string>org.spearce.git-gui</string>
2673 <key>CFBundleInfoDictionaryVersion</key>
2674 <string>6.0</string>
2675 <key>CFBundlePackageType</key>
2676 <string>APPL</string>
2677 <key>CFBundleSignature</key>
2678 <string>????</string>
2679 <key>CFBundleVersion</key>
2680 <string>1.0</string>
2681 <key>NSPrincipalClass</key>
2682 <string>NSApplication</string>
2687 set fd [open $exe w]
2688 set gd [file normalize $gitdir]
2689 set ep [file normalize [exec git --exec-path]]
2690 regsub -all ' $gd "'\\''" gd
2691 regsub
-all ' $ep "'\\''" ep
2692 puts $fd "#!/bin/sh"
2693 foreach name
[array names env
] {
2694 if {[string match GIT_
* $name]} {
2695 regsub
-all ' $env($name) "'\\''" v
2696 puts $fd "export $name='$v'"
2699 puts $fd "export PATH
='$ep':\
$PATH"
2700 puts $fd "export GIT_DIR
='$gd'"
2701 puts $fd "exec [file normalize
$argv0]"
2704 file attributes $exe -permissions u+x,g+x,o+x
2706 error_popup "Cannot
write icon
:\n\n$err"
2711 proc toggle_or_diff {w x y} {
2712 global file_states file_lists current_diff ui_index ui_other
2713 global last_clicked selected_paths
2715 set pos [split [$w index @$x,$y] .]
2716 set lno [lindex $pos 0]
2717 set col [lindex $pos 1]
2718 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2724 set last_clicked [list $w $lno]
2725 array unset selected_paths
2726 $ui_index tag remove in_sel 0.0 end
2727 $ui_other tag remove in_sel 0.0 end
2730 if {$current_diff eq $path} {
2731 set after {reshow_diff;}
2735 switch -glob -- [lindex $file_states($path) 0] {
2742 "Removing
[short_path
$path] from commit
" \
2744 [concat $after {set ui_status_value {Ready.}}]
2748 "Including
[short_path
$path]" \
2750 [concat $after {set ui_status_value {Ready.}}]
2754 show_diff $path $w $lno
2758 proc add_one_to_selection {w x y} {
2760 global last_clicked selected_paths
2762 set pos [split [$w index @$x,$y] .]
2763 set lno [lindex $pos 0]
2764 set col [lindex $pos 1]
2765 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2771 set last_clicked [list $w $lno]
2772 if {[catch {set in_sel $selected_paths($path)}]} {
2776 unset selected_paths($path)
2777 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2779 set selected_paths($path) 1
2780 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2784 proc add_range_to_selection {w x y} {
2786 global last_clicked selected_paths
2788 if {[lindex $last_clicked 0] ne $w} {
2789 toggle_or_diff $w $x $y
2793 set pos [split [$w index @$x,$y] .]
2794 set lno [lindex $pos 0]
2795 set lc [lindex $last_clicked 1]
2804 foreach path [lrange $file_lists($w) \
2805 [expr {$begin - 1}] \
2806 [expr {$end - 1}]] {
2807 set selected_paths($path) 1
2809 $w tag add in_sel $begin.0 [expr {$end + 1}].0
2812 ######################################################################
2816 set cursor_ptr arrow
2817 font create font_diff -family Courier -size 10
2821 eval font configure font_ui [font actual [.dummy cget -font]]
2825 font create font_uibold
2826 font create font_diffbold
2831 } elseif {[is_MacOSX]} {
2839 proc apply_config {} {
2840 global repo_config font_descs
2842 foreach option $font_descs {
2843 set name [lindex $option 0]
2844 set font [lindex $option 1]
2846 foreach {cn cv} $repo_config(gui.$name) {
2847 font configure $font $cn $cv
2850 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
2852 foreach {cn cv} [font configure $font] {
2853 font configure ${font}bold $cn $cv
2855 font configure ${font}bold -weight bold
2859 set default_config(gui.trustmtime) false
2860 set default_config(gui.pullsummary) true
2861 set default_config(gui.partialinclude) false
2862 set default_config(gui.diffcontext) 5
2863 set default_config(gui.fontui) [font configure font_ui]
2864 set default_config(gui.fontdiff) [font configure font_diff]
2866 {fontui font_ui {Main Font}}
2867 {fontdiff font_diff {Diff/Console Font}}
2872 ######################################################################
2878 menu .mbar -tearoff 0
2879 .mbar add cascade -label Repository -menu .mbar.repository
2880 .mbar add cascade -label Edit -menu .mbar.edit
2881 .mbar add cascade -label Commit -menu .mbar.commit
2882 if {!$single_commit} {
2883 .mbar add cascade -label Fetch -menu .mbar.fetch
2884 .mbar add cascade -label Pull -menu .mbar.pull
2885 .mbar add cascade -label Push -menu .mbar.push
2887 . configure -menu .mbar
2889 # -- Repository Menu
2891 menu .mbar.repository
2892 .mbar.repository add command \
2893 -label {Visualize Current Branch} \
2894 -command {do_gitk {}} \
2897 .mbar.repository add command \
2898 -label {Visualize All Branches} \
2899 -command {do_gitk {--all}} \
2902 .mbar.repository add separator
2904 if {!$single_commit} {
2905 .mbar.repository add command -label {Repack Database} \
2906 -command do_repack \
2909 .mbar.repository add command -label {Verify Database} \
2910 -command do_fsck_objects \
2913 .mbar.repository add separator
2916 .mbar.repository add command \
2917 -label {Create Desktop Icon} \
2918 -command do_windows_shortcut \
2920 } elseif {[is_MacOSX]} {
2921 .mbar.repository add command \
2922 -label {Create Desktop Icon} \
2923 -command do_macosx_app \
2927 .mbar.repository add command -label Quit \
2929 -accelerator $M1T-Q \
2935 .mbar.edit add command -label Undo \
2936 -command {catch {[focus] edit undo}} \
2937 -accelerator $M1T-Z \
2939 .mbar.edit add command -label Redo \
2940 -command {catch {[focus] edit redo}} \
2941 -accelerator $M1T-Y \
2943 .mbar.edit add separator
2944 .mbar.edit add command -label Cut \
2945 -command {catch {tk_textCut [focus]}} \
2946 -accelerator $M1T-X \
2948 .mbar.edit add command -label Copy \
2949 -command {catch {tk_textCopy [focus]}} \
2950 -accelerator $M1T-C \
2952 .mbar.edit add command -label Paste \
2953 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2954 -accelerator $M1T-V \
2956 .mbar.edit add command -label Delete \
2957 -command {catch {[focus] delete sel.first sel.last}} \
2960 .mbar.edit add separator
2961 .mbar.edit add command -label {Select All} \
2962 -command {catch {[focus] tag add sel 0.0 end}} \
2963 -accelerator $M1T-A \
2970 .mbar.commit add radiobutton \
2971 -label {New Commit} \
2972 -command do_select_commit_type \
2973 -variable selected_commit_type \
2976 lappend disable_on_lock \
2977 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2979 .mbar.commit add radiobutton \
2980 -label {Amend Last Commit} \
2981 -command do_select_commit_type \
2982 -variable selected_commit_type \
2985 lappend disable_on_lock \
2986 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2988 .mbar.commit add separator
2990 .mbar.commit add command -label Rescan \
2991 -command do_rescan \
2994 lappend disable_on_lock \
2995 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2997 .mbar.commit add command -label {Include In Commit} \
2998 -command do_include_selection \
3000 lappend disable_on_lock \
3001 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3003 .mbar.commit add command -label {Include All In Commit} \
3004 -command do_include_all \
3005 -accelerator $M1T-I \
3007 lappend disable_on_lock \
3008 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3010 .mbar.commit add command -label {Remove From Commit} \
3011 -command do_remove_selection \
3013 lappend disable_on_lock \
3014 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3016 .mbar.commit add command -label {Revert Changes} \
3017 -command do_revert_selection \
3019 lappend disable_on_lock \
3020 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3022 .mbar.commit add separator
3024 .mbar.commit add command -label {Sign Off} \
3025 -command do_signoff \
3026 -accelerator $M1T-S \
3029 .mbar.commit add command -label Commit \
3030 -command do_commit \
3031 -accelerator $M1T-Return \
3033 lappend disable_on_lock \
3034 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3036 # -- Transport menus
3038 if {!$single_commit} {
3045 # -- Apple Menu (Mac OS X only)
3047 .mbar add cascade -label Apple -menu .mbar.apple
3050 .mbar.apple add command -label "About
$appname" \
3053 .mbar.apple add command -label "$appname Options...
" \
3054 -command do_options \
3059 .mbar.edit add separator
3060 .mbar.edit add command -label {Options...} \
3061 -command do_options \
3066 .mbar add cascade -label Help -menu .mbar.help
3069 .mbar.help add command -label "About
$appname" \
3081 -text {Current Branch:} \
3086 -textvariable current_branch \
3090 pack .branch.l1 -side left
3091 pack .branch.cb -side left -fill x
3092 pack .branch -side top -fill x
3094 # -- Main Window Layout
3096 panedwindow .vpane -orient vertical
3097 panedwindow .vpane.files -orient horizontal
3098 .vpane add .vpane.files -sticky nsew -height 100 -width 400
3099 pack .vpane -anchor n -side top -fill both -expand 1
3101 # -- Index File List
3103 frame .vpane.files.index -height 100 -width 400
3104 label .vpane.files.index.title -text {Modified Files} \
3107 text $ui_index -background white -borderwidth 0 \
3108 -width 40 -height 10 \
3110 -cursor $cursor_ptr \
3111 -yscrollcommand {.vpane.files.index.sb set} \
3113 scrollbar .vpane.files.index.sb -command [list $ui_index yview]
3114 pack .vpane.files.index.title -side top -fill x
3115 pack .vpane.files.index.sb -side right -fill y
3116 pack $ui_index -side left -fill both -expand 1
3117 .vpane.files add .vpane.files.index -sticky nsew
3119 # -- Other (Add) File List
3121 frame .vpane.files.other -height 100 -width 100
3122 label .vpane.files.other.title -text {Untracked Files} \
3125 text $ui_other -background white -borderwidth 0 \
3126 -width 40 -height 10 \
3128 -cursor $cursor_ptr \
3129 -yscrollcommand {.vpane.files.other.sb set} \
3131 scrollbar .vpane.files.other.sb -command [list $ui_other yview]
3132 pack .vpane.files.other.title -side top -fill x
3133 pack .vpane.files.other.sb -side right -fill y
3134 pack $ui_other -side left -fill both -expand 1
3135 .vpane.files add .vpane.files.other -sticky nsew
3137 foreach i [list $ui_index $ui_other] {
3138 $i tag conf in_diff -font font_uibold
3139 $i tag conf in_sel \
3140 -background [$i cget -foreground] \
3141 -foreground [$i cget -background]
3145 # -- Diff and Commit Area
3147 frame .vpane.lower -height 300 -width 400
3148 frame .vpane.lower.commarea
3149 frame .vpane.lower.diff -relief sunken -borderwidth 1
3150 pack .vpane.lower.commarea -side top -fill x
3151 pack .vpane.lower.diff -side bottom -fill both -expand 1
3152 .vpane add .vpane.lower -stick nsew
3154 # -- Commit Area Buttons
3156 frame .vpane.lower.commarea.buttons
3157 label .vpane.lower.commarea.buttons.l -text {} \
3161 pack .vpane.lower.commarea.buttons.l -side top -fill x
3162 pack .vpane.lower.commarea.buttons -side left -fill y
3164 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
3165 -command do_rescan \
3167 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3168 lappend disable_on_lock \
3169 {.vpane.lower.commarea.buttons.rescan conf -state}
3171 button .vpane.lower.commarea.buttons.incall -text {Include All} \
3172 -command do_include_all \
3174 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3175 lappend disable_on_lock \
3176 {.vpane.lower.commarea.buttons.incall conf -state}
3178 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
3179 -command do_signoff \
3181 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3183 button .vpane.lower.commarea.buttons.commit -text {Commit} \
3184 -command do_commit \
3186 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3187 lappend disable_on_lock \
3188 {.vpane.lower.commarea.buttons.commit conf -state}
3190 # -- Commit Message Buffer
3192 frame .vpane.lower.commarea.buffer
3193 frame .vpane.lower.commarea.buffer.header
3194 set ui_comm .vpane.lower.commarea.buffer.t
3195 set ui_coml .vpane.lower.commarea.buffer.header.l
3196 radiobutton .vpane.lower.commarea.buffer.header.new \
3197 -text {New Commit} \
3198 -command do_select_commit_type \
3199 -variable selected_commit_type \
3202 lappend disable_on_lock \
3203 [list .vpane.lower.commarea.buffer.header.new conf -state]
3204 radiobutton .vpane.lower.commarea.buffer.header.amend \
3205 -text {Amend Last Commit} \
3206 -command do_select_commit_type \
3207 -variable selected_commit_type \
3210 lappend disable_on_lock \
3211 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3216 proc trace_commit_type {varname args} {
3217 global ui_coml commit_type
3218 switch -glob -- $commit_type {
3219 initial {set txt {Initial Commit Message:}}
3220 amend {set txt {Amended Commit Message:}}
3221 amend-initial {set txt {Amended Initial Commit Message:}}
3222 amend-merge {set txt {Amended Merge Commit Message:}}
3223 merge {set txt {Merge Commit Message:}}
3224 * {set txt {Commit Message:}}
3226 $ui_coml conf -text $txt
3228 trace add variable commit_type write trace_commit_type
3229 pack $ui_coml -side left -fill x
3230 pack .vpane.lower.commarea.buffer.header.amend -side right
3231 pack .vpane.lower.commarea.buffer.header.new -side right
3233 text $ui_comm -background white -borderwidth 1 \
3236 -autoseparators true \
3238 -width 75 -height 9 -wrap none \
3240 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3241 scrollbar .vpane.lower.commarea.buffer.sby \
3242 -command [list $ui_comm yview]
3243 pack .vpane.lower.commarea.buffer.header -side top -fill x
3244 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3245 pack $ui_comm -side left -fill y
3246 pack .vpane.lower.commarea.buffer -side left -fill y
3248 # -- Commit Message Buffer Context Menu
3250 set ctxm .vpane.lower.commarea.buffer.ctxm
3251 menu $ctxm -tearoff 0
3255 -command {tk_textCut $ui_comm}
3259 -command {tk_textCopy $ui_comm}
3263 -command {tk_textPaste $ui_comm}
3267 -command {$ui_comm delete sel.first sel.last}
3270 -label {Select All} \
3272 -command {$ui_comm tag add sel 0.0 end}
3277 $ui_comm tag add sel 0.0 end
3278 tk_textCopy $ui_comm
3279 $ui_comm tag remove sel 0.0 end
3286 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
3291 set diff_actions [list]
3292 proc trace_current_diff {varname args} {
3293 global current_diff diff_actions file_states
3294 if {$current_diff eq {}} {
3301 set s [mapdesc [lindex $file_states($p) 0] $p]
3303 set p [escape_path $p]
3307 .vpane.lower.diff.header.status configure -text $s
3308 .vpane.lower.diff.header.file configure -text $f
3309 .vpane.lower.diff.header.path configure -text $p
3310 foreach w $diff_actions {
3314 trace add variable current_diff write trace_current_diff
3316 frame .vpane.lower.diff.header -background orange
3317 label .vpane.lower.diff.header.status \
3318 -background orange \
3319 -width $max_status_desc \
3323 label .vpane.lower.diff.header.file \
3324 -background orange \
3328 label .vpane.lower.diff.header.path \
3329 -background orange \
3333 pack .vpane.lower.diff.header.status -side left
3334 pack .vpane.lower.diff.header.file -side left
3335 pack .vpane.lower.diff.header.path -fill x
3336 set ctxm .vpane.lower.diff.header.ctxm
3337 menu $ctxm -tearoff 0
3348 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3349 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
3353 frame .vpane.lower.diff.body
3354 set ui_diff .vpane.lower.diff.body.t
3355 text $ui_diff -background white -borderwidth 0 \
3356 -width 80 -height 15 -wrap none \
3358 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3359 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3361 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3362 -command [list $ui_diff xview]
3363 scrollbar .vpane.lower.diff.body.sby -orient vertical \
3364 -command [list $ui_diff yview]
3365 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3366 pack .vpane.lower.diff.body.sby -side right -fill y
3367 pack $ui_diff -side left -fill both -expand 1
3368 pack .vpane.lower.diff.header -side top -fill x
3369 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3371 $ui_diff tag conf d_@ -font font_diffbold
3372 $ui_diff tag conf d_+ -foreground blue
3373 $ui_diff tag conf d_- -foreground red
3374 $ui_diff tag conf d_++ -foreground {#00a000}
3375 $ui_diff tag conf d_-- -foreground {#a000a0}
3376 $ui_diff tag conf d_+- \
3378 -background {light goldenrod yellow}
3379 $ui_diff tag conf d_-+ \
3383 # -- Diff Body Context Menu
3385 set ctxm .vpane.lower.diff.body.ctxm
3386 menu $ctxm -tearoff 0
3390 -command {tk_textCopy $ui_diff}
3391 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3393 -label {Select All} \
3395 -command {$ui_diff tag add sel 0.0 end}
3396 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3401 $ui_diff tag add sel 0.0 end
3402 tk_textCopy $ui_diff
3403 $ui_diff tag remove sel 0.0 end
3405 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3408 -label {Decrease Font Size} \
3410 -command {incr_font_size font_diff -1}
3411 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3413 -label {Increase Font Size} \
3415 -command {incr_font_size font_diff 1}
3416 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3419 -label {Show Less Context} \
3421 -command {if {$repo_config(gui.diffcontext) >= 2} {
3422 incr repo_config(gui.diffcontext) -1
3425 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3427 -label {Show More Context} \
3430 incr repo_config(gui.diffcontext)
3433 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3435 $ctxm add command -label {Options...} \
3438 bind_button3 $ui_diff "tk_popup
$ctxm %X
%Y
"
3442 set ui_status_value {Initializing...}
3443 label .status -textvariable ui_status_value \
3449 pack .status -anchor w -side bottom -fill x
3454 set gm $repo_config(gui.geometry)
3455 wm geometry . [lindex $gm 0]
3456 .vpane sash place 0 \
3457 [lindex [.vpane sash coord 0] 0] \
3459 .vpane.files sash place 0 \
3461 [lindex [.vpane.files sash coord 0] 1]
3467 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3468 bind $ui_comm <$M1B-Key-i> {do_include_all;break}
3469 bind $ui_comm <$M1B-Key-I> {do_include_all;break}
3470 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3471 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3472 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3473 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3474 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3475 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3476 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3477 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3479 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3480 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3481 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3482 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3483 bind $ui_diff <$M1B-Key-v> {break}
3484 bind $ui_diff <$M1B-Key-V> {break}
3485 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3486 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3487 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3488 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3489 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3490 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3492 bind . <Destroy> do_quit
3493 bind all <Key-F5> do_rescan
3494 bind all <$M1B-Key-r> do_rescan
3495 bind all <$M1B-Key-R> do_rescan
3496 bind . <$M1B-Key-s> do_signoff
3497 bind . <$M1B-Key-S> do_signoff
3498 bind . <$M1B-Key-i> do_include_all
3499 bind . <$M1B-Key-I> do_include_all
3500 bind . <$M1B-Key-Return> do_commit
3501 bind all <$M1B-Key-q> do_quit
3502 bind all <$M1B-Key-Q> do_quit
3503 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
3504 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
3505 foreach i [list $ui_index $ui_other] {
3506 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
3507 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
3508 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
3512 set file_lists($ui_index) [list]
3513 set file_lists($ui_other) [list]
3517 set MERGE_HEAD [list]
3520 set current_branch {}
3522 set selected_commit_type new
3524 wm title . "$appname ([file normalize
[file dirname $gitdir]])"
3525 focus -force $ui_comm
3527 # -- Warn the user about environmental problems.
3528 # Cygwin's Tcl does *not* pass its env array
3529 # onto any processes it spawns. This means
3530 # that the git processes get none of our
3531 # environment. That may not work...
3536 set msg "Possible environment issues exist.
3538 The following environment variables are probably
3539 going to be ignored by any Git subprocess run
3543 foreach name [array names env] {
3544 switch -regexp -- $name {
3545 {^GIT_INDEX_FILE$} -
3546 {^GIT_OBJECT_DIRECTORY$} -
3547 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3549 {^GIT_EXTERNAL_DIFF$} -
3553 {^GIT_CONFIG_LOCAL$} -
3554 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3555 append msg " - $name\n"
3558 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3559 append msg " - $name\n"
3561 set suggest_user $name
3565 if {$ignored_env > 0} {
3567 This is due to a known issue with the
3568 Tcl binary distributed by Cygwin.
"
3570 if {$suggest_user ne {}} {
3573 A good replacement
for $suggest_user
3574 is placing values
for the user.name and
3575 user.email settings into your personal
3581 unset ignored_env msg suggest_user name
3584 if {!$single_commit} {
3586 populate_fetch_menu .mbar.fetch
3587 populate_pull_menu .mbar.pull
3588 populate_push_menu .mbar.push
3590 lock_index begin-read