2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright (C) 2006 Shawn Pearce, Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
10 set appname
[lindex
[file split $argv0] end
]
13 ######################################################################
17 proc is_many_config
{name
} {
18 switch
-glob -- $name {
27 proc load_config
{include_global
} {
28 global repo_config global_config default_config
30 array
unset global_config
31 if {$include_global} {
33 set fd_rc
[open
"| git repo-config --global --list" r
]
34 while {[gets
$fd_rc line
] >= 0} {
35 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
36 if {[is_many_config
$name]} {
37 lappend global_config
($name) $value
39 set global_config
($name) $value
47 array
unset repo_config
49 set fd_rc
[open
"| git repo-config --list" r
]
50 while {[gets
$fd_rc line
] >= 0} {
51 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
52 if {[is_many_config
$name]} {
53 lappend repo_config
($name) $value
55 set repo_config
($name) $value
62 foreach name
[array names default_config
] {
63 if {[catch
{set v
$global_config($name)}]} {
64 set global_config
($name) $default_config($name)
66 if {[catch
{set v
$repo_config($name)}]} {
67 set repo_config
($name) $default_config($name)
73 global default_config font_descs
74 global repo_config global_config
75 global repo_config_new global_config_new
77 foreach option
$font_descs {
78 set name
[lindex
$option 0]
79 set font
[lindex
$option 1]
80 font configure
$font \
81 -family $global_config_new(gui.
$font^^family
) \
82 -size $global_config_new(gui.
$font^^size
)
83 font configure
${font}bold \
84 -family $global_config_new(gui.
$font^^family
) \
85 -size $global_config_new(gui.
$font^^size
)
86 set global_config_new
(gui.
$name) [font configure
$font]
87 unset global_config_new
(gui.
$font^^family
)
88 unset global_config_new
(gui.
$font^^size
)
91 foreach name
[array names default_config
] {
92 set value
$global_config_new($name)
93 if {$value ne
$global_config($name)} {
94 if {$value eq
$default_config($name)} {
95 catch
{exec git repo-config
--global --unset $name}
97 regsub
-all "\[{}\]" $value {"} value
98 exec git repo-config --global $name $value
100 set global_config($name) $value
101 if {$value eq $repo_config($name)} {
102 catch {exec git repo-config --unset $name}
103 set repo_config($name) $value
108 foreach name [array names default_config] {
109 set value $repo_config_new($name)
110 if {$value ne $repo_config($name)} {
111 if {$value eq $global_config($name)} {
112 catch {exec git repo-config --unset $name}
114 regsub -all "\
[{}\
]" $value {"} value
115 exec git repo-config
$name $value
117 set repo_config
($name) $value
122 proc error_popup
{msg
} {
123 global gitdir appname
128 append title
[lindex \
129 [file split [file normalize
[file dirname $gitdir]]] \
137 -title "$title: error" \
141 proc info_popup
{msg
} {
142 global gitdir appname
147 append title
[lindex \
148 [file split [file normalize
[file dirname $gitdir]]] \
160 ######################################################################
164 if { [catch
{set gitdir
$env(GIT_DIR
)}]
165 && [catch
{set gitdir
[exec git rev-parse
--git-dir]} err
]} {
166 catch
{wm withdraw .
}
167 error_popup
"Cannot find the git directory:\n\n$err"
170 if {[catch
{cd [file dirname $gitdir]} err
]} {
171 catch
{wm withdraw .
}
172 error_popup
"No working directory [file dirname $gitdir]:\n\n$err"
177 if {$appname eq
{git-citool
}} {
181 ######################################################################
189 set disable_on_lock
[list
]
190 set index_lock_type none
196 proc lock_index
{type} {
197 global index_lock_type disable_on_lock
199 if {$index_lock_type eq
{none
}} {
200 set index_lock_type
$type
201 foreach w
$disable_on_lock {
202 uplevel
#0 $w disabled
205 } elseif
{$index_lock_type eq
{begin-update
} && $type eq
{update
}} {
206 set index_lock_type
$type
212 proc unlock_index
{} {
213 global index_lock_type disable_on_lock
215 set index_lock_type none
216 foreach w
$disable_on_lock {
221 ######################################################################
225 proc repository_state
{hdvar ctvar
} {
227 upvar
$hdvar hd
$ctvar ct
229 if {[catch
{set hd
[exec git rev-parse
--verify HEAD
]}]} {
231 } elseif
{[file exists
[file join $gitdir MERGE_HEAD
]]} {
238 proc rescan
{after
} {
239 global HEAD PARENT commit_type
240 global ui_index ui_other ui_status_value ui_comm
241 global rescan_active file_states
244 if {$rescan_active > 0 ||
![lock_index
read]} return
246 repository_state new_HEAD new_type
247 if {$commit_type eq
{amend
}
248 && $new_type eq
{normal
}
249 && $new_HEAD eq
$HEAD} {
253 set commit_type
$new_type
256 array
unset file_states
258 if {![$ui_comm edit modified
]
259 ||
[string trim
[$ui_comm get
0.0 end
]] eq
{}} {
260 if {[load_message GITGUI_MSG
]} {
261 } elseif
{[load_message MERGE_MSG
]} {
262 } elseif
{[load_message SQUASH_MSG
]} {
264 $ui_comm edit modified false
268 if {$repo_config(gui.trustmtime
) eq
{true
}} {
269 rescan_stage2
{} $after
272 set ui_status_value
{Refreshing
file status...
}
273 set cmd
[list git update-index
]
275 lappend cmd
--unmerged
276 lappend cmd
--ignore-missing
277 lappend cmd
--refresh
278 set fd_rf
[open
"| $cmd" r
]
279 fconfigure
$fd_rf -blocking 0 -translation binary
280 fileevent
$fd_rf readable \
281 [list rescan_stage2
$fd_rf $after]
285 proc rescan_stage2
{fd after
} {
286 global gitdir PARENT commit_type
287 global ui_index ui_other ui_status_value ui_comm
289 global buf_rdi buf_rdf buf_rlo
293 if {![eof
$fd]} return
297 set ls_others
[list | git ls-files
--others -z \
298 --exclude-per-directory=.gitignore
]
299 set info_exclude
[file join $gitdir info exclude
]
300 if {[file readable
$info_exclude]} {
301 lappend ls_others
"--exclude-from=$info_exclude"
309 set ui_status_value
{Scanning
for modified files ...
}
310 set fd_di
[open
"| git diff-index --cached -z $PARENT" r
]
311 set fd_df
[open
"| git diff-files -z" r
]
312 set fd_lo
[open
$ls_others r
]
314 fconfigure
$fd_di -blocking 0 -translation binary
315 fconfigure
$fd_df -blocking 0 -translation binary
316 fconfigure
$fd_lo -blocking 0 -translation binary
317 fileevent
$fd_di readable
[list read_diff_index
$fd_di $after]
318 fileevent
$fd_df readable
[list read_diff_files
$fd_df $after]
319 fileevent
$fd_lo readable
[list read_ls_others
$fd_lo $after]
322 proc load_message
{file} {
323 global gitdir ui_comm
325 set f
[file join $gitdir $file]
326 if {[file isfile
$f]} {
327 if {[catch
{set fd
[open
$f r
]}]} {
330 set content
[string trim
[read $fd]]
332 $ui_comm delete
0.0 end
333 $ui_comm insert end
$content
339 proc read_diff_index
{fd after
} {
342 append buf_rdi
[read $fd]
344 set n
[string length
$buf_rdi]
346 set z1
[string first
"\0" $buf_rdi $c]
349 set z2
[string first
"\0" $buf_rdi $z1]
355 [string range
$buf_rdi $z1 $z2] \
356 [string index
$buf_rdi [expr {$z1 - 2}]]_
360 set buf_rdi
[string range
$buf_rdi $c end
]
365 rescan_done
$fd buf_rdi
$after
368 proc read_diff_files
{fd after
} {
371 append buf_rdf
[read $fd]
373 set n
[string length
$buf_rdf]
375 set z1
[string first
"\0" $buf_rdf $c]
378 set z2
[string first
"\0" $buf_rdf $z1]
384 [string range
$buf_rdf $z1 $z2] \
385 _
[string index
$buf_rdf [expr {$z1 - 2}]]
389 set buf_rdf
[string range
$buf_rdf $c end
]
394 rescan_done
$fd buf_rdf
$after
397 proc read_ls_others
{fd after
} {
400 append buf_rlo
[read $fd]
401 set pck
[split $buf_rlo "\0"]
402 set buf_rlo
[lindex
$pck end
]
403 foreach p
[lrange
$pck 0 end-1
] {
406 rescan_done
$fd buf_rlo
$after
409 proc rescan_done
{fd buf after
} {
411 global file_states repo_config
414 if {![eof
$fd]} return
417 if {[incr rescan_active
-1] > 0} return
423 if {$repo_config(gui.partialinclude
) ne
{true
}} {
425 foreach path
[array names file_states
] {
426 switch
-- [lindex
$file_states($path) 0] {
428 MM
{lappend pathList
$path}
431 if {$pathList ne
{}} {
433 "Updating included files" \
435 [concat
{reshow_diff
;} $after]
444 proc prune_selection
{} {
445 global file_states selected_paths
447 foreach path
[array names selected_paths
] {
448 if {[catch
{set still_here
$file_states($path)}]} {
449 unset selected_paths
($path)
454 ######################################################################
459 global ui_diff current_diff ui_index ui_other
461 $ui_diff conf
-state normal
462 $ui_diff delete
0.0 end
463 $ui_diff conf
-state disabled
467 $ui_index tag remove in_diff
0.0 end
468 $ui_other tag remove in_diff
0.0 end
471 proc reshow_diff
{} {
472 global current_diff ui_status_value file_states
474 if {$current_diff eq
{}
475 ||
[catch
{set s
$file_states($current_diff)}]} {
478 show_diff
$current_diff
482 proc handle_empty_diff
{} {
483 global current_diff file_states file_lists
485 set path
$current_diff
486 set s
$file_states($path)
487 if {[lindex
$s 0] ne
{_M
}} return
489 info_popup
"No differences detected.
491 [short_path $path] has no changes.
493 The modification date of this file was updated
494 by another application and you currently have
495 the Trust File Modification Timestamps option
496 enabled, so Git did not automatically detect
497 that there are no content differences in this
500 This file will now be removed from the modified
501 files list, to prevent possible confusion.
503 if {[catch
{exec git update-index
-- $path} err
]} {
504 error_popup
"Failed to refresh index:\n\n$err"
508 set old_w
[mapcol
[lindex
$file_states($path) 0] $path]
509 set lno
[lsearch
-sorted $file_lists($old_w) $path]
511 set file_lists
($old_w) \
512 [lreplace
$file_lists($old_w) $lno $lno]
514 $old_w conf
-state normal
515 $old_w delete
$lno.0 [expr {$lno + 1}].0
516 $old_w conf
-state disabled
520 proc show_diff
{path
{w
{}} {lno
{}}} {
521 global file_states file_lists
522 global PARENT diff_3way diff_active repo_config
523 global ui_diff current_diff ui_status_value
525 if {$diff_active ||
![lock_index
read]} return
528 if {$w eq
{} ||
$lno == {}} {
529 foreach w
[array names file_lists
] {
530 set lno
[lsearch
-sorted $file_lists($w) $path]
537 if {$w ne
{} && $lno >= 1} {
538 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
541 set s
$file_states($path)
545 set current_diff
$path
546 set ui_status_value
"Loading diff of [escape_path $path]..."
548 set cmd
[list | git diff-index
]
549 lappend cmd
--no-color
550 if {$repo_config(gui.diffcontext
) > 0} {
551 lappend cmd
"-U$repo_config(gui.diffcontext)"
561 set fd
[open
$path r
]
562 set content
[read $fd]
567 set ui_status_value
"Unable to display [escape_path $path]"
568 error_popup
"Error loading file:\n\n$err"
571 $ui_diff conf
-state normal
572 $ui_diff insert end
$content
573 $ui_diff conf
-state disabled
576 set ui_status_value
{Ready.
}
585 if {[catch
{set fd
[open
$cmd r
]} err
]} {
588 set ui_status_value
"Unable to display [escape_path $path]"
589 error_popup
"Error loading diff:\n\n$err"
593 fconfigure
$fd -blocking 0 -translation auto
594 fileevent
$fd readable
[list read_diff
$fd]
597 proc read_diff
{fd
} {
598 global ui_diff ui_status_value diff_3way diff_active
601 while {[gets
$fd line
] >= 0} {
602 if {[string match
{diff --git *} $line]} continue
603 if {[string match
{diff --combined *} $line]} continue
604 if {[string match
{--- *} $line]} continue
605 if {[string match
{+++ *} $line]} continue
606 if {[string match index
* $line]} {
607 if {[string first
, $line] >= 0} {
612 $ui_diff conf
-state normal
614 set x
[string index
$line 0]
619 default
{set tags
{}}
622 set x
[string range
$line 0 1]
624 default
{set tags
{}}
626 "++" {set tags dp
; set x
" +"}
627 " +" {set tags
{di bold
}; set x
"++"}
628 "+ " {set tags dni
; set x
"-+"}
629 "--" {set tags dm
; set x
" -"}
630 " -" {set tags
{dm bold
}; set x
"--"}
631 "- " {set tags di
; set x
"+-"}
632 default
{set tags
{}}
634 set line
[string replace
$line 0 1 $x]
636 $ui_diff insert end
$line $tags
637 $ui_diff insert end
"\n"
638 $ui_diff conf
-state disabled
645 set ui_status_value
{Ready.
}
647 if {$repo_config(gui.trustmtime
) eq
{true
}
648 && [$ui_diff index end
] eq
{2.0}} {
654 ######################################################################
658 proc load_last_commit
{} {
659 global HEAD PARENT commit_type ui_comm
661 if {$commit_type eq
{amend
}} return
662 if {$commit_type ne
{normal
}} {
663 error_popup
"Can't amend a $commit_type commit."
671 set fd
[open
"| git cat-file commit $HEAD" r
]
672 while {[gets
$fd line
] > 0} {
673 if {[string match
{parent
*} $line]} {
674 set parent
[string range
$line 7 end
]
678 set msg
[string trim
[read $fd]]
681 error_popup
"Error loading commit data for amend:\n\n$err"
685 if {$parent_count == 0} {
686 set commit_type amend
689 rescan
{set ui_status_value
{Ready.
}}
690 } elseif
{$parent_count == 1} {
691 set commit_type amend
693 $ui_comm delete
0.0 end
694 $ui_comm insert end
$msg
695 $ui_comm edit modified false
697 rescan
{set ui_status_value
{Ready.
}}
699 error_popup
{You can
't amend a merge commit.}
704 proc commit_tree {} {
705 global HEAD commit_type file_states ui_comm repo_config
707 if {![lock_index update]} return
709 # -- Our in memory state should match the repository.
711 repository_state curHEAD cur_type
712 if {$commit_type eq {amend}
713 && $cur_type eq {normal}
714 && $curHEAD eq $HEAD} {
715 } elseif {$commit_type ne $cur_type || $HEAD ne $curHEAD} {
716 error_popup {Last scanned state does not match repository state.
718 Its highly likely that another Git program modified the
719 repository since the last scan. A rescan is required
722 A rescan will be automatically started now.
725 rescan {set ui_status_value {Ready.}}
729 # -- At least one file should differ in the index.
732 foreach path [array names file_states] {
733 switch -glob -- [lindex $file_states($path) 0] {
737 M? {set files_ready 1; break}
739 error_popup "Unmerged files cannot be committed.
741 File [short_path $path] has merge conflicts.
742 You must resolve them and include the file before committing.
748 error_popup "Unknown file state [lindex $s 0] detected.
750 File [short_path $path] cannot be committed by this program.
756 error_popup {No included files to commit.
758 You must include at least 1 file before you can commit.
764 # -- A message is required.
766 set msg [string trim [$ui_comm get 1.0 end]]
768 error_popup {Please supply a commit message.
770 A good commit message has the following format:
772 - First line: Describe in one sentance what you did.
774 - Remaining lines: Describe why this change is good.
780 # -- Update included files if partialincludes are off.
782 if {$repo_config(gui.partialinclude) ne {true}} {
784 foreach path [array names file_states] {
785 switch -glob -- [lindex $file_states($path) 0] {
787 M? {lappend pathList $path}
790 if {$pathList ne {}} {
793 "Updating included files" \
795 [concat {lock_index update;} \
796 [list commit_prehook $curHEAD $msg]]
801 commit_prehook $curHEAD $msg
804 proc commit_prehook {curHEAD msg} {
805 global tcl_platform gitdir ui_status_value pch_error
807 # On Cygwin [file executable] might lie so we need to ask
808 # the shell if the hook is executable. Yes that's annoying.
810 set pchook
[file join $gitdir hooks pre-commit
]
811 if {$tcl_platform(platform
) eq
{windows
}
812 && [file isfile
$pchook]} {
813 set pchook
[list sh
-c [concat \
814 "if test -x \"$pchook\";" \
815 "then exec \"$pchook\" 2>&1;" \
817 } elseif
{[file executable
$pchook]} {
818 set pchook
[list
$pchook |
& cat]
820 commit_writetree
$curHEAD $msg
824 set ui_status_value
{Calling pre-commit hook...
}
826 set fd_ph
[open
"| $pchook" r
]
827 fconfigure
$fd_ph -blocking 0 -translation binary
828 fileevent
$fd_ph readable \
829 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
832 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
833 global pch_error ui_status_value
835 append pch_error
[read $fd_ph]
836 fconfigure
$fd_ph -blocking 1
838 if {[catch
{close
$fd_ph}]} {
839 set ui_status_value
{Commit declined by pre-commit hook.
}
840 hook_failed_popup pre-commit
$pch_error
843 commit_writetree
$curHEAD $msg
848 fconfigure
$fd_ph -blocking 0
851 proc commit_writetree
{curHEAD msg
} {
852 global ui_status_value
854 set ui_status_value
{Committing changes...
}
855 set fd_wt
[open
"| git write-tree" r
]
856 fileevent
$fd_wt readable \
857 [list commit_committree
$fd_wt $curHEAD $msg]
860 proc commit_committree
{fd_wt curHEAD msg
} {
861 global single_commit gitdir HEAD PARENT commit_type tcl_platform
862 global ui_status_value ui_comm
863 global file_states selected_paths
866 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
867 error_popup
"write-tree failed:\n\n$err"
868 set ui_status_value
{Commit failed.
}
873 # -- Create the commit.
875 set cmd
[list git commit-tree
$tree_id]
877 lappend cmd
-p $PARENT
879 if {$commit_type eq
{merge
}} {
881 set fd_mh
[open
[file join $gitdir MERGE_HEAD
] r
]
882 while {[gets
$fd_mh merge_head
] >= 0} {
883 lappend cmd
-p $merge_head
887 error_popup
"Loading MERGE_HEAD failed:\n\n$err"
888 set ui_status_value
{Commit failed.
}
894 # git commit-tree writes to stderr during initial commit.
895 lappend cmd
2>/dev
/null
898 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
899 error_popup
"commit-tree failed:\n\n$err"
900 set ui_status_value
{Commit failed.
}
905 # -- Update the HEAD ref.
908 if {$commit_type ne
{normal
}} {
909 append reflogm
" ($commit_type)"
911 set i
[string first
"\n" $msg]
913 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
915 append reflogm
{: } $msg
917 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
918 if {[catch
{eval exec $cmd} err
]} {
919 error_popup
"update-ref failed:\n\n$err"
920 set ui_status_value
{Commit failed.
}
925 # -- Cleanup after ourselves.
927 catch
{file delete
[file join $gitdir MERGE_HEAD
]}
928 catch
{file delete
[file join $gitdir MERGE_MSG
]}
929 catch
{file delete
[file join $gitdir SQUASH_MSG
]}
930 catch
{file delete
[file join $gitdir GITGUI_MSG
]}
932 # -- Let rerere do its thing.
934 if {[file isdirectory
[file join $gitdir rr-cache
]]} {
935 catch
{exec git rerere
}
938 # -- Run the post-commit hook.
940 set pchook
[file join $gitdir hooks post-commit
]
941 if {$tcl_platform(platform
) eq
{windows
} && [file isfile
$pchook]} {
942 set pchook
[list sh
-c [concat \
943 "if test -x \"$pchook\";" \
944 "then exec \"$pchook\";" \
946 } elseif
{![file executable
$pchook]} {
950 catch
{exec $pchook &}
953 $ui_comm delete
0.0 end
954 $ui_comm edit modified false
957 if {$single_commit} do_quit
959 # -- Update status without invoking any git commands.
961 set commit_type normal
965 foreach path
[array names file_states
] {
966 set s
$file_states($path)
971 D?
{set m _
[string index
$m 1]}
975 unset file_states
($path)
976 catch
{unset selected_paths
($path)}
978 lset file_states
($path) 0 $m
985 set ui_status_value \
986 "Changes committed as [string range $cmt_id 0 7]."
989 ######################################################################
993 proc fetch_from
{remote
} {
994 set w
[new_console
"fetch $remote" \
995 "Fetching new changes from $remote"]
996 set cmd
[list git fetch
]
1001 proc pull_remote
{remote branch
} {
1002 global HEAD commit_type file_states repo_config
1004 if {![lock_index update
]} return
1006 # -- Our in memory state should match the repository.
1008 repository_state curHEAD cur_type
1009 if {$commit_type ne
$cur_type ||
$HEAD ne
$curHEAD} {
1010 error_popup
{Last scanned state does not match repository state.
1012 Its highly likely that another Git program modified the
1013 repository since our last scan. A rescan is required
1014 before a pull can be started.
1017 rescan
{set ui_status_value
{Ready.
}}
1021 # -- No differences should exist before a pull.
1023 if {[array size file_states
] != 0} {
1024 error_popup
{Uncommitted but modified files are present.
1026 You should not perform a pull with unmodified files
in your working
1027 directory as Git would be unable to recover from an incorrect merge.
1029 Commit or throw away all changes before starting a pull operation.
1035 set w
[new_console
"pull $remote $branch" \
1036 "Pulling new changes from branch $branch in $remote"]
1037 set cmd
[list git pull
]
1038 if {$repo_config(gui.pullsummary
) eq
{false
}} {
1039 lappend cmd
--no-summary
1043 console_exec
$w $cmd [list post_pull_remote
$remote $branch]
1046 proc post_pull_remote
{remote branch success
} {
1047 global HEAD PARENT commit_type
1048 global ui_status_value
1052 repository_state HEAD commit_type
1054 set $ui_status_value "Pulling $branch from $remote complete."
1056 set m
"Conflicts detected while pulling $branch from $remote."
1057 rescan
"set ui_status_value {$m}"
1061 proc push_to
{remote
} {
1062 set w
[new_console
"push $remote" \
1063 "Pushing changes to $remote"]
1064 set cmd
[list git push
]
1066 console_exec
$w $cmd
1069 ######################################################################
1073 proc mapcol
{state path
} {
1074 global all_cols ui_other
1076 if {[catch
{set r
$all_cols($state)}]} {
1077 puts
"error: no column for state={$state} $path"
1083 proc mapicon
{state path
} {
1086 if {[catch
{set r
$all_icons($state)}]} {
1087 puts
"error: no icon for state={$state} $path"
1093 proc mapdesc
{state path
} {
1096 if {[catch
{set r
$all_descs($state)}]} {
1097 puts
"error: no desc for state={$state} $path"
1103 proc escape_path
{path
} {
1104 regsub
-all "\n" $path "\\n" path
1108 proc short_path
{path
} {
1109 return [escape_path
[lindex
[file split $path] end
]]
1114 proc merge_state
{path new_state
} {
1115 global file_states next_icon_id
1117 set s0
[string index
$new_state 0]
1118 set s1
[string index
$new_state 1]
1120 if {[catch
{set info
$file_states($path)}]} {
1122 set icon n
[incr next_icon_id
]
1124 set state
[lindex
$info 0]
1125 set icon
[lindex
$info 1]
1129 set s0
[string index
$state 0]
1130 } elseif
{$s0 eq
{*}} {
1135 set s1
[string index
$state 1]
1136 } elseif
{$s1 eq
{*}} {
1140 set file_states
($path) [list
$s0$s1 $icon]
1144 proc display_file
{path state
} {
1145 global file_states file_lists selected_paths rescan_active
1147 set old_m
[merge_state
$path $state]
1148 if {$rescan_active > 0} return
1150 set s
$file_states($path)
1151 set new_m
[lindex
$s 0]
1152 set new_w
[mapcol
$new_m $path]
1153 set old_w
[mapcol
$old_m $path]
1154 set new_icon
[mapicon
$new_m $path]
1156 if {$new_w ne
$old_w} {
1157 set lno
[lsearch
-sorted $file_lists($old_w) $path]
1160 $old_w conf
-state normal
1161 $old_w delete
$lno.0 [expr {$lno + 1}].0
1162 $old_w conf
-state disabled
1165 lappend file_lists
($new_w) $path
1166 set file_lists
($new_w) [lsort
$file_lists($new_w)]
1167 set lno
[lsearch
-sorted $file_lists($new_w) $path]
1169 $new_w conf
-state normal
1170 $new_w image create
$lno.0 \
1171 -align center
-padx 5 -pady 1 \
1172 -name [lindex
$s 1] \
1174 $new_w insert
$lno.1 "[escape_path $path]\n"
1175 if {[catch
{set in_sel
$selected_paths($path)}]} {
1179 $new_w tag add in_sel
$lno.0 [expr {$lno + 1}].0
1181 $new_w conf
-state disabled
1182 } elseif
{$new_icon ne
[mapicon
$old_m $path]} {
1183 $new_w conf
-state normal
1184 $new_w image conf
[lindex
$s 1] -image $new_icon
1185 $new_w conf
-state disabled
1189 proc display_all_files
{} {
1190 global ui_index ui_other
1191 global file_states file_lists
1192 global last_clicked selected_paths
1194 $ui_index conf
-state normal
1195 $ui_other conf
-state normal
1197 $ui_index delete
0.0 end
1198 $ui_other delete
0.0 end
1201 set file_lists
($ui_index) [list
]
1202 set file_lists
($ui_other) [list
]
1204 foreach path
[lsort
[array names file_states
]] {
1205 set s
$file_states($path)
1207 set w
[mapcol
$m $path]
1208 lappend file_lists
($w) $path
1209 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1210 $w image create end \
1211 -align center
-padx 5 -pady 1 \
1212 -name [lindex
$s 1] \
1213 -image [mapicon
$m $path]
1214 $w insert end
"[escape_path $path]\n"
1215 if {[catch
{set in_sel
$selected_paths($path)}]} {
1219 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
1223 $ui_index conf
-state disabled
1224 $ui_other conf
-state disabled
1227 proc update_index
{msg pathList after
} {
1228 global update_index_cp update_index_rsd ui_status_value
1230 if {![lock_index update
]} return
1232 set update_index_cp
0
1233 set update_index_rsd
0
1234 set pathList
[lsort
$pathList]
1235 set totalCnt
[llength
$pathList]
1236 set batch [expr {int
($totalCnt * .01) + 1}]
1237 if {$batch > 25} {set batch 25}
1239 set ui_status_value
[format \
1240 "$msg... %i/%i files (%.2f%%)" \
1244 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1250 fileevent
$fd writable
[list \
1251 write_update_index \
1261 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1262 global update_index_cp update_index_rsd ui_status_value
1263 global file_states current_diff
1265 if {$update_index_cp >= $totalCnt} {
1268 if {$update_index_rsd} reshow_diff
1273 for {set i
$batch} \
1274 {$update_index_cp < $totalCnt && $i > 0} \
1276 set path
[lindex
$pathList $update_index_cp]
1277 incr update_index_cp
1279 switch
-glob -- [lindex
$file_states($path) 0] {
1295 puts
-nonewline $fd $path
1296 puts
-nonewline $fd "\0"
1297 display_file
$path $new
1298 if {$current_diff eq
$path} {
1299 set update_index_rsd
1
1303 set ui_status_value
[format \
1304 "$msg... %i/%i files (%.2f%%)" \
1307 [expr {100.0 * $update_index_cp / $totalCnt}]]
1310 ######################################################################
1312 ## remote management
1314 proc load_all_remotes
{} {
1315 global gitdir all_remotes repo_config
1317 set all_remotes
[list
]
1318 set rm_dir
[file join $gitdir remotes
]
1319 if {[file isdirectory
$rm_dir]} {
1320 set all_remotes
[concat
$all_remotes [glob \
1324 -directory $rm_dir *]]
1327 foreach line
[array names repo_config remote.
*.url
] {
1328 if {[regexp ^remote\.
(.
*)\.url\$
$line line name
]} {
1329 lappend all_remotes
$name
1333 set all_remotes
[lsort
-unique $all_remotes]
1336 proc populate_remote_menu
{m pfx op
} {
1339 foreach remote
$all_remotes {
1340 $m add
command -label "$pfx $remote..." \
1341 -command [list
$op $remote] \
1346 proc populate_pull_menu
{m
} {
1347 global gitdir repo_config all_remotes disable_on_lock
1349 foreach remote
$all_remotes {
1351 if {[array get repo_config remote.
$remote.url
] ne
{}} {
1352 if {[array get repo_config remote.
$remote.fetch
] ne
{}} {
1353 regexp
{^
([^
:]+):} \
1354 [lindex
$repo_config(remote.
$remote.fetch
) 0] \
1359 set fd
[open
[file join $gitdir remotes
$remote] r
]
1360 while {[gets
$fd line
] >= 0} {
1361 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $line line rb
]} {
1370 regsub ^refs
/heads
/ $rb {} rb_short
1371 if {$rb_short ne
{}} {
1373 -label "Branch $rb_short from $remote..." \
1374 -command [list pull_remote
$remote $rb] \
1376 lappend disable_on_lock \
1377 [list
$m entryconf
[$m index last
] -state]
1382 ######################################################################
1387 #define mask_width 14
1388 #define mask_height 15
1389 static unsigned char mask_bits
[] = {
1390 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1391 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1392 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1395 image create bitmap file_plain
-background white
-foreground black
-data {
1396 #define plain_width 14
1397 #define plain_height 15
1398 static unsigned char plain_bits
[] = {
1399 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1400 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1401 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1402 } -maskdata $filemask
1404 image create bitmap file_mod
-background white
-foreground blue
-data {
1405 #define mod_width 14
1406 #define mod_height 15
1407 static unsigned char mod_bits
[] = {
1408 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1409 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1410 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1411 } -maskdata $filemask
1413 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
1414 #define file_fulltick_width 14
1415 #define file_fulltick_height 15
1416 static unsigned char file_fulltick_bits
[] = {
1417 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1418 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1419 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1420 } -maskdata $filemask
1422 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
1423 #define parttick_width 14
1424 #define parttick_height 15
1425 static unsigned char parttick_bits
[] = {
1426 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1427 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
1428 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1429 } -maskdata $filemask
1431 image create bitmap file_question
-background white
-foreground black
-data {
1432 #define file_question_width 14
1433 #define file_question_height 15
1434 static unsigned char file_question_bits
[] = {
1435 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1436 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1437 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1438 } -maskdata $filemask
1440 image create bitmap file_removed
-background white
-foreground red
-data {
1441 #define file_removed_width 14
1442 #define file_removed_height 15
1443 static unsigned char file_removed_bits
[] = {
1444 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1445 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1446 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1447 } -maskdata $filemask
1449 image create bitmap file_merge
-background white
-foreground blue
-data {
1450 #define file_merge_width 14
1451 #define file_merge_height 15
1452 static unsigned char file_merge_bits
[] = {
1453 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1454 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1455 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1456 } -maskdata $filemask
1458 set ui_index .vpane.files.index.list
1459 set ui_other .vpane.files.other.list
1460 set max_status_desc
0
1462 {__ i plain
"Unmodified"}
1463 {_M i mod
"Modified"}
1464 {M_ i fulltick
"Included in commit"}
1465 {MM i parttick
"Partially included"}
1467 {_O o plain
"Untracked"}
1468 {A_ o fulltick
"Added by commit"}
1469 {AM o parttick
"Partially added"}
1470 {AD o question
"Added (but now gone)"}
1472 {_D i question
"Missing"}
1473 {D_ i removed
"Removed by commit"}
1474 {DD i removed
"Removed by commit"}
1475 {DO i removed
"Removed (still exists)"}
1477 {UM i merge
"Merge conflicts"}
1478 {U_ i merge
"Merge conflicts"}
1480 if {$max_status_desc < [string length
[lindex
$i 3]]} {
1481 set max_status_desc
[string length
[lindex
$i 3]]
1483 if {[lindex
$i 1] eq
{i
}} {
1484 set all_cols
([lindex
$i 0]) $ui_index
1486 set all_cols
([lindex
$i 0]) $ui_other
1488 set all_icons
([lindex
$i 0]) file_
[lindex
$i 2]
1489 set all_descs
([lindex
$i 0]) [lindex
$i 3]
1493 ######################################################################
1498 global tcl_platform tk_library
1499 if {$tcl_platform(platform
) eq
{unix
}
1500 && $tcl_platform(os
) eq
{Darwin
}
1501 && [string match
/Library
/Frameworks
/* $tk_library]} {
1507 proc bind_button3
{w cmd
} {
1508 bind $w <Any-Button-3
> $cmd
1510 bind $w <Control-Button-1
> $cmd
1514 proc incr_font_size
{font
{amt
1}} {
1515 set sz
[font configure
$font -size]
1517 font configure
$font -size $sz
1518 font configure
${font}bold
-size $sz
1521 proc hook_failed_popup
{hook msg
} {
1522 global gitdir appname
1528 label
$w.m.l1
-text "$hook hook failed:" \
1533 -background white
-borderwidth 1 \
1535 -width 80 -height 10 \
1537 -yscrollcommand [list
$w.m.sby
set]
1539 -text {You must correct the above errors before committing.
} \
1543 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
1544 pack
$w.m.l1
-side top
-fill x
1545 pack
$w.m.l2
-side bottom
-fill x
1546 pack
$w.m.sby
-side right
-fill y
1547 pack
$w.m.t
-side left
-fill both
-expand 1
1548 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
1550 $w.m.t insert
1.0 $msg
1551 $w.m.t conf
-state disabled
1553 button
$w.ok
-text OK \
1556 -command "destroy $w"
1557 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
1559 bind $w <Visibility
> "grab $w; focus $w"
1560 bind $w <Key-Return
> "destroy $w"
1561 wm title
$w "$appname ([lindex [file split \
1562 [file normalize [file dirname $gitdir]]] \
1567 set next_console_id
0
1569 proc new_console
{short_title long_title
} {
1570 global next_console_id console_data
1571 set w .console
[incr next_console_id
]
1572 set console_data
($w) [list
$short_title $long_title]
1573 return [console_init
$w]
1576 proc console_init
{w
} {
1577 global console_cr console_data
1578 global gitdir appname M1B
1580 set console_cr
($w) 1.0
1583 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
1588 -background white
-borderwidth 1 \
1590 -width 80 -height 10 \
1593 -yscrollcommand [list
$w.m.sby
set]
1594 label
$w.m.s
-text {Working... please
wait...
} \
1598 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
1599 pack
$w.m.l1
-side top
-fill x
1600 pack
$w.m.s
-side bottom
-fill x
1601 pack
$w.m.sby
-side right
-fill y
1602 pack
$w.m.t
-side left
-fill both
-expand 1
1603 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
1605 menu
$w.ctxm
-tearoff 0
1606 $w.ctxm add
command -label "Copy" \
1608 -command "tk_textCopy $w.m.t"
1609 $w.ctxm add
command -label "Select All" \
1611 -command "$w.m.t tag add sel 0.0 end"
1612 $w.ctxm add
command -label "Copy All" \
1615 $w.m.t tag add sel 0.0 end
1617 $w.m.t tag remove sel 0.0 end
1620 button
$w.ok
-text {Close
} \
1623 -command "destroy $w"
1624 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
1626 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
1627 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
1628 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
1629 bind $w <Visibility
> "focus $w"
1630 wm title
$w "$appname ([lindex [file split \
1631 [file normalize [file dirname $gitdir]]] \
1632 end]): [lindex $console_data($w) 0]"
1636 proc console_exec
{w cmd
{after
{}}} {
1639 # -- Windows tosses the enviroment when we exec our child.
1640 # But most users need that so we have to relogin. :-(
1642 if {$tcl_platform(platform
) eq
{windows
}} {
1643 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
1646 # -- Tcl won't let us redirect both stdout and stderr to
1647 # the same pipe. So pass it through cat...
1649 set cmd
[concat |
$cmd |
& cat]
1651 set fd_f
[open
$cmd r
]
1652 fconfigure
$fd_f -blocking 0 -translation binary
1653 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
1656 proc console_read
{w fd after
} {
1657 global console_cr console_data
1661 if {![winfo exists
$w]} {console_init
$w}
1662 $w.m.t conf
-state normal
1664 set n
[string length
$buf]
1666 set cr
[string first
"\r" $buf $c]
1667 set lf
[string first
"\n" $buf $c]
1668 if {$cr < 0} {set cr
[expr {$n + 1}]}
1669 if {$lf < 0} {set lf
[expr {$n + 1}]}
1672 $w.m.t insert end
[string range
$buf $c $lf]
1673 set console_cr
($w) [$w.m.t index
{end
-1c}]
1677 $w.m.t delete
$console_cr($w) end
1678 $w.m.t insert end
"\n"
1679 $w.m.t insert end
[string range
$buf $c $cr]
1684 $w.m.t conf
-state disabled
1688 fconfigure
$fd -blocking 1
1690 if {[catch
{close
$fd}]} {
1691 if {![winfo exists
$w]} {console_init
$w}
1692 $w.m.s conf
-background red
-text {Error
: Command Failed
}
1693 $w.ok conf
-state normal
1695 } elseif
{[winfo exists
$w]} {
1696 $w.m.s conf
-background green
-text {Success
}
1697 $w.ok conf
-state normal
1700 array
unset console_cr
$w
1701 array
unset console_data
$w
1703 uplevel
#0 $after $ok
1707 fconfigure
$fd -blocking 0
1710 ######################################################################
1714 set starting_gitk_msg
{Please
wait... Starting gitk...
}
1717 global tcl_platform ui_status_value starting_gitk_msg
1719 set ui_status_value
$starting_gitk_msg
1721 if {$ui_status_value eq
$starting_gitk_msg} {
1722 set ui_status_value
{Ready.
}
1726 if {$tcl_platform(platform
) eq
{windows
}} {
1734 set w
[new_console
"repack" "Repacking the object database"]
1735 set cmd
[list git repack
]
1738 console_exec
$w $cmd
1744 global gitdir ui_comm is_quitting repo_config
1746 if {$is_quitting} return
1749 # -- Stash our current commit buffer.
1751 set save
[file join $gitdir GITGUI_MSG
]
1752 set msg
[string trim
[$ui_comm get
0.0 end
]]
1753 if {[$ui_comm edit modified
] && $msg ne
{}} {
1755 set fd
[open
$save w
]
1756 puts
$fd [string trim
[$ui_comm get
0.0 end
]]
1759 } elseif
{$msg eq
{} && [file exists
$save]} {
1763 # -- Stash our current window geometry into this repository.
1765 set cfg_geometry
[list
]
1766 lappend cfg_geometry
[wm geometry .
]
1767 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
1768 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
1769 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
1772 if {$cfg_geometry ne
$rc_geometry} {
1773 catch
{exec git repo-config gui.geometry
$cfg_geometry}
1780 rescan
{set ui_status_value
{Ready.
}}
1783 proc do_include_all
{} {
1786 if {![lock_index begin-update
]} return
1789 foreach path
[array names file_states
] {
1790 set s
$file_states($path)
1796 _D
{lappend pathList
$path}
1799 if {$pathList eq
{}} {
1803 "Including all modified files" \
1805 {set ui_status_value
{Ready to commit.
}}
1809 set GIT_COMMITTER_IDENT
{}
1811 proc do_signoff
{} {
1812 global ui_comm GIT_COMMITTER_IDENT
1814 if {$GIT_COMMITTER_IDENT eq
{}} {
1815 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
1816 error_popup
"Unable to obtain your identity:\n\n$err"
1819 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
1820 $me me GIT_COMMITTER_IDENT
]} {
1821 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
1826 set sob
"Signed-off-by: $GIT_COMMITTER_IDENT"
1827 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
1828 if {$last ne
$sob} {
1829 $ui_comm edit separator
1831 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
1832 $ui_comm insert end
"\n"
1834 $ui_comm insert end
"\n$sob"
1835 $ui_comm edit separator
1840 proc do_amend_last
{} {
1848 proc do_options
{} {
1849 global appname gitdir font_descs
1850 global repo_config global_config
1851 global repo_config_new global_config_new
1853 array
unset repo_config_new
1854 array
unset global_config_new
1855 foreach name
[array names repo_config
] {
1856 set repo_config_new
($name) $repo_config($name)
1859 foreach name
[array names repo_config
] {
1861 gui.diffcontext
{continue}
1863 set repo_config_new
($name) $repo_config($name)
1865 foreach name
[array names global_config
] {
1866 set global_config_new
($name) $global_config($name)
1868 set reponame
[lindex
[file split \
1869 [file normalize
[file dirname $gitdir]]] \
1872 set w .options_editor
1874 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1876 label
$w.header
-text "$appname Options" \
1878 pack
$w.header
-side top
-fill x
1881 button
$w.buttons.restore
-text {Restore Defaults
} \
1883 -command do_restore_defaults
1884 pack
$w.buttons.restore
-side left
1885 button
$w.buttons.save
-text Save \
1887 -command [list do_save_config
$w]
1888 pack
$w.buttons.save
-side right
1889 button
$w.buttons.cancel
-text {Cancel
} \
1891 -command [list destroy
$w]
1892 pack
$w.buttons.cancel
-side right
1893 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1895 labelframe
$w.repo
-text "$reponame Repository" \
1897 -relief raised
-borderwidth 2
1898 labelframe
$w.global
-text {Global
(All Repositories
)} \
1900 -relief raised
-borderwidth 2
1901 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
1902 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
1905 {b partialinclude
{Allow Partially Included Files
}}
1906 {b pullsummary
{Show Pull Summary
}}
1907 {b trustmtime
{Trust File Modification Timestamps
}}
1908 {i diffcontext
{Number of Diff Context Lines
}}
1910 set type [lindex
$option 0]
1911 set name
[lindex
$option 1]
1912 set text
[lindex
$option 2]
1913 foreach f
{repo global
} {
1916 checkbutton
$w.
$f.
$name -text $text \
1917 -variable ${f}_config_new
(gui.
$name) \
1921 pack
$w.
$f.
$name -side top
-anchor w
1925 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
1926 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
1927 spinbox
$w.
$f.
$name.v \
1928 -textvariable ${f}_config_new
(gui.
$name) \
1929 -from 1 -to 99 -increment 1 \
1932 pack
$w.
$f.
$name.v
-side right
-anchor e
1933 pack
$w.
$f.
$name -side top
-anchor w
-fill x
1939 set all_fonts
[lsort
[font families
]]
1940 foreach option
$font_descs {
1941 set name
[lindex
$option 0]
1942 set font
[lindex
$option 1]
1943 set text
[lindex
$option 2]
1945 set global_config_new
(gui.
$font^^family
) \
1946 [font configure
$font -family]
1947 set global_config_new
(gui.
$font^^size
) \
1948 [font configure
$font -size]
1950 frame
$w.global.
$name
1951 label
$w.global.
$name.l
-text "$text:" -font font_ui
1952 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
1953 eval tk_optionMenu
$w.global.
$name.family \
1954 global_config_new
(gui.
$font^^family
) \
1956 spinbox
$w.global.
$name.size \
1957 -textvariable global_config_new
(gui.
$font^^size
) \
1958 -from 2 -to 80 -increment 1 \
1961 pack
$w.global.
$name.size
-side right
-anchor e
1962 pack
$w.global.
$name.family
-side right
-anchor e
1963 pack
$w.global.
$name -side top
-anchor w
-fill x
1966 bind $w <Visibility
> "grab $w; focus $w"
1967 bind $w <Key-Escape
> "destroy $w"
1968 wm title
$w "$appname ($reponame): Options"
1972 proc do_restore_defaults
{} {
1973 global font_descs default_config repo_config
1974 global repo_config_new global_config_new
1976 foreach name
[array names default_config
] {
1977 set repo_config_new
($name) $default_config($name)
1978 set global_config_new
($name) $default_config($name)
1981 foreach option
$font_descs {
1982 set name
[lindex
$option 0]
1983 set repo_config
(gui.
$name) $default_config(gui.
$name)
1987 foreach option
$font_descs {
1988 set name
[lindex
$option 0]
1989 set font
[lindex
$option 1]
1990 set global_config_new
(gui.
$font^^family
) \
1991 [font configure
$font -family]
1992 set global_config_new
(gui.
$font^^size
) \
1993 [font configure
$font -size]
1997 proc do_save_config
{w
} {
1998 if {[catch
{save_config
} err
]} {
1999 error_popup
"Failed to completely save options:\n\n$err"
2005 proc do_windows_shortcut
{} {
2006 global gitdir appname argv0
2008 set reponame
[lindex
[file split \
2009 [file normalize
[file dirname $gitdir]]] \
2013 set desktop
[exec cygpath \
2021 set fn
[tk_getSaveFile \
2023 -title "$appname ($reponame): Create Desktop Icon" \
2024 -initialdir $desktop \
2025 -initialfile "Git $reponame.bat"]
2029 set sh
[exec cygpath \
2034 set me
[exec cygpath \
2038 set gd
[exec cygpath \
2042 puts
-nonewline $fd "\"$sh\" --login -c \""
2043 puts
-nonewline $fd "GIT_DIR=\\\"$gd\\\""
2044 puts
-nonewline $fd " \\\"$me\\\""
2048 error_popup
"Cannot write script:\n\n$err"
2053 proc toggle_or_diff
{w x y
} {
2054 global file_lists ui_index ui_other
2055 global last_clicked selected_paths
2057 set pos
[split [$w index @
$x,$y] .
]
2058 set lno
[lindex
$pos 0]
2059 set col [lindex
$pos 1]
2060 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
2066 set last_clicked
[list
$w $lno]
2067 array
unset selected_paths
2068 $ui_index tag remove in_sel
0.0 end
2069 $ui_other tag remove in_sel
0.0 end
2073 "Including [short_path $path]" \
2075 {set ui_status_value
{Ready.
}}
2077 show_diff
$path $w $lno
2081 proc add_one_to_selection
{w x y
} {
2083 global last_clicked selected_paths
2085 set pos
[split [$w index @
$x,$y] .
]
2086 set lno
[lindex
$pos 0]
2087 set col [lindex
$pos 1]
2088 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
2094 set last_clicked
[list
$w $lno]
2095 if {[catch
{set in_sel
$selected_paths($path)}]} {
2099 unset selected_paths
($path)
2100 $w tag remove in_sel
$lno.0 [expr {$lno + 1}].0
2102 set selected_paths
($path) 1
2103 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
2107 proc add_range_to_selection
{w x y
} {
2109 global last_clicked selected_paths
2111 if {[lindex
$last_clicked 0] ne
$w} {
2112 toggle_or_diff
$w $x $y
2116 set pos
[split [$w index @
$x,$y] .
]
2117 set lno
[lindex
$pos 0]
2118 set lc
[lindex
$last_clicked 1]
2127 foreach path
[lrange
$file_lists($w) \
2128 [expr {$begin - 1}] \
2129 [expr {$end - 1}]] {
2130 set selected_paths
($path) 1
2132 $w tag add in_sel
$begin.0 [expr {$end + 1}].0
2135 ######################################################################
2139 set cursor_ptr arrow
2140 font create font_diff
-family Courier
-size 10
2144 eval font configure font_ui
[font actual
[.dummy cget
-font]]
2148 font create font_uibold
2149 font create font_diffbold
2153 if {$tcl_platform(platform
) eq
{windows
}} {
2156 } elseif
{[is_MacOSX
]} {
2161 proc apply_config
{} {
2162 global repo_config font_descs
2164 foreach option
$font_descs {
2165 set name
[lindex
$option 0]
2166 set font
[lindex
$option 1]
2168 foreach
{cn cv
} $repo_config(gui.
$name) {
2169 font configure
$font $cn $cv
2172 error_popup
"Invalid font specified in gui.$name:\n\n$err"
2174 foreach
{cn cv
} [font configure
$font] {
2175 font configure
${font}bold
$cn $cv
2177 font configure
${font}bold
-weight bold
2181 set default_config
(gui.trustmtime
) false
2182 set default_config
(gui.pullsummary
) true
2183 set default_config
(gui.partialinclude
) false
2184 set default_config
(gui.diffcontext
) 5
2185 set default_config
(gui.fontui
) [font configure font_ui
]
2186 set default_config
(gui.fontdiff
) [font configure font_diff
]
2188 {fontui font_ui
{Main Font
}}
2189 {fontdiff font_diff
{Diff
/Console Font
}}
2194 ######################################################################
2199 menu .mbar
-tearoff 0
2200 .mbar add cascade
-label Project
-menu .mbar.project
2201 .mbar add cascade
-label Edit
-menu .mbar.edit
2202 .mbar add cascade
-label Commit
-menu .mbar.commit
2203 if {!$single_commit} {
2204 .mbar add cascade
-label Fetch
-menu .mbar.fetch
2205 .mbar add cascade
-label Pull
-menu .mbar.pull
2206 .mbar add cascade
-label Push
-menu .mbar.push
2208 . configure
-menu .mbar
2212 .mbar.project add
command -label Visualize \
2215 if {!$single_commit} {
2216 .mbar.project add
command -label {Repack Database
} \
2217 -command do_repack \
2220 if {$tcl_platform(platform
) eq
{windows
}} {
2221 .mbar.project add
command \
2222 -label {Create Desktop Icon
} \
2223 -command do_windows_shortcut \
2227 .mbar.project add
command -label Quit \
2229 -accelerator $M1T-Q \
2235 .mbar.edit add
command -label Undo \
2236 -command {catch
{[focus
] edit undo
}} \
2237 -accelerator $M1T-Z \
2239 .mbar.edit add
command -label Redo \
2240 -command {catch
{[focus
] edit redo
}} \
2241 -accelerator $M1T-Y \
2243 .mbar.edit add separator
2244 .mbar.edit add
command -label Cut \
2245 -command {catch
{tk_textCut
[focus
]}} \
2246 -accelerator $M1T-X \
2248 .mbar.edit add
command -label Copy \
2249 -command {catch
{tk_textCopy
[focus
]}} \
2250 -accelerator $M1T-C \
2252 .mbar.edit add
command -label Paste \
2253 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
2254 -accelerator $M1T-V \
2256 .mbar.edit add
command -label Delete \
2257 -command {catch
{[focus
] delete sel.first sel.last
}} \
2260 .mbar.edit add separator
2261 .mbar.edit add
command -label {Select All
} \
2262 -command {catch
{[focus
] tag add sel
0.0 end
}} \
2263 -accelerator $M1T-A \
2265 .mbar.edit add separator
2266 .mbar.edit add
command -label {Options...
} \
2267 -command do_options \
2272 .mbar.commit add
command -label Rescan \
2273 -command do_rescan \
2276 lappend disable_on_lock \
2277 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2278 .mbar.commit add
command -label {Amend Last Commit
} \
2279 -command do_amend_last \
2281 lappend disable_on_lock \
2282 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2283 .mbar.commit add
command -label {Include All Files
} \
2284 -command do_include_all \
2285 -accelerator $M1T-I \
2287 lappend disable_on_lock \
2288 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2289 .mbar.commit add
command -label {Sign Off
} \
2290 -command do_signoff \
2291 -accelerator $M1T-S \
2293 .mbar.commit add
command -label Commit \
2294 -command do_commit \
2295 -accelerator $M1T-Return \
2297 lappend disable_on_lock \
2298 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2300 if {!$single_commit} {
2311 # -- Main Window Layout
2312 panedwindow .vpane
-orient vertical
2313 panedwindow .vpane.files
-orient horizontal
2314 .vpane add .vpane.files
-sticky nsew
-height 100 -width 400
2315 pack .vpane
-anchor n
-side top
-fill both
-expand 1
2317 # -- Index File List
2318 frame .vpane.files.index
-height 100 -width 400
2319 label .vpane.files.index.title
-text {Modified Files
} \
2322 text
$ui_index -background white
-borderwidth 0 \
2323 -width 40 -height 10 \
2325 -cursor $cursor_ptr \
2326 -yscrollcommand {.vpane.files.index.sb
set} \
2328 scrollbar .vpane.files.index.sb
-command [list
$ui_index yview
]
2329 pack .vpane.files.index.title
-side top
-fill x
2330 pack .vpane.files.index.sb
-side right
-fill y
2331 pack
$ui_index -side left
-fill both
-expand 1
2332 .vpane.files add .vpane.files.index
-sticky nsew
2334 # -- Other (Add) File List
2335 frame .vpane.files.other
-height 100 -width 100
2336 label .vpane.files.other.title
-text {Untracked Files
} \
2339 text
$ui_other -background white
-borderwidth 0 \
2340 -width 40 -height 10 \
2342 -cursor $cursor_ptr \
2343 -yscrollcommand {.vpane.files.other.sb
set} \
2345 scrollbar .vpane.files.other.sb
-command [list
$ui_other yview
]
2346 pack .vpane.files.other.title
-side top
-fill x
2347 pack .vpane.files.other.sb
-side right
-fill y
2348 pack
$ui_other -side left
-fill both
-expand 1
2349 .vpane.files add .vpane.files.other
-sticky nsew
2351 foreach i
[list
$ui_index $ui_other] {
2352 $i tag conf in_diff
-font font_uibold
2353 $i tag conf in_sel \
2354 -background [$i cget
-foreground] \
2355 -foreground [$i cget
-background]
2359 # -- Diff and Commit Area
2360 frame .vpane.lower
-height 300 -width 400
2361 frame .vpane.lower.commarea
2362 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
2363 pack .vpane.lower.commarea
-side top
-fill x
2364 pack .vpane.lower.
diff -side bottom
-fill both
-expand 1
2365 .vpane add .vpane.lower
-stick nsew
2367 # -- Commit Area Buttons
2368 frame .vpane.lower.commarea.buttons
2369 label .vpane.lower.commarea.buttons.l
-text {} \
2373 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
2374 pack .vpane.lower.commarea.buttons
-side left
-fill y
2376 button .vpane.lower.commarea.buttons.rescan
-text {Rescan
} \
2377 -command do_rescan \
2379 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
2380 lappend disable_on_lock \
2381 {.vpane.lower.commarea.buttons.rescan conf
-state}
2383 button .vpane.lower.commarea.buttons.amend
-text {Amend Last
} \
2384 -command do_amend_last \
2386 pack .vpane.lower.commarea.buttons.amend
-side top
-fill x
2387 lappend disable_on_lock \
2388 {.vpane.lower.commarea.buttons.amend conf
-state}
2390 button .vpane.lower.commarea.buttons.incall
-text {Include All
} \
2391 -command do_include_all \
2393 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
2394 lappend disable_on_lock \
2395 {.vpane.lower.commarea.buttons.incall conf
-state}
2397 button .vpane.lower.commarea.buttons.signoff
-text {Sign Off
} \
2398 -command do_signoff \
2400 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
2402 button .vpane.lower.commarea.buttons.commit
-text {Commit
} \
2403 -command do_commit \
2405 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
2406 lappend disable_on_lock \
2407 {.vpane.lower.commarea.buttons.commit conf
-state}
2409 # -- Commit Message Buffer
2410 frame .vpane.lower.commarea.buffer
2411 set ui_comm .vpane.lower.commarea.buffer.t
2412 set ui_coml .vpane.lower.commarea.buffer.l
2413 label
$ui_coml -text {Commit Message
:} \
2417 trace add variable commit_type
write {uplevel
#0 {
2418 switch
-glob $commit_type \
2419 initial
{$ui_coml conf
-text {Initial Commit Message
:}} \
2420 amend
{$ui_coml conf
-text {Amended Commit Message
:}} \
2421 merge
{$ui_coml conf
-text {Merge Commit Message
:}} \
2422 * {$ui_coml conf
-text {Commit Message
:}}
2424 text
$ui_comm -background white
-borderwidth 1 \
2427 -autoseparators true \
2429 -width 75 -height 9 -wrap none \
2431 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
2432 scrollbar .vpane.lower.commarea.buffer.sby \
2433 -command [list
$ui_comm yview
]
2434 pack
$ui_coml -side top
-fill x
2435 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
2436 pack
$ui_comm -side left
-fill y
2437 pack .vpane.lower.commarea.buffer
-side left
-fill y
2439 # -- Commit Message Buffer Context Menu
2441 set ctxm .vpane.lower.commarea.buffer.ctxm
2442 menu
$ctxm -tearoff 0
2446 -command {tk_textCut
$ui_comm}
2450 -command {tk_textCopy
$ui_comm}
2454 -command {tk_textPaste
$ui_comm}
2458 -command {$ui_comm delete sel.first sel.last
}
2461 -label {Select All
} \
2463 -command {$ui_comm tag add sel
0.0 end
}
2468 $ui_comm tag add sel
0.0 end
2469 tk_textCopy
$ui_comm
2470 $ui_comm tag remove sel
0.0 end
2477 bind_button3
$ui_comm "tk_popup $ctxm %X %Y"
2481 set diff_actions
[list
]
2482 proc current_diff_trace
{varname args
} {
2483 global current_diff diff_actions file_states
2484 if {$current_diff eq
{}} {
2491 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
2493 set p
[escape_path
$p]
2497 .vpane.lower.
diff.header.status configure
-text $s
2498 .vpane.lower.
diff.header.
file configure
-text $f
2499 .vpane.lower.
diff.header.path configure
-text $p
2500 foreach w
$diff_actions {
2504 trace add variable current_diff
write current_diff_trace
2506 frame .vpane.lower.
diff.header
-background orange
2507 label .vpane.lower.
diff.header.status \
2508 -background orange \
2509 -width $max_status_desc \
2513 label .vpane.lower.
diff.header.
file \
2514 -background orange \
2518 label .vpane.lower.
diff.header.path \
2519 -background orange \
2523 pack .vpane.lower.
diff.header.status
-side left
2524 pack .vpane.lower.
diff.header.
file -side left
2525 pack .vpane.lower.
diff.header.path
-fill x
2526 set ctxm .vpane.lower.
diff.header.ctxm
2527 menu
$ctxm -tearoff 0
2538 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2539 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
2542 frame .vpane.lower.
diff.body
2543 set ui_diff .vpane.lower.
diff.body.t
2544 text
$ui_diff -background white
-borderwidth 0 \
2545 -width 80 -height 15 -wrap none \
2547 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
2548 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
2550 scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
2551 -command [list
$ui_diff xview
]
2552 scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
2553 -command [list
$ui_diff yview
]
2554 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
2555 pack .vpane.lower.
diff.body.sby
-side right
-fill y
2556 pack
$ui_diff -side left
-fill both
-expand 1
2557 pack .vpane.lower.
diff.header
-side top
-fill x
2558 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
2560 $ui_diff tag conf dm
-foreground red
2561 $ui_diff tag conf dp
-foreground blue
2562 $ui_diff tag conf di
-foreground {#00a000}
2563 $ui_diff tag conf dni
-foreground {#a000a0}
2564 $ui_diff tag conf da
-font font_diffbold
2565 $ui_diff tag conf bold
-font font_diffbold
2567 # -- Diff Body Context Menu
2569 set ctxm .vpane.lower.
diff.body.ctxm
2570 menu
$ctxm -tearoff 0
2574 -command {tk_textCopy
$ui_diff}
2575 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2577 -label {Select All
} \
2579 -command {$ui_diff tag add sel
0.0 end
}
2580 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2585 $ui_diff tag add sel
0.0 end
2586 tk_textCopy
$ui_diff
2587 $ui_diff tag remove sel
0.0 end
2589 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2592 -label {Decrease Font Size
} \
2594 -command {incr_font_size font_diff
-1}
2595 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2597 -label {Increase Font Size
} \
2599 -command {incr_font_size font_diff
1}
2600 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2603 -label {Show Less Context
} \
2605 -command {if {$repo_config(gui.diffcontext
) >= 2} {
2606 incr repo_config
(gui.diffcontext
) -1
2609 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2611 -label {Show More Context
} \
2614 incr repo_config
(gui.diffcontext
)
2617 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
2619 $ctxm add
command -label {Options...
} \
2622 bind_button3
$ui_diff "tk_popup $ctxm %X %Y"
2626 set ui_status_value
{Initializing...
}
2627 label .status
-textvariable ui_status_value \
2633 pack .status
-anchor w
-side bottom
-fill x
2638 set gm
$repo_config(gui.geometry
)
2639 wm geometry .
[lindex
$gm 0]
2640 .vpane sash place
0 \
2641 [lindex
[.vpane sash coord
0] 0] \
2643 .vpane.files sash place
0 \
2645 [lindex
[.vpane.files sash coord
0] 1]
2651 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
2652 bind $ui_comm <$M1B-Key-i> {do_include_all
;break}
2653 bind $ui_comm <$M1B-Key-I> {do_include_all
;break}
2654 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
2655 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
2656 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
2657 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
2658 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
2659 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
2660 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2661 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2663 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
2664 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
2665 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
2666 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
2667 bind $ui_diff <$M1B-Key-v> {break}
2668 bind $ui_diff <$M1B-Key-V> {break}
2669 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
2670 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
2671 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
2672 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
2673 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
2674 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
2676 bind .
<Destroy
> do_quit
2677 bind all
<Key-F5
> do_rescan
2678 bind all
<$M1B-Key-r> do_rescan
2679 bind all
<$M1B-Key-R> do_rescan
2680 bind .
<$M1B-Key-s> do_signoff
2681 bind .
<$M1B-Key-S> do_signoff
2682 bind .
<$M1B-Key-i> do_include_all
2683 bind .
<$M1B-Key-I> do_include_all
2684 bind .
<$M1B-Key-Return> do_commit
2685 bind all
<$M1B-Key-q> do_quit
2686 bind all
<$M1B-Key-Q> do_quit
2687 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
2688 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
2689 foreach i
[list
$ui_index $ui_other] {
2690 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
2691 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
2692 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
2696 set file_lists
($ui_index) [list
]
2697 set file_lists
($ui_other) [list
]
2700 wm title .
"$appname ([file normalize [file dirname $gitdir]])"
2701 focus
-force $ui_comm
2702 if {!$single_commit} {
2704 populate_remote_menu .mbar.fetch From fetch_from
2705 populate_remote_menu .mbar.push To push_to
2706 populate_pull_menu .mbar.pull