blob: 11048c7a0e94f598b168de98d18fda9aea420c7d [file] [log] [blame]
Shawn O. Pearcebd11b822006-11-19 02:57:58 -05001#!/bin/sh
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002# Tcl ignores the next line -*- tcl -*- \
Shawn O. Pearce4e817d12007-06-22 01:10:12 -04003 if test "z$*" = zversion \
4 || test "z$*" = z--version; \
5 then \
6 echo 'git-gui version @@GITGUI_VERSION@@'; \
7 exit; \
8 fi; \
Shawn O. Pearce2f7c9a72007-09-20 21:25:34 -04009 argv0=$0; \
10 exec wish "$argv0" -- "$@"
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -050011
Shawn O. Pearce7e81d4e2007-02-12 16:12:04 -050012set appvers {@@GITGUI_VERSION@@}
Pat Thoyts24735432010-09-13 20:41:42 +010013set copyright [string map [list (c) \u00a9] {
14Copyright (c) 2006-2010 Shawn Pearce, et. al.
Shawn O. Pearcebdc9ea22006-11-21 02:36:55 -050015
Shawn O. Pearce0499b242007-01-20 20:08:20 -050016This program is free software; you can redistribute it and/or modify
17it under the terms of the GNU General Public License as published by
18the Free Software Foundation; either version 2 of the License, or
19(at your option) any later version.
Shawn O. Pearcebdc9ea22006-11-21 02:36:55 -050020
Shawn O. Pearce0499b242007-01-20 20:08:20 -050021This program is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public License
27along with this program; if not, write to the Free Software
Shawn O. Pearced6db1ad2007-10-12 12:18:02 -040028Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}]
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -050029
Shawn O. Pearcec950c662007-01-20 21:48:56 -050030######################################################################
31##
Shawn O. Pearcecfb07cc2007-06-02 16:11:26 -040032## Tcl/Tk sanity check
33
34if {[catch {package require Tcl 8.4} err]
35 || [catch {package require Tk 8.4} err]
36} {
37 catch {wm withdraw .}
38 tk_messageBox \
39 -icon error \
40 -type ok \
Pat Thoyts9cb268c2010-08-02 12:13:05 +010041 -title "git-gui: fatal error" \
Shawn O. Pearcecfb07cc2007-06-02 16:11:26 -040042 -message $err
43 exit 1
44}
45
Shawn O. Pearce63c4024f2007-09-11 13:37:45 -040046catch {rename send {}} ; # What an evil concept...
Shawn O. Pearcecff93392007-09-08 23:47:00 -040047
Shawn O. Pearcecfb07cc2007-06-02 16:11:26 -040048######################################################################
49##
Shawn O. Pearcefc703c22007-09-01 21:58:29 -040050## locate our library
51
David Turnera3b3ae32014-07-21 16:41:38 -040052if { [info exists ::env(GIT_GUI_LIB_DIR) ] } {
53 set oguilib $::env(GIT_GUI_LIB_DIR)
54} else {
55 set oguilib {@@GITGUI_LIBDIR@@}
56}
Shawn O. Pearcefc703c22007-09-01 21:58:29 -040057set oguirel {@@GITGUI_RELATIVE@@}
58if {$oguirel eq {1}} {
Johannes Sixt9534c9f2008-08-04 22:09:46 +020059 set oguilib [file dirname [file normalize $argv0]]
60 if {[file tail $oguilib] eq {git-core}} {
61 set oguilib [file dirname $oguilib]
62 }
63 set oguilib [file dirname $oguilib]
Shawn O. Pearcefc703c22007-09-01 21:58:29 -040064 set oguilib [file join $oguilib share git-gui lib]
Shawn O. Pearced4b0ccd2007-09-01 22:22:42 -040065 set oguimsg [file join $oguilib msgs]
Shawn O. Pearcefc703c22007-09-01 21:58:29 -040066} elseif {[string match @@* $oguirel]} {
67 set oguilib [file join [file dirname [file normalize $argv0]] lib]
Shawn O. Pearced4b0ccd2007-09-01 22:22:42 -040068 set oguimsg [file join [file dirname [file normalize $argv0]] po]
69} else {
70 set oguimsg [file join $oguilib msgs]
Shawn O. Pearcefc703c22007-09-01 21:58:29 -040071}
72unset oguirel
73
74######################################################################
75##
Shawn O. Pearcecd129012007-05-28 11:22:13 -040076## enable verbose loading?
77
78if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
79 unset _verbose
80 rename auto_load real__auto_load
81 proc auto_load {name args} {
82 puts stderr "auto_load $name"
83 return [uplevel 1 real__auto_load $name $args]
84 }
85 rename source real__source
Pat Thoytscdc6aba2014-11-07 00:37:28 +000086 proc source {args} {
87 puts stderr "source $args"
88 uplevel 1 [linsert $args 0 real__source]
Shawn O. Pearcecd129012007-05-28 11:22:13 -040089 }
Pat Thoytsc0d2c382010-10-05 23:51:34 +010090 if {[tk windowingsystem] eq "win32"} { console show }
Shawn O. Pearcecd129012007-05-28 11:22:13 -040091}
92
93######################################################################
94##
Shawn O. Pearced4b0ccd2007-09-01 22:22:42 -040095## Internationalization (i18n) through msgcat and gettext. See
96## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
97
98package require msgcat
Shawn O. Pearce146d73a2007-09-12 16:47:06 -040099
Pat Thoyts35b6f722011-02-18 13:42:54 +0000100# Check for Windows 7 MUI language pack (missed by msgcat < 1.4.4)
101if {[tk windowingsystem] eq "win32"
102 && [package vcompare [package provide msgcat] 1.4.4] < 0
103} then {
104 proc _mc_update_locale {} {
105 set key {HKEY_CURRENT_USER\Control Panel\Desktop}
106 if {![catch {
107 package require registry
108 set uilocale [registry get $key "PreferredUILanguages"]
109 msgcat::ConvertLocale [string map {- _} [lindex $uilocale 0]]
110 } uilocale]} {
111 if {[string length $uilocale] > 0} {
112 msgcat::mclocale $uilocale
113 }
114 }
115 }
116 _mc_update_locale
117}
118
Shawn O. Pearceab0d33c2007-10-23 18:44:55 -0400119proc _mc_trim {fmt} {
Shawn O. Pearce146d73a2007-09-12 16:47:06 -0400120 set cmk [string first @@ $fmt]
121 if {$cmk > 0} {
Shawn O. Pearceab0d33c2007-10-23 18:44:55 -0400122 return [string range $fmt 0 [expr {$cmk - 1}]]
Shawn O. Pearce146d73a2007-09-12 16:47:06 -0400123 }
Shawn O. Pearceab0d33c2007-10-23 18:44:55 -0400124 return $fmt
125}
126
127proc mc {en_fmt args} {
128 set fmt [_mc_trim [::msgcat::mc $en_fmt]]
129 if {[catch {set msg [eval [list format $fmt] $args]} err]} {
130 set msg [eval [list format [_mc_trim $en_fmt]] $args]
131 }
132 return $msg
Shawn O. Pearce146d73a2007-09-12 16:47:06 -0400133}
134
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -0400135proc strcat {args} {
136 return [join $args {}]
137}
138
Shawn O. Pearced4b0ccd2007-09-01 22:22:42 -0400139::msgcat::mcload $oguimsg
140unset oguimsg
141
142######################################################################
143##
Stefan Haller7d2017e2013-06-06 10:17:47 +0200144## On Mac, bring the current Wish process window to front
145
146if {[tk windowingsystem] eq "aqua"} {
147 catch {
148 exec osascript -e [format {
149 tell application "System Events"
150 set frontmost of processes whose unix id is %d to true
151 end tell
152 } [pid]]
153 }
154}
155
156######################################################################
157##
Shawn O. Pearcec950c662007-01-20 21:48:56 -0500158## read only globals
159
Shawn O. Pearce0b2bc462007-09-27 02:15:29 -0400160set _appname {Git Gui}
Shawn O. Pearcec950c662007-01-20 21:48:56 -0500161set _gitdir {}
Giuseppe Bilotta21985a12010-01-23 11:03:34 +0100162set _gitworktree {}
Giuseppe Bilotta29e55732010-01-23 11:03:35 +0100163set _isbare {}
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500164set _gitexec {}
Markus Heidelberg3eb56822009-04-05 03:48:21 +0200165set _githtmldir {}
Shawn O. Pearcec950c662007-01-20 21:48:56 -0500166set _reponame {}
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500167set _iscygwin {}
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400168set _search_path {}
Matthieu Moy62f9a632010-08-05 12:05:22 +0200169set _shellpath {@@SHELL_PATH@@}
Shawn O. Pearcec950c662007-01-20 21:48:56 -0500170
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400171set _trace [lsearch -exact $argv --trace]
172if {$_trace >= 0} {
173 set argv [lreplace $argv $_trace $_trace]
174 set _trace 1
Heiko Voigtc42939d2012-03-23 18:46:27 +0100175 if {[tk windowingsystem] eq "win32"} { console show }
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400176} else {
177 set _trace 0
178}
179
Heiko Voigt9d042782011-02-12 17:44:58 +0100180# variable for the last merged branch (useful for a default when deleting
181# branches).
182set _last_merged_branch {}
183
Matthieu Moy62f9a632010-08-05 12:05:22 +0200184proc shellpath {} {
Pat Thoytsd5257fb2010-08-07 20:32:13 +0100185 global _shellpath env
186 if {[string match @@* $_shellpath]} {
187 if {[info exists env(SHELL)]} {
188 return $env(SHELL)
189 } else {
190 return /bin/sh
191 }
192 }
Matthieu Moy62f9a632010-08-05 12:05:22 +0200193 return $_shellpath
194}
195
Shawn O. Pearcec950c662007-01-20 21:48:56 -0500196proc appname {} {
197 global _appname
198 return $_appname
199}
200
Shawn O. Pearcec2758a12007-01-20 21:55:05 -0500201proc gitdir {args} {
Shawn O. Pearcec950c662007-01-20 21:48:56 -0500202 global _gitdir
Shawn O. Pearcec2758a12007-01-20 21:55:05 -0500203 if {$args eq {}} {
204 return $_gitdir
205 }
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400206 return [eval [list file join $_gitdir] $args]
Shawn O. Pearcec950c662007-01-20 21:48:56 -0500207}
208
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500209proc gitexec {args} {
210 global _gitexec
211 if {$_gitexec eq {}} {
Shawn O. Pearce81347222007-02-12 22:48:56 -0500212 if {[catch {set _gitexec [git --exec-path]} err]} {
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500213 error "Git not installed?\n\n$err"
214 }
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400215 if {[is_Cygwin]} {
216 set _gitexec [exec cygpath \
217 --windows \
218 --absolute \
219 $_gitexec]
220 } else {
221 set _gitexec [file normalize $_gitexec]
222 }
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500223 }
224 if {$args eq {}} {
225 return $_gitexec
226 }
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400227 return [eval [list file join $_gitexec] $args]
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500228}
229
Markus Heidelberg3eb56822009-04-05 03:48:21 +0200230proc githtmldir {args} {
231 global _githtmldir
232 if {$_githtmldir eq {}} {
233 if {[catch {set _githtmldir [git --html-path]}]} {
234 # Git not installed or option not yet supported
235 return {}
236 }
237 if {[is_Cygwin]} {
238 set _githtmldir [exec cygpath \
239 --windows \
240 --absolute \
241 $_githtmldir]
242 } else {
243 set _githtmldir [file normalize $_githtmldir]
244 }
245 }
246 if {$args eq {}} {
247 return $_githtmldir
248 }
249 return [eval [list file join $_githtmldir] $args]
250}
251
Shawn O. Pearcec950c662007-01-20 21:48:56 -0500252proc reponame {} {
Shawn O. Pearced36cd962007-07-19 00:43:16 -0400253 return $::_reponame
Shawn O. Pearcec950c662007-01-20 21:48:56 -0500254}
Shawn O. Pearceda5239d2006-11-11 19:03:06 -0500255
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500256proc is_MacOSX {} {
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500257 if {[tk windowingsystem] eq {aqua}} {
258 return 1
259 }
260 return 0
261}
262
263proc is_Windows {} {
Shawn O. Pearced36cd962007-07-19 00:43:16 -0400264 if {$::tcl_platform(platform) eq {windows}} {
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500265 return 1
266 }
267 return 0
268}
269
270proc is_Cygwin {} {
Shawn O. Pearced36cd962007-07-19 00:43:16 -0400271 global _iscygwin
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500272 if {$_iscygwin eq {}} {
Shawn O. Pearced36cd962007-07-19 00:43:16 -0400273 if {$::tcl_platform(platform) eq {windows}} {
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -0500274 if {[catch {set p [exec cygpath --windir]} err]} {
275 set _iscygwin 0
276 } else {
277 set _iscygwin 1
278 }
279 } else {
280 set _iscygwin 0
281 }
282 }
283 return $_iscygwin
284}
285
Shawn O. Pearcecf25ddc2007-02-08 18:03:41 -0500286proc is_enabled {option} {
287 global enabled_options
288 if {[catch {set on $enabled_options($option)}]} {return 0}
289 return $on
290}
291
292proc enable_option {option} {
293 global enabled_options
294 set enabled_options($option) 1
295}
296
297proc disable_option {option} {
298 global enabled_options
299 set enabled_options($option) 0
300}
301
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -0500302######################################################################
303##
Shawn O. Pearce2d195162006-11-08 23:42:51 -0500304## config
305
Shawn O. Pearce51f4d162006-11-12 03:47:00 -0500306proc is_many_config {name} {
307 switch -glob -- $name {
Steffen Prohaska24f7c642007-10-08 08:25:47 +0200308 gui.recentrepo -
Shawn O. Pearce51f4d162006-11-12 03:47:00 -0500309 remote.*.fetch -
310 remote.*.push
311 {return 1}
312 *
313 {return 0}
314 }
315}
316
Shawn O. Pearcec5394492007-01-26 04:43:43 -0500317proc is_config_true {name} {
318 global repo_config
319 if {[catch {set v $repo_config($name)}]} {
320 return 0
Bert Wesarg12b219f2011-10-14 10:14:49 +0200321 }
322 set v [string tolower $v]
323 if {$v eq {} || $v eq {true} || $v eq {1} || $v eq {yes} || $v eq {on}} {
Shawn O. Pearcec5394492007-01-26 04:43:43 -0500324 return 1
325 } else {
326 return 0
327 }
328}
329
Clément Poulain1fbacca2010-07-30 09:11:02 +0100330proc is_config_false {name} {
331 global repo_config
332 if {[catch {set v $repo_config($name)}]} {
333 return 0
Bert Wesarg12b219f2011-10-14 10:14:49 +0200334 }
335 set v [string tolower $v]
336 if {$v eq {false} || $v eq {0} || $v eq {no} || $v eq {off}} {
Clément Poulain1fbacca2010-07-30 09:11:02 +0100337 return 1
338 } else {
339 return 0
340 }
341}
342
Shawn O. Pearce61f82ce2007-05-28 12:52:57 -0400343proc get_config {name} {
344 global repo_config
345 if {[catch {set v $repo_config($name)}]} {
346 return {}
347 } else {
348 return $v
349 }
350}
351
Giuseppe Bilotta29e55732010-01-23 11:03:35 +0100352proc is_bare {} {
353 global _isbare
354 global _gitdir
355 global _gitworktree
356
357 if {$_isbare eq {}} {
358 if {[catch {
359 set _bare [git rev-parse --is-bare-repository]
360 switch -- $_bare {
361 true { set _isbare 1 }
362 false { set _isbare 0}
363 default { throw }
364 }
365 }]} {
366 if {[is_config_true core.bare]
367 || ($_gitworktree eq {}
368 && [lindex [file split $_gitdir] end] ne {.git})} {
369 set _isbare 1
370 } else {
371 set _isbare 0
372 }
373 }
374 }
375 return $_isbare
376}
377
Shawn O. Pearce81347222007-02-12 22:48:56 -0500378######################################################################
379##
380## handy utils
381
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400382proc _trace_exec {cmd} {
383 if {!$::_trace} return
384 set d {}
385 foreach v $cmd {
386 if {$d ne {}} {
387 append d { }
388 }
389 if {[regexp {[ \t\r\n'"$?*]} $v]} {
390 set v [sq $v]
391 }
392 append d $v
393 }
394 puts stderr $d
395}
396
Pat Thoyts2810a582010-08-02 13:42:45 +0100397#'" fix poor old emacs font-lock mode
398
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400399proc _git_cmd {name} {
400 global _git_cmd_path
401
402 if {[catch {set v $_git_cmd_path($name)}]} {
403 switch -- $name {
Shawn O. Pearce70a75952007-07-09 02:30:24 -0400404 version -
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400405 --version -
406 --exec-path { return [list $::_git $name] }
407 }
408
409 set p [gitexec git-$name$::_search_exe]
410 if {[file exists $p]} {
411 set v [list $p]
Shawn O. Pearcec136f2b2007-07-09 02:47:33 -0400412 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
413 # Try to determine what sort of magic will make
414 # git-$name go and do its thing, because native
415 # Tcl on Windows doesn't know it.
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400416 #
Shawn O. Pearcec136f2b2007-07-09 02:47:33 -0400417 set p [gitexec git-$name]
418 set f [open $p r]
419 set s [gets $f]
420 close $f
421
Shawn O. Pearce6e4ba052007-09-02 15:19:07 -0400422 switch -glob -- [lindex $s 0] {
Shawn O. Pearcec136f2b2007-07-09 02:47:33 -0400423 #!*sh { set i sh }
424 #!*perl { set i perl }
425 #!*python { set i python }
426 default { error "git-$name is not supported: $s" }
427 }
428
429 upvar #0 _$i interp
430 if {![info exists interp]} {
431 set interp [_which $i]
432 }
433 if {$interp eq {}} {
434 error "git-$name requires $i (not in PATH)"
435 }
Shawn O. Pearce6e4ba052007-09-02 15:19:07 -0400436 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400437 } else {
Shawn O. Pearcec6729892007-07-09 02:13:00 -0400438 # Assume it is builtin to git somehow and we
439 # aren't actually able to see a file for it.
440 #
441 set v [list $::_git $name]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400442 }
443 set _git_cmd_path($name) $v
444 }
445 return $v
446}
447
Shawn O. Pearce79317e52008-07-29 22:36:58 -0700448proc _which {what args} {
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400449 global env _search_exe _search_path
450
451 if {$_search_path eq {}} {
Shawn O. Pearce299077f2007-09-21 11:08:50 -0400452 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400453 set _search_path [split [exec cygpath \
454 --windows \
455 --path \
456 --absolute \
457 $env(PATH)] {;}]
458 set _search_exe .exe
459 } elseif {[is_Windows]} {
Steffen Prohaskabe700fe2007-10-06 11:29:02 +0200460 set gitguidir [file dirname [info script]]
461 regsub -all ";" $gitguidir "\\;" gitguidir
462 set env(PATH) "$gitguidir;$env(PATH)"
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400463 set _search_path [split $env(PATH) {;}]
464 set _search_exe .exe
465 } else {
466 set _search_path [split $env(PATH) :]
467 set _search_exe {}
468 }
469 }
470
Shawn O. Pearce79317e52008-07-29 22:36:58 -0700471 if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
472 set suffix {}
473 } else {
474 set suffix $_search_exe
475 }
476
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400477 foreach p $_search_path {
Shawn O. Pearce79317e52008-07-29 22:36:58 -0700478 set p [file join $p $what$suffix]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400479 if {[file exists $p]} {
480 return [file normalize $p]
481 }
482 }
483 return {}
484}
485
Pat Thoyts7d076d52011-12-09 15:14:32 +0000486# Test a file for a hashbang to identify executable scripts on Windows.
487proc is_shellscript {filename} {
488 if {![file exists $filename]} {return 0}
489 set f [open $filename r]
490 fconfigure $f -encoding binary
491 set magic [read $f 2]
492 close $f
493 return [expr {$magic eq "#!"}]
494}
495
496# Run a command connected via pipes on stdout.
497# This is for use with textconv filters and uses sh -c "..." to allow it to
498# contain a command with arguments. On windows we must check for shell
499# scripts specifically otherwise just call the filter command.
500proc open_cmd_pipe {cmd path} {
501 global env
502 if {![file executable [shellpath]]} {
503 set exe [auto_execok [lindex $cmd 0]]
504 if {[is_shellscript [lindex $exe 0]]} {
505 set run [linsert [auto_execok sh] end -c "$cmd \"\$0\"" $path]
506 } else {
507 set run [concat $exe [lrange $cmd 1 end] $path]
508 }
509 } else {
510 set run [list [shellpath] -c "$cmd \"\$0\"" $path]
511 }
512 return [open |$run r]
513}
514
Shawn O. Pearce6f62b4f2007-07-17 22:31:16 -0400515proc _lappend_nice {cmd_var} {
516 global _nice
517 upvar $cmd_var cmd
518
519 if {![info exists _nice]} {
520 set _nice [_which nice]
Heiko Voigt9c898a12010-02-07 22:47:56 +0100521 if {[catch {exec $_nice git version}]} {
522 set _nice {}
Sebastian Schuberthff9db6c2010-10-05 11:12:00 +0200523 } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} {
524 set _nice {}
Heiko Voigt9c898a12010-02-07 22:47:56 +0100525 }
Shawn O. Pearce6f62b4f2007-07-17 22:31:16 -0400526 }
527 if {$_nice ne {}} {
528 lappend cmd $_nice
529 }
530}
531
Shawn O. Pearce81347222007-02-12 22:48:56 -0500532proc git {args} {
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400533 set opt [list]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400534
535 while {1} {
536 switch -- [lindex $args 0] {
537 --nice {
Shawn O. Pearce6f62b4f2007-07-17 22:31:16 -0400538 _lappend_nice opt
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400539 }
540
541 default {
542 break
543 }
544
545 }
546
547 set args [lrange $args 1 end]
548 }
549
550 set cmdp [_git_cmd [lindex $args 0]]
551 set args [lrange $args 1 end]
552
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400553 _trace_exec [concat $opt $cmdp $args]
554 set result [eval exec $opt $cmdp $args]
555 if {$::_trace} {
556 puts stderr "< $result"
557 }
558 return $result
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400559}
560
Shawn O. Pearce74c47632007-07-09 03:07:05 -0400561proc _open_stdout_stderr {cmd} {
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400562 _trace_exec $cmd
Shawn O. Pearce74c47632007-07-09 03:07:05 -0400563 if {[catch {
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400564 set fd [open [concat [list | ] $cmd] r]
Shawn O. Pearce74c47632007-07-09 03:07:05 -0400565 } err]} {
566 if { [lindex $cmd end] eq {2>@1}
567 && $err eq {can not find channel named "1"}
568 } {
569 # Older versions of Tcl 8.4 don't have this 2>@1 IO
570 # redirect operator. Fallback to |& cat for those.
571 # The command was not actually started, so its safe
572 # to try to start it a second time.
573 #
574 set fd [open [concat \
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400575 [list | ] \
Shawn O. Pearce74c47632007-07-09 03:07:05 -0400576 [lrange $cmd 0 end-1] \
577 [list |& cat] \
578 ] r]
579 } else {
580 error $err
581 }
582 }
Shawn O. Pearce6eb420e2007-07-17 01:50:10 -0400583 fconfigure $fd -eofchar {}
Shawn O. Pearce74c47632007-07-09 03:07:05 -0400584 return $fd
585}
586
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400587proc git_read {args} {
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400588 set opt [list]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400589
590 while {1} {
591 switch -- [lindex $args 0] {
592 --nice {
Shawn O. Pearce6f62b4f2007-07-17 22:31:16 -0400593 _lappend_nice opt
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400594 }
595
596 --stderr {
597 lappend args 2>@1
598 }
599
600 default {
601 break
602 }
603
604 }
605
606 set args [lrange $args 1 end]
607 }
608
609 set cmdp [_git_cmd [lindex $args 0]]
610 set args [lrange $args 1 end]
611
Shawn O. Pearce74c47632007-07-09 03:07:05 -0400612 return [_open_stdout_stderr [concat $opt $cmdp $args]]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400613}
614
615proc git_write {args} {
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400616 set opt [list]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400617
618 while {1} {
619 switch -- [lindex $args 0] {
620 --nice {
Shawn O. Pearce6f62b4f2007-07-17 22:31:16 -0400621 _lappend_nice opt
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400622 }
623
624 default {
625 break
626 }
627
628 }
629
630 set args [lrange $args 1 end]
631 }
632
633 set cmdp [_git_cmd [lindex $args 0]]
634 set args [lrange $args 1 end]
635
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400636 _trace_exec [concat $opt $cmdp $args]
637 return [open [concat [list | ] $opt $cmdp $args] w]
Shawn O. Pearce81347222007-02-12 22:48:56 -0500638}
639
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500640proc githook_read {hook_name args} {
641 set pchook [gitdir hooks $hook_name]
642 lappend args 2>@1
643
Alexander Gavrilovfbc0e7a2008-07-17 00:12:28 +0400644 # On Windows [file executable] might lie so we need to ask
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500645 # the shell if the hook is executable. Yes that's annoying.
646 #
Alexander Gavrilovfbc0e7a2008-07-17 00:12:28 +0400647 if {[is_Windows]} {
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500648 upvar #0 _sh interp
649 if {![info exists interp]} {
650 set interp [_which sh]
651 }
652 if {$interp eq {}} {
653 error "hook execution requires sh (not in PATH)"
654 }
655
656 set scr {if test -x "$1";then exec "$@";fi}
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400657 set sh_c [list $interp -c $scr $interp $pchook]
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500658 return [_open_stdout_stderr [concat $sh_c $args]]
659 }
660
661 if {[file executable $pchook]} {
Shawn O. Pearce16dd62a2008-05-18 13:08:17 -0400662 return [_open_stdout_stderr [concat [list $pchook] $args]]
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500663 }
664
665 return {}
666}
667
Alexander Gavrilove6131d32008-07-17 00:48:08 +0400668proc kill_file_process {fd} {
669 set process [pid $fd]
670
671 catch {
672 if {[is_Windows]} {
Sebastian Schuberth3b422bc2014-10-23 21:30:54 +0200673 exec taskkill /pid $process
Alexander Gavrilove6131d32008-07-17 00:48:08 +0400674 } else {
675 exec kill $process
676 }
677 }
678}
679
Shawn O. Pearce1ffca602008-01-23 00:37:10 -0500680proc gitattr {path attr default} {
681 if {[catch {set r [git check-attr $attr -- $path]}]} {
682 set r unspecified
683 } else {
684 set r [join [lrange [split $r :] 2 end] :]
685 regsub {^ } $r {} r
686 }
687 if {$r eq {unspecified}} {
688 return $default
689 }
690 return $r
691}
692
Shawn O. Pearce7eafa2f2007-07-09 03:28:41 -0400693proc sq {value} {
694 regsub -all ' $value "'\\''" value
695 return "'$value'"
696}
697
Shawn O. Pearced41b43e2007-07-08 18:40:56 -0400698proc load_current_branch {} {
699 global current_branch is_detached
700
Shawn O. Pearcefc4e8da2007-05-30 20:39:46 -0400701 set fd [open [gitdir HEAD] r]
Shawn O. Pearce311e02a2007-07-05 19:19:37 -0400702 if {[gets $fd ref] < 1} {
Shawn O. Pearcefc4e8da2007-05-30 20:39:46 -0400703 set ref {}
704 }
705 close $fd
Shawn O. Pearce311e02a2007-07-05 19:19:37 -0400706
707 set pfx {ref: refs/heads/}
708 set len [string length $pfx]
709 if {[string equal -length $len $pfx $ref]} {
710 # We're on a branch. It might not exist. But
711 # HEAD looks good enough to be a branch.
712 #
Shawn O. Pearced41b43e2007-07-08 18:40:56 -0400713 set current_branch [string range $ref $len end]
714 set is_detached 0
Shawn O. Pearce311e02a2007-07-05 19:19:37 -0400715 } else {
716 # Assume this is a detached head.
717 #
Shawn O. Pearced41b43e2007-07-08 18:40:56 -0400718 set current_branch HEAD
719 set is_detached 1
Shawn O. Pearce311e02a2007-07-05 19:19:37 -0400720 }
Shawn O. Pearcefc4e8da2007-05-30 20:39:46 -0400721}
722
Shawn O. Pearce27392912007-04-28 22:00:02 -0400723auto_load tk_optionMenu
724rename tk_optionMenu real__tkOptionMenu
725proc tk_optionMenu {w varName args} {
726 set m [eval real__tkOptionMenu $w $varName $args]
727 $m configure -font font_ui
728 $w configure -font font_ui
729 return $m
730}
731
Shawn O. Pearce3849bfb2007-09-16 23:12:19 -0400732proc rmsel_tag {text} {
733 $text tag conf sel \
734 -background [$text cget -background] \
735 -foreground [$text cget -foreground] \
736 -borderwidth 0
737 $text tag conf in_sel -background lightgray
738 bind $text <Motion> break
739 return $text
740}
741
Pat Thoyts2810a582010-08-02 13:42:45 +0100742wm withdraw .
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400743set root_exists 0
744bind . <Visibility> {
745 bind . <Visibility> {}
746 set root_exists 1
747}
748
Shawn O. Pearce1bdd8a12007-09-27 00:18:29 -0400749if {[is_Windows]} {
750 wm iconbitmap . -default $oguilib/git-gui.ico
Alexander Gavrilovf10d5b02008-10-03 11:36:53 +0400751 set ::tk::AlwaysShowSelection 1
Pat Thoytsc0d2c382010-10-05 23:51:34 +0100752 bind . <Control-F2> {console show}
Alexander Gavrilov8c762122008-10-15 13:28:21 +0400753
754 # Spoof an X11 display for SSH
755 if {![info exists env(DISPLAY)]} {
756 set env(DISPLAY) :9999
757 }
Giuseppe Bilottad1f2b362008-11-16 03:42:32 +0100758} else {
759 catch {
760 image create photo gitlogo -width 16 -height 16
761
762 gitlogo put #33CC33 -to 7 0 9 2
763 gitlogo put #33CC33 -to 4 2 12 4
764 gitlogo put #33CC33 -to 7 4 9 6
765 gitlogo put #CC3333 -to 4 6 12 8
766 gitlogo put gray26 -to 4 9 6 10
767 gitlogo put gray26 -to 3 10 6 12
768 gitlogo put gray26 -to 8 9 13 11
769 gitlogo put gray26 -to 8 11 10 12
770 gitlogo put gray26 -to 11 11 13 14
771 gitlogo put gray26 -to 3 12 5 14
772 gitlogo put gray26 -to 5 13
773 gitlogo put gray26 -to 10 13
774 gitlogo put gray26 -to 4 14 12 15
775 gitlogo put gray26 -to 5 15 11 16
776 gitlogo redither
777
Samuel Bronson215d4fd2011-12-07 12:48:04 +0000778 image create photo gitlogo32 -width 32 -height 32
779 gitlogo32 copy gitlogo -zoom 2 2
780
781 wm iconphoto . -default gitlogo gitlogo32
Giuseppe Bilottad1f2b362008-11-16 03:42:32 +0100782 }
Shawn O. Pearce1bdd8a12007-09-27 00:18:29 -0400783}
784
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400785######################################################################
786##
787## config defaults
788
789set cursor_ptr arrow
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400790font create font_ui
Pat Thoytsc80d7be2010-01-26 00:05:31 +0000791if {[lsearch -exact [font names] TkDefaultFont] != -1} {
792 eval [linsert [font actual TkDefaultFont] 0 font configure font_ui]
793 eval [linsert [font actual TkFixedFont] 0 font create font_diff]
794} else {
795 font create font_diff -family Courier -size 10
796 catch {
797 label .dummy
798 eval font configure font_ui [font actual [.dummy cget -font]]
799 destroy .dummy
800 }
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400801}
802
803font create font_uiitalic
804font create font_uibold
805font create font_diffbold
806font create font_diffitalic
807
808foreach class {Button Checkbutton Entry Label
Daniel A. Steffena91be3f2008-08-16 03:20:09 +0200809 Labelframe Listbox Message
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400810 Radiobutton Spinbox Text} {
811 option add *$class.font font_ui
812}
Daniel A. Steffena91be3f2008-08-16 03:20:09 +0200813if {![is_MacOSX]} {
814 option add *Menu.font font_ui
Pat Thoytsc80d7be2010-01-26 00:05:31 +0000815 option add *Entry.borderWidth 1 startupFile
816 option add *Entry.relief sunken startupFile
817 option add *RadioButton.anchor w startupFile
Daniel A. Steffena91be3f2008-08-16 03:20:09 +0200818}
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400819unset class
820
821if {[is_Windows] || [is_MacOSX]} {
822 option add *Menu.tearOff 0
823}
824
825if {[is_MacOSX]} {
826 set M1B M1
827 set M1T Cmd
828} else {
829 set M1B Control
830 set M1T Ctrl
831}
832
833proc bind_button3 {w cmd} {
834 bind $w <Any-Button-3> $cmd
835 if {[is_MacOSX]} {
836 # Mac OS X sends Button-2 on right click through three-button mouse,
837 # or through trackpad right-clicking (two-finger touch + click).
838 bind $w <Any-Button-2> $cmd
839 bind $w <Control-Button-1> $cmd
840 }
841}
842
843proc apply_config {} {
844 global repo_config font_descs
845
846 foreach option $font_descs {
847 set name [lindex $option 0]
848 set font [lindex $option 1]
849 if {[catch {
Shawn O. Pearce48b8d2b2007-11-01 00:31:36 -0400850 set need_weight 1
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400851 foreach {cn cv} $repo_config(gui.$name) {
Shawn O. Pearce48b8d2b2007-11-01 00:31:36 -0400852 if {$cn eq {-weight}} {
853 set need_weight 0
854 }
855 font configure $font $cn $cv
856 }
857 if {$need_weight} {
858 font configure $font -weight normal
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400859 }
860 } err]} {
861 error_popup [strcat [mc "Invalid font specified in %s:" "gui.$name"] "\n\n$err"]
862 }
863 foreach {cn cv} [font configure $font] {
864 font configure ${font}bold $cn $cv
865 font configure ${font}italic $cn $cv
866 }
867 font configure ${font}bold -weight bold
868 font configure ${font}italic -slant italic
869 }
Pat Thoytsc80d7be2010-01-26 00:05:31 +0000870
871 global use_ttk NS
872 set use_ttk 0
873 set NS {}
874 if {$repo_config(gui.usettk)} {
875 set use_ttk [package vsatisfies [package provide Tk] 8.5]
876 if {$use_ttk} {
877 set NS ttk
878 bind [winfo class .] <<ThemeChanged>> [list InitTheme]
879 pave_toplevel .
880 }
881 }
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400882}
883
Shawn O. Pearcefe702252008-05-08 20:16:43 -0400884set default_config(branch.autosetupmerge) true
Alexander Gavrilov7e306822008-08-31 00:56:51 +0400885set default_config(merge.tool) {}
Ferry Hubertsfb250922009-04-07 17:33:35 +0200886set default_config(mergetool.keepbackup) true
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400887set default_config(merge.diffstat) true
888set default_config(merge.summary) false
889set default_config(merge.verbosity) 2
890set default_config(user.name) {}
891set default_config(user.email) {}
892
Alexander Gavrilov72e6b002008-09-18 01:07:32 +0400893set default_config(gui.encoding) [encoding system]
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400894set default_config(gui.matchtrackingbranch) false
Clément Poulain1fbacca2010-07-30 09:11:02 +0100895set default_config(gui.textconv) true
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400896set default_config(gui.pruneduringfetch) false
897set default_config(gui.trustmtime) false
Alexander Gavrilov57cae872008-07-17 00:43:48 +0400898set default_config(gui.fastcopyblame) false
Pat Thoytsd4780562013-08-27 11:11:15 +0100899set default_config(gui.maxrecentrepo) 10
Alexander Gavrilov57cae872008-07-17 00:43:48 +0400900set default_config(gui.copyblamethreshold) 40
Alexander Gavrilova9c80b82008-08-23 12:30:00 +0400901set default_config(gui.blamehistoryctx) 7
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400902set default_config(gui.diffcontext) 5
Tilman Vogel54531e72011-01-21 11:59:45 +0100903set default_config(gui.diffopts) {}
Adam PiÄ…tyszek11027d52008-03-06 20:38:40 +0100904set default_config(gui.commitmsgwidth) 75
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400905set default_config(gui.newbranchtemplate) {}
Shawn O. Pearce95b002e2008-02-07 02:35:25 -0500906set default_config(gui.spellingdictionary) {}
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400907set default_config(gui.fontui) [font configure font_ui]
908set default_config(gui.fontdiff) [font configure font_diff]
Dan Zwelldd6451f2009-08-11 13:50:00 -0500909# TODO: this option should be added to the git-config documentation
910set default_config(gui.maxfilesdisplayed) 5000
Pat Thoytsc80d7be2010-01-26 00:05:31 +0000911set default_config(gui.usettk) 1
Heiko Voigte34789c2011-02-15 19:43:54 +0000912set default_config(gui.warndetachedcommit) 1
Michael Lutza43c5f52012-02-12 16:55:17 +0100913set default_config(gui.tabsize) 8
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400914set font_descs {
915 {fontui font_ui {mc "Main Font"}}
916 {fontdiff font_diff {mc "Diff/Console Font"}}
917}
Bert Wesargbb196e22011-10-14 21:25:21 +0200918set default_config(gui.stageuntracked) ask
Max Kirillove632b3c2013-08-21 06:29:13 +0300919set default_config(gui.displayuntracked) true
Shawn O. Pearcea4bee592007-09-21 03:41:51 -0400920
Shawn O. Pearce2d195162006-11-08 23:42:51 -0500921######################################################################
922##
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400923## find git
924
925set _git [_which git]
926if {$_git eq {}} {
927 catch {wm withdraw .}
Shawn O. Pearce183a1d12007-09-21 10:58:02 -0400928 tk_messageBox \
929 -icon error \
930 -type ok \
931 -title [mc "git-gui: fatal error"] \
932 -message [mc "Cannot find git in PATH."]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400933 exit 1
934}
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400935
936######################################################################
937##
Shawn O. Pearce54acdd92007-02-13 23:15:25 -0500938## version check
939
Shawn O. Pearced6967022007-07-08 18:48:08 -0400940if {[catch {set _git_version [git --version]} err]} {
Shawn O. Pearce54acdd92007-02-13 23:15:25 -0500941 catch {wm withdraw .}
Shawn O. Pearce875b7c92007-08-22 02:41:00 -0400942 tk_messageBox \
943 -icon error \
944 -type ok \
Michele Ballabioc8c48542007-09-13 15:19:05 +0200945 -title [mc "git-gui: fatal error"] \
Shawn O. Pearce875b7c92007-08-22 02:41:00 -0400946 -message "Cannot determine Git version:
Shawn O. Pearce54acdd92007-02-13 23:15:25 -0500947
948$err
949
Shawn O. Pearced6967022007-07-08 18:48:08 -0400950[appname] requires Git 1.5.0 or later."
Shawn O. Pearce54acdd92007-02-13 23:15:25 -0500951 exit 1
952}
Shawn O. Pearced6967022007-07-08 18:48:08 -0400953if {![regsub {^git version } $_git_version {} _git_version]} {
Shawn O. Pearce54acdd92007-02-13 23:15:25 -0500954 catch {wm withdraw .}
Shawn O. Pearce875b7c92007-08-22 02:41:00 -0400955 tk_messageBox \
956 -icon error \
957 -type ok \
Michele Ballabioc8c48542007-09-13 15:19:05 +0200958 -title [mc "git-gui: fatal error"] \
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -0400959 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
Shawn O. Pearce54acdd92007-02-13 23:15:25 -0500960 exit 1
961}
Shawn O. Pearce301dfaa2007-07-17 23:09:31 -0400962
Pat Thoyts67112c42010-10-07 22:28:45 +0100963proc get_trimmed_version {s} {
964 set r {}
965 foreach x [split $s -._] {
966 if {[string is integer -strict $x]} {
967 lappend r $x
968 } else {
969 break
970 }
971 }
972 return [join $r .]
973}
Shawn O. Pearce301dfaa2007-07-17 23:09:31 -0400974set _real_git_version $_git_version
Pat Thoyts67112c42010-10-07 22:28:45 +0100975set _git_version [get_trimmed_version $_git_version]
Shawn O. Pearced6967022007-07-08 18:48:08 -0400976
Shawn O. Pearce301dfaa2007-07-17 23:09:31 -0400977if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
978 catch {wm withdraw .}
979 if {[tk_messageBox \
980 -icon warning \
981 -type yesno \
982 -default no \
983 -title "[appname]: warning" \
Christian Stimming1ac17952007-07-21 14:21:34 +0200984 -message [mc "Git version cannot be determined.
Shawn O. Pearce301dfaa2007-07-17 23:09:31 -0400985
Christian Stimming1ac17952007-07-21 14:21:34 +0200986%s claims it is version '%s'.
Shawn O. Pearce301dfaa2007-07-17 23:09:31 -0400987
Christian Stimming1ac17952007-07-21 14:21:34 +0200988%s requires at least Git 1.5.0 or later.
Shawn O. Pearce301dfaa2007-07-17 23:09:31 -0400989
Christian Stimming1ac17952007-07-21 14:21:34 +0200990Assume '%s' is version 1.5.0?
991" $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
Shawn O. Pearce301dfaa2007-07-17 23:09:31 -0400992 set _git_version 1.5.0
993 } else {
994 exit 1
995 }
996}
997unset _real_git_version
998
Shawn O. Pearced6967022007-07-08 18:48:08 -0400999proc git-version {args} {
1000 global _git_version
1001
1002 switch [llength $args] {
1003 0 {
1004 return $_git_version
1005 }
1006
1007 2 {
1008 set op [lindex $args 0]
1009 set vr [lindex $args 1]
1010 set cm [package vcompare $_git_version $vr]
1011 return [expr $cm $op 0]
1012 }
1013
1014 4 {
1015 set type [lindex $args 0]
1016 set name [lindex $args 1]
1017 set parm [lindex $args 2]
1018 set body [lindex $args 3]
1019
1020 if {($type ne {proc} && $type ne {method})} {
1021 error "Invalid arguments to git-version"
1022 }
1023 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
1024 error "Last arm of $type $name must be default"
1025 }
1026
1027 foreach {op vr cb} [lrange $body 0 end-2] {
1028 if {[git-version $op $vr]} {
1029 return [uplevel [list $type $name $parm $cb]]
1030 }
1031 }
1032
1033 return [uplevel [list $type $name $parm [lindex $body end]]]
1034 }
1035
1036 default {
1037 error "git-version >= x"
1038 }
1039
1040 }
1041}
1042
1043if {[git-version < 1.5]} {
1044 catch {wm withdraw .}
Shawn O. Pearce875b7c92007-08-22 02:41:00 -04001045 tk_messageBox \
1046 -icon error \
1047 -type ok \
Michele Ballabioc8c48542007-09-13 15:19:05 +02001048 -title [mc "git-gui: fatal error"] \
Shawn O. Pearce875b7c92007-08-22 02:41:00 -04001049 -message "[appname] requires Git 1.5.0 or later.
Shawn O. Pearced6967022007-07-08 18:48:08 -04001050
1051You are using [git-version]:
1052
1053[git --version]"
1054 exit 1
1055}
Shawn O. Pearce54acdd92007-02-13 23:15:25 -05001056
1057######################################################################
1058##
Shawn O. Pearce875b7c92007-08-22 02:41:00 -04001059## configure our library
1060
Shawn O. Pearce875b7c92007-08-22 02:41:00 -04001061set idx [file join $oguilib tclIndex]
1062if {[catch {set fd [open $idx r]} err]} {
1063 catch {wm withdraw .}
1064 tk_messageBox \
1065 -icon error \
1066 -type ok \
Michele Ballabioc8c48542007-09-13 15:19:05 +02001067 -title [mc "git-gui: fatal error"] \
Shawn O. Pearce875b7c92007-08-22 02:41:00 -04001068 -message $err
1069 exit 1
1070}
1071if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
1072 set idx [list]
1073 while {[gets $fd n] >= 0} {
1074 if {$n ne {} && ![string match #* $n]} {
1075 lappend idx $n
1076 }
1077 }
1078} else {
1079 set idx {}
1080}
1081close $fd
1082
1083if {$idx ne {}} {
1084 set loaded [list]
1085 foreach p $idx {
1086 if {[lsearch -exact $loaded $p] >= 0} continue
1087 source [file join $oguilib $p]
1088 lappend loaded $p
1089 }
1090 unset loaded p
1091} else {
1092 set auto_path [concat [list $oguilib] $auto_path]
1093}
Shawn O. Pearcefc703c22007-09-01 21:58:29 -04001094unset -nocomplain idx fd
Shawn O. Pearce875b7c92007-08-22 02:41:00 -04001095
1096######################################################################
1097##
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001098## config file parsing
1099
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001100git-version proc _parse_config {arr_name args} {
Shawn O. Pearce85f7a942007-10-12 00:54:15 -04001101 >= 1.5.3 {
1102 upvar $arr_name arr
1103 array unset arr
1104 set buf {}
1105 catch {
Shawn O. Pearcea5bb31f2007-10-16 12:55:34 -04001106 set fd_rc [eval \
1107 [list git_read config] \
1108 $args \
1109 [list --null --list]]
Shawn O. Pearce85f7a942007-10-12 00:54:15 -04001110 fconfigure $fd_rc -translation binary
1111 set buf [read $fd_rc]
1112 close $fd_rc
1113 }
1114 foreach line [split $buf "\0"] {
1115 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1116 if {[is_many_config $name]} {
1117 lappend arr($name) $value
1118 } else {
1119 set arr($name) $value
1120 }
Bert Wesarg12b219f2011-10-14 10:14:49 +02001121 } elseif {[regexp {^([^\n]+)$} $line line name]} {
1122 # no value given, but interpreting them as
1123 # boolean will be handled as true
1124 set arr($name) {}
Shawn O. Pearce85f7a942007-10-12 00:54:15 -04001125 }
1126 }
1127 }
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001128 default {
1129 upvar $arr_name arr
1130 array unset arr
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001131 catch {
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001132 set fd_rc [eval [list git_read config --list] $args]
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001133 while {[gets $fd_rc line] >= 0} {
1134 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1135 if {[is_many_config $name]} {
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001136 lappend arr($name) $value
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001137 } else {
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001138 set arr($name) $value
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001139 }
Bert Wesarg12b219f2011-10-14 10:14:49 +02001140 } elseif {[regexp {^([^=]+)$} $line line name]} {
1141 # no value given, but interpreting them as
1142 # boolean will be handled as true
1143 set arr($name) {}
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001144 }
1145 }
1146 close $fd_rc
1147 }
1148 }
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001149}
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001150
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001151proc load_config {include_global} {
Alexander Gavrilov153ad782008-11-16 21:46:47 +03001152 global repo_config global_config system_config default_config
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001153
1154 if {$include_global} {
Alexander Gavrilov153ad782008-11-16 21:46:47 +03001155 _parse_config system_config --system
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001156 _parse_config global_config --global
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001157 }
Shawn O. Pearcef00d5042007-10-12 00:42:17 -04001158 _parse_config repo_config
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001159
1160 foreach name [array names default_config] {
Alexander Gavrilov153ad782008-11-16 21:46:47 +03001161 if {[catch {set v $system_config($name)}]} {
1162 set system_config($name) $default_config($name)
1163 }
1164 }
1165 foreach name [array names system_config] {
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001166 if {[catch {set v $global_config($name)}]} {
Alexander Gavrilov153ad782008-11-16 21:46:47 +03001167 set global_config($name) $system_config($name)
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001168 }
1169 if {[catch {set v $repo_config($name)}]} {
Alexander Gavrilov153ad782008-11-16 21:46:47 +03001170 set repo_config($name) $system_config($name)
Shawn O. Pearce69f85ff2007-10-12 00:34:04 -04001171 }
1172 }
1173}
1174
1175######################################################################
1176##
Shawn O. Pearceba7cc662007-07-17 23:23:56 -04001177## feature option selection
1178
Shawn O. Pearce0b2bc462007-09-27 02:15:29 -04001179if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
Shawn O. Pearceba7cc662007-07-17 23:23:56 -04001180 unset _junk
1181} else {
1182 set subcommand gui
1183}
1184if {$subcommand eq {gui.sh}} {
1185 set subcommand gui
1186}
1187if {$subcommand eq {gui} && [llength $argv] > 0} {
1188 set subcommand [lindex $argv 0]
1189 set argv [lrange $argv 1 end]
1190}
1191
1192enable_option multicommit
1193enable_option branch
1194enable_option transport
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04001195disable_option bare
Shawn O. Pearceba7cc662007-07-17 23:23:56 -04001196
1197switch -- $subcommand {
1198browser -
1199blame {
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04001200 enable_option bare
1201
Shawn O. Pearceba7cc662007-07-17 23:23:56 -04001202 disable_option multicommit
1203 disable_option branch
1204 disable_option transport
1205}
1206citool {
1207 enable_option singlecommit
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04001208 enable_option retcode
Shawn O. Pearceba7cc662007-07-17 23:23:56 -04001209
1210 disable_option multicommit
1211 disable_option branch
1212 disable_option transport
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04001213
1214 while {[llength $argv] > 0} {
1215 set a [lindex $argv 0]
1216 switch -- $a {
1217 --amend {
1218 enable_option initialamend
1219 }
1220 --nocommit {
1221 enable_option nocommit
1222 enable_option nocommitmsg
1223 }
1224 --commitmsg {
1225 disable_option nocommitmsg
1226 }
1227 default {
1228 break
1229 }
1230 }
1231
1232 set argv [lrange $argv 1 end]
1233 }
Shawn O. Pearceba7cc662007-07-17 23:23:56 -04001234}
1235}
1236
1237######################################################################
1238##
Alexander Gavrilove29c0d12008-11-09 18:51:16 +03001239## execution environment
1240
1241set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1242
1243# Suggest our implementation of askpass, if none is set
1244if {![info exists env(SSH_ASKPASS)]} {
1245 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1246}
1247
1248######################################################################
1249##
Shawn O. Pearce2d195162006-11-08 23:42:51 -05001250## repository setup
1251
Petr Baudisbb4812b2008-09-25 00:07:02 +02001252set picked 0
Shawn O. Pearcec6127852007-05-08 21:58:25 -04001253if {[catch {
1254 set _gitdir $env(GIT_DIR)
1255 set _prefix {}
1256 }]
1257 && [catch {
Giuseppe Bilotta87cd09f2010-01-23 11:03:36 +01001258 # beware that from the .git dir this sets _gitdir to .
1259 # and _prefix to the empty string
Shawn O. Pearcec6127852007-05-08 21:58:25 -04001260 set _gitdir [git rev-parse --git-dir]
1261 set _prefix [git rev-parse --show-prefix]
1262 } err]} {
Shawn O. Pearceab08b362007-09-22 03:47:43 -04001263 load_config 1
1264 apply_config
1265 choose_repository::pick
Petr Baudisbb4812b2008-09-25 00:07:02 +02001266 set picked 1
Shawn O. Pearce2d195162006-11-08 23:42:51 -05001267}
Giuseppe Bilotta87cd09f2010-01-23 11:03:36 +01001268
1269# we expand the _gitdir when it's just a single dot (i.e. when we're being
1270# run from the .git dir itself) lest the routines to find the worktree
1271# get confused
1272if {$_gitdir eq "."} {
1273 set _gitdir [pwd]
1274}
1275
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -05001276if {![file isdirectory $_gitdir] && [is_Cygwin]} {
Shawn O. Pearce2f7c9a72007-09-20 21:25:34 -04001277 catch {set _gitdir [exec cygpath --windows $_gitdir]}
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -05001278}
Shawn O. Pearcec950c662007-01-20 21:48:56 -05001279if {![file isdirectory $_gitdir]} {
Shawn O. Pearcedbccbbd2006-11-15 22:45:33 -05001280 catch {wm withdraw .}
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -04001281 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
Shawn O. Pearcedbccbbd2006-11-15 22:45:33 -05001282 exit 1
1283}
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01001284# _gitdir exists, so try loading the config
1285load_config 0
1286apply_config
Pat Thoyts38ec8d32010-10-20 14:29:56 +01001287
1288# v1.7.0 introduced --show-toplevel to return the canonical work-tree
Kyle J. McKayce3e8482015-01-06 02:41:21 -08001289if {[package vcompare $_git_version 1.7.0] >= 0} {
John Murphy4394faf2013-09-04 11:03:48 -04001290 if { [is_Cygwin] } {
1291 catch {set _gitworktree [exec cygpath --windows [git rev-parse --show-toplevel]]}
1292 } else {
1293 set _gitworktree [git rev-parse --show-toplevel]
1294 }
Pat Thoyts38ec8d32010-10-20 14:29:56 +01001295} else {
1296 # try to set work tree from environment, core.worktree or use
1297 # cdup to obtain a relative path to the top of the worktree. If
1298 # run from the top, the ./ prefix ensures normalize expands pwd.
1299 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1300 set _gitworktree [get_config core.worktree]
1301 if {$_gitworktree eq ""} {
1302 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1303 }
Pat Thoyts13a3d632010-07-10 23:40:59 +01001304 }
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01001305}
Pat Thoyts38ec8d32010-10-20 14:29:56 +01001306
Shawn O. Pearcec80d25d2007-08-24 23:15:50 -04001307if {$_prefix ne {}} {
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01001308 if {$_gitworktree eq {}} {
1309 regsub -all {[^/]+/} $_prefix ../ cdup
1310 } else {
1311 set cdup $_gitworktree
1312 }
Shawn O. Pearcec80d25d2007-08-24 23:15:50 -04001313 if {[catch {cd $cdup} err]} {
1314 catch {wm withdraw .}
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -04001315 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
Shawn O. Pearcec80d25d2007-08-24 23:15:50 -04001316 exit 1
1317 }
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01001318 set _gitworktree [pwd]
Shawn O. Pearcec80d25d2007-08-24 23:15:50 -04001319 unset cdup
1320} elseif {![is_enabled bare]} {
Giuseppe Bilotta29e55732010-01-23 11:03:35 +01001321 if {[is_bare]} {
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04001322 catch {wm withdraw .}
Giuseppe Bilotta29e55732010-01-23 11:03:35 +01001323 error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04001324 exit 1
1325 }
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01001326 if {$_gitworktree eq {}} {
1327 set _gitworktree [file dirname $_gitdir]
1328 }
1329 if {[catch {cd $_gitworktree} err]} {
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04001330 catch {wm withdraw .}
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01001331 error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04001332 exit 1
1333 }
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01001334 set _gitworktree [pwd]
Shawn O. Pearcedbccbbd2006-11-15 22:45:33 -05001335}
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04001336set _reponame [file split [file normalize $_gitdir]]
1337if {[lindex $_reponame end] eq {.git}} {
1338 set _reponame [lindex $_reponame end-1]
1339} else {
1340 set _reponame [lindex $_reponame end]
Shawn O. Pearce2d195162006-11-08 23:42:51 -05001341}
Shawn O. Pearce2d195162006-11-08 23:42:51 -05001342
Giuseppe Bilottaa9fa11f2010-01-24 00:59:00 +01001343set env(GIT_DIR) $_gitdir
1344set env(GIT_WORK_TREE) $_gitworktree
1345
Shawn O. Pearce2d195162006-11-08 23:42:51 -05001346######################################################################
1347##
Shawn O. Pearce372ef952007-02-18 02:12:32 -05001348## global init
1349
1350set current_diff_path {}
1351set current_diff_side {}
1352set diff_actions [list]
Shawn O. Pearce372ef952007-02-18 02:12:32 -05001353
1354set HEAD {}
1355set PARENT {}
1356set MERGE_HEAD [list]
1357set commit_type {}
1358set empty_tree {}
1359set current_branch {}
Shawn O. Pearced41b43e2007-07-08 18:40:56 -04001360set is_detached 0
Shawn O. Pearce372ef952007-02-18 02:12:32 -05001361set current_diff_path {}
Shawn O. Pearce9c9f5fa2007-08-23 02:44:13 -04001362set is_3way_diff 0
Jens Lehmanncd846aa2009-09-24 18:56:28 +02001363set is_submodule_diff 0
Alexander Gavrilov3e348382008-09-20 12:19:18 +04001364set is_conflict_diff 0
Shawn O. Pearce372ef952007-02-18 02:12:32 -05001365set selected_commit_type new
Joerg Bornemann8052e782009-04-06 21:59:28 +02001366set diff_empty_count 0
Shawn O. Pearce372ef952007-02-18 02:12:32 -05001367
Alexander Gavrilova9786bb2008-09-08 11:18:52 +04001368set nullid "0000000000000000000000000000000000000000"
1369set nullid2 "0000000000000000000000000000000000000001"
1370
Alexander Gavrilov8c762122008-10-15 13:28:21 +04001371######################################################################
Shawn O. Pearce372ef952007-02-18 02:12:32 -05001372##
Shawn O. Pearcee210e672006-11-06 19:12:58 -05001373## task management
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001374
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001375set rescan_active 0
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001376set diff_active 0
Shawn O. Pearce24263b72006-11-13 16:06:38 -05001377set last_clicked {}
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001378
Shawn O. Pearcee210e672006-11-06 19:12:58 -05001379set disable_on_lock [list]
1380set index_lock_type none
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001381
Shawn O. Pearcee210e672006-11-06 19:12:58 -05001382proc lock_index {type} {
1383 global index_lock_type disable_on_lock
1384
Shawn O. Pearce043f7012006-11-12 18:16:45 -05001385 if {$index_lock_type eq {none}} {
Shawn O. Pearcee210e672006-11-06 19:12:58 -05001386 set index_lock_type $type
1387 foreach w $disable_on_lock {
1388 uplevel #0 $w disabled
1389 }
1390 return 1
Shawn O. Pearce53716a72006-11-18 03:31:25 -05001391 } elseif {$index_lock_type eq "begin-$type"} {
Shawn O. Pearcee210e672006-11-06 19:12:58 -05001392 set index_lock_type $type
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001393 return 1
1394 }
1395 return 0
1396}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001397
Shawn O. Pearcee210e672006-11-06 19:12:58 -05001398proc unlock_index {} {
1399 global index_lock_type disable_on_lock
1400
1401 set index_lock_type none
1402 foreach w $disable_on_lock {
1403 uplevel #0 $w normal
1404 }
1405}
1406
1407######################################################################
1408##
1409## status
1410
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001411proc repository_state {ctvar hdvar mhvar} {
Shawn O. Pearcec950c662007-01-20 21:48:56 -05001412 global current_branch
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001413 upvar $ctvar ct $hdvar hd $mhvar mh
1414
1415 set mh [list]
Shawn O. Pearceec6b4242006-11-06 20:50:59 -05001416
Shawn O. Pearced41b43e2007-07-08 18:40:56 -04001417 load_current_branch
Shawn O. Pearce81347222007-02-12 22:48:56 -05001418 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
Shawn O. Pearce4539eac2006-11-18 02:50:58 -05001419 set hd {}
Shawn O. Pearceec6b4242006-11-06 20:50:59 -05001420 set ct initial
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001421 return
Shawn O. Pearceec6b4242006-11-06 20:50:59 -05001422 }
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001423
Shawn O. Pearcec2758a12007-01-20 21:55:05 -05001424 set merge_head [gitdir MERGE_HEAD]
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001425 if {[file exists $merge_head]} {
1426 set ct merge
1427 set fd_mh [open $merge_head r]
1428 while {[gets $fd_mh line] >= 0} {
1429 lappend mh $line
1430 }
1431 close $fd_mh
1432 return
1433 }
1434
1435 set ct normal
Shawn O. Pearceec6b4242006-11-06 20:50:59 -05001436}
1437
Shawn O. Pearce4539eac2006-11-18 02:50:58 -05001438proc PARENT {} {
1439 global PARENT empty_tree
1440
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001441 set p [lindex $PARENT 0]
1442 if {$p ne {}} {
1443 return $p
Shawn O. Pearce4539eac2006-11-18 02:50:58 -05001444 }
1445 if {$empty_tree eq {}} {
Shawn O. Pearce81347222007-02-12 22:48:56 -05001446 set empty_tree [git mktree << {}]
Shawn O. Pearce4539eac2006-11-18 02:50:58 -05001447 }
1448 return $empty_tree
1449}
1450
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04001451proc force_amend {} {
1452 global selected_commit_type
1453 global HEAD PARENT MERGE_HEAD commit_type
1454
1455 repository_state newType newHEAD newMERGE_HEAD
1456 set HEAD $newHEAD
1457 set PARENT $newHEAD
1458 set MERGE_HEAD $newMERGE_HEAD
1459 set commit_type $newType
1460
1461 set selected_commit_type amend
1462 do_select_commit_type
1463}
1464
Shawn O. Pearce46aaf902007-01-22 17:10:38 -05001465proc rescan {after {honor_trustmtime 1}} {
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001466 global HEAD PARENT MERGE_HEAD commit_type
Shawn O. Pearce699d5602007-07-05 23:16:13 -04001467 global ui_index ui_workdir ui_comm
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001468 global rescan_active file_states
Shawn O. Pearcecf25ddc2007-02-08 18:03:41 -05001469 global repo_config
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001470
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001471 if {$rescan_active > 0 || ![lock_index read]} return
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001472
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001473 repository_state newType newHEAD newMERGE_HEAD
Shawn O. Pearce4539eac2006-11-18 02:50:58 -05001474 if {[string match amend* $commit_type]
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001475 && $newType eq {normal}
1476 && $newHEAD eq $HEAD} {
Shawn O. Pearcee57ca852006-11-06 21:34:10 -05001477 } else {
Shawn O. Pearcef18e40a2006-11-20 21:27:22 -05001478 set HEAD $newHEAD
1479 set PARENT $newHEAD
1480 set MERGE_HEAD $newMERGE_HEAD
1481 set commit_type $newType
Shawn O. Pearcee57ca852006-11-06 21:34:10 -05001482 }
1483
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001484 array unset file_states
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001485
Shawn O. Pearce1e0a92f2007-07-27 02:30:15 -04001486 if {!$::GITGUI_BCK_exists &&
1487 (![$ui_comm edit modified]
1488 || [string trim [$ui_comm get 0.0 end]] eq {})} {
Shawn O. Pearceb2f3bb12007-06-11 19:39:55 -04001489 if {[string match amend* $commit_type]} {
Pat Thoytsfda1ba02012-04-19 11:19:58 +01001490 } elseif {[load_message GITGUI_MSG utf-8]} {
Joshua Williams2cd1fd12008-09-24 14:11:53 -05001491 } elseif {[run_prepare_commit_msg_hook]} {
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001492 } elseif {[load_message MERGE_MSG]} {
1493 } elseif {[load_message SQUASH_MSG]} {
1494 }
Shawn O. Pearceb2c6fcf2006-11-11 16:16:25 -05001495 $ui_comm edit reset
Shawn O. Pearce21d77442006-11-20 21:59:19 -05001496 $ui_comm edit modified false
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001497 }
1498
Shawn O. Pearce46aaf902007-01-22 17:10:38 -05001499 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001500 rescan_stage2 {} $after
Shawn O. Pearcee534f3a2006-11-07 21:27:29 -05001501 } else {
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001502 set rescan_active 1
Christian Stimming1ac17952007-07-21 14:21:34 +02001503 ui_status [mc "Refreshing file status..."]
Shawn O. Pearce0b812612007-07-09 01:17:09 -04001504 set fd_rf [git_read update-index \
1505 -q \
1506 --unmerged \
1507 --ignore-missing \
1508 --refresh \
1509 ]
Shawn O. Pearcee534f3a2006-11-07 21:27:29 -05001510 fconfigure $fd_rf -blocking 0 -translation binary
Shawn O. Pearce390adae2006-11-11 19:40:33 -05001511 fileevent $fd_rf readable \
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001512 [list rescan_stage2 $fd_rf $after]
Shawn O. Pearcee534f3a2006-11-07 21:27:29 -05001513 }
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001514}
1515
Shawn O. Pearce2fe167b2007-09-21 11:44:23 -04001516if {[is_Cygwin]} {
Shawn O. Pearce2fe167b2007-09-21 11:44:23 -04001517 set is_git_info_exclude {}
1518 proc have_info_exclude {} {
Shawn O. Pearce7f83aa22008-05-21 16:40:10 -04001519 global is_git_info_exclude
Shawn O. Pearce2fe167b2007-09-21 11:44:23 -04001520
Shawn O. Pearce7f83aa22008-05-21 16:40:10 -04001521 if {$is_git_info_exclude eq {}} {
1522 if {[catch {exec test -f [gitdir info exclude]}]} {
1523 set is_git_info_exclude 0
1524 } else {
1525 set is_git_info_exclude 1
Shawn O. Pearce2fe167b2007-09-21 11:44:23 -04001526 }
Shawn O. Pearce2fe167b2007-09-21 11:44:23 -04001527 }
Shawn O. Pearce7f83aa22008-05-21 16:40:10 -04001528 return $is_git_info_exclude
Shawn O. Pearce2fe167b2007-09-21 11:44:23 -04001529 }
1530} else {
1531 proc have_info_exclude {} {
1532 return [file readable [gitdir info exclude]]
1533 }
1534}
1535
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001536proc rescan_stage2 {fd after} {
Shawn O. Pearce4539eac2006-11-18 02:50:58 -05001537 global rescan_active buf_rdi buf_rdf buf_rlo
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001538
Shawn O. Pearce043f7012006-11-12 18:16:45 -05001539 if {$fd ne {}} {
Shawn O. Pearcee534f3a2006-11-07 21:27:29 -05001540 read $fd
1541 if {![eof $fd]} return
1542 close $fd
1543 }
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001544
Kyle J. McKayce3e8482015-01-06 02:41:21 -08001545 if {[package vcompare $::_git_version 1.6.3] >= 0} {
Stefan Naewe673eb4a2010-12-10 15:41:09 +00001546 set ls_others [list --exclude-standard]
1547 } else {
1548 set ls_others [list --exclude-per-directory=.gitignore]
1549 if {[have_info_exclude]} {
1550 lappend ls_others "--exclude-from=[gitdir info exclude]"
1551 }
1552 set user_exclude [get_config core.excludesfile]
1553 if {$user_exclude ne {} && [file readable $user_exclude]} {
1554 lappend ls_others "--exclude-from=[file normalize $user_exclude]"
1555 }
Shawn O. Pearce94a4dd92007-07-29 03:22:27 -04001556 }
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001557
Shawn O. Pearce868c8752006-11-07 18:34:09 -05001558 set buf_rdi {}
1559 set buf_rdf {}
1560 set buf_rlo {}
1561
Max Kirillove632b3c2013-08-21 06:29:13 +03001562 set rescan_active 2
Christian Stimming1ac17952007-07-21 14:21:34 +02001563 ui_status [mc "Scanning for modified files ..."]
Jens Lehmanne0db1dd2014-04-08 21:30:51 +02001564 if {[git-version >= "1.7.2"]} {
1565 set fd_di [git_read diff-index --cached --ignore-submodules=dirty -z [PARENT]]
1566 } else {
1567 set fd_di [git_read diff-index --cached -z [PARENT]]
1568 }
Shawn O. Pearce0b812612007-07-09 01:17:09 -04001569 set fd_df [git_read diff-files -z]
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001570
Shawn O. Pearce51a989b2007-01-23 04:07:18 -05001571 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1572 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
Max Kirillove632b3c2013-08-21 06:29:13 +03001573
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001574 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1575 fileevent $fd_df readable [list read_diff_files $fd_df $after]
Max Kirillove632b3c2013-08-21 06:29:13 +03001576
1577 if {[is_config_true gui.displayuntracked]} {
1578 set fd_lo [eval git_read ls-files --others -z $ls_others]
1579 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1580 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1581 incr rescan_active
1582 }
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001583}
1584
Pat Thoytsfda1ba02012-04-19 11:19:58 +01001585proc load_message {file {encoding {}}} {
Shawn O. Pearcec950c662007-01-20 21:48:56 -05001586 global ui_comm
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001587
Shawn O. Pearcec2758a12007-01-20 21:55:05 -05001588 set f [gitdir $file]
Shawn O. Pearcee57ca852006-11-06 21:34:10 -05001589 if {[file isfile $f]} {
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001590 if {[catch {set fd [open $f r]}]} {
1591 return 0
1592 }
Shawn O. Pearce6eb420e2007-07-17 01:50:10 -04001593 fconfigure $fd -eofchar {}
Pat Thoytsfda1ba02012-04-19 11:19:58 +01001594 if {$encoding ne {}} {
1595 fconfigure $fd -encoding $encoding
1596 }
Shawn O. Pearcee57ca852006-11-06 21:34:10 -05001597 set content [string trim [read $fd]]
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001598 close $fd
Shawn O. Pearce4e55d192007-01-25 12:54:59 -05001599 regsub -all -line {[ \r\t]+$} $content {} content
Shawn O. Pearce131f5032006-11-06 16:07:32 -05001600 $ui_comm delete 0.0 end
1601 $ui_comm insert end $content
1602 return 1
1603 }
1604 return 0
1605}
1606
Joshua Williams2cd1fd12008-09-24 14:11:53 -05001607proc run_prepare_commit_msg_hook {} {
1608 global pch_error
1609
1610 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1611 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
Dmitry Ivankovc5c45e12011-06-16 18:22:39 +06001612 # empty file but existent file.
Joshua Williams2cd1fd12008-09-24 14:11:53 -05001613
1614 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1615
1616 if {[file isfile [gitdir MERGE_MSG]]} {
1617 set pcm_source "merge"
1618 set fd_mm [open [gitdir MERGE_MSG] r]
1619 puts -nonewline $fd_pcm [read $fd_mm]
1620 close $fd_mm
1621 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1622 set pcm_source "squash"
1623 set fd_sm [open [gitdir SQUASH_MSG] r]
1624 puts -nonewline $fd_pcm [read $fd_sm]
1625 close $fd_sm
1626 } else {
1627 set pcm_source ""
1628 }
1629
1630 close $fd_pcm
1631
1632 set fd_ph [githook_read prepare-commit-msg \
1633 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1634 if {$fd_ph eq {}} {
1635 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1636 return 0;
1637 }
1638
1639 ui_status [mc "Calling prepare-commit-msg hook..."]
1640 set pch_error {}
1641
1642 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1643 fileevent $fd_ph readable \
1644 [list prepare_commit_msg_hook_wait $fd_ph]
1645
1646 return 1;
1647}
1648
1649proc prepare_commit_msg_hook_wait {fd_ph} {
1650 global pch_error
1651
1652 append pch_error [read $fd_ph]
1653 fconfigure $fd_ph -blocking 1
1654 if {[eof $fd_ph]} {
1655 if {[catch {close $fd_ph}]} {
1656 ui_status [mc "Commit declined by prepare-commit-msg hook."]
1657 hook_failed_popup prepare-commit-msg $pch_error
1658 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1659 exit 1
1660 } else {
1661 load_message PREPARE_COMMIT_MSG
1662 }
1663 set pch_error {}
1664 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1665 return
1666 }
1667 fconfigure $fd_ph -blocking 0
1668 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1669}
1670
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001671proc read_diff_index {fd after} {
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001672 global buf_rdi
1673
1674 append buf_rdi [read $fd]
Shawn O. Pearce868c8752006-11-07 18:34:09 -05001675 set c 0
1676 set n [string length $buf_rdi]
1677 while {$c < $n} {
1678 set z1 [string first "\0" $buf_rdi $c]
1679 if {$z1 == -1} break
1680 incr z1
1681 set z2 [string first "\0" $buf_rdi $z1]
1682 if {$z2 == -1} break
1683
Shawn O. Pearce868c8752006-11-07 18:34:09 -05001684 incr c
Shawn O. Pearce86291552006-11-19 01:00:48 -05001685 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
Shawn O. Pearce51a989b2007-01-23 04:07:18 -05001686 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001687 merge_state \
Shawn O. Pearce51a989b2007-01-23 04:07:18 -05001688 [encoding convertfrom $p] \
Shawn O. Pearce86291552006-11-19 01:00:48 -05001689 [lindex $i 4]? \
1690 [list [lindex $i 0] [lindex $i 2]] \
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001691 [list]
1692 set c $z2
Shawn O. Pearce86291552006-11-19 01:00:48 -05001693 incr c
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001694 }
Shawn O. Pearce868c8752006-11-07 18:34:09 -05001695 if {$c < $n} {
1696 set buf_rdi [string range $buf_rdi $c end]
1697 } else {
1698 set buf_rdi {}
1699 }
1700
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001701 rescan_done $fd buf_rdi $after
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001702}
1703
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001704proc read_diff_files {fd after} {
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001705 global buf_rdf
1706
1707 append buf_rdf [read $fd]
Shawn O. Pearce868c8752006-11-07 18:34:09 -05001708 set c 0
1709 set n [string length $buf_rdf]
1710 while {$c < $n} {
1711 set z1 [string first "\0" $buf_rdf $c]
1712 if {$z1 == -1} break
1713 incr z1
1714 set z2 [string first "\0" $buf_rdf $z1]
1715 if {$z2 == -1} break
1716
Shawn O. Pearce868c8752006-11-07 18:34:09 -05001717 incr c
Shawn O. Pearce86291552006-11-19 01:00:48 -05001718 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
Shawn O. Pearce51a989b2007-01-23 04:07:18 -05001719 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001720 merge_state \
Shawn O. Pearce51a989b2007-01-23 04:07:18 -05001721 [encoding convertfrom $p] \
Shawn O. Pearce86291552006-11-19 01:00:48 -05001722 ?[lindex $i 4] \
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001723 [list] \
Shawn O. Pearce86291552006-11-19 01:00:48 -05001724 [list [lindex $i 0] [lindex $i 2]]
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001725 set c $z2
Shawn O. Pearce86291552006-11-19 01:00:48 -05001726 incr c
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001727 }
Shawn O. Pearce868c8752006-11-07 18:34:09 -05001728 if {$c < $n} {
1729 set buf_rdf [string range $buf_rdf $c end]
1730 } else {
1731 set buf_rdf {}
1732 }
1733
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001734 rescan_done $fd buf_rdf $after
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001735}
1736
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001737proc read_ls_others {fd after} {
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001738 global buf_rlo
1739
1740 append buf_rlo [read $fd]
1741 set pck [split $buf_rlo "\0"]
1742 set buf_rlo [lindex $pck end]
1743 foreach p [lrange $pck 0 end-1] {
Shawn O. Pearce89384102007-09-09 20:38:05 -04001744 set p [encoding convertfrom $p]
1745 if {[string index $p end] eq {/}} {
1746 set p [string range $p 0 end-1]
1747 }
1748 merge_state $p ?O
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001749 }
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001750 rescan_done $fd buf_rlo $after
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001751}
1752
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001753proc rescan_done {fd buf after} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -04001754 global rescan_active current_diff_path
Shawn O. Pearcef7f8d322006-11-13 04:22:42 -05001755 global file_states repo_config
Shawn O. Pearce7f1df792006-11-11 18:38:00 -05001756 upvar $buf to_clear
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001757
Shawn O. Pearcef7f8d322006-11-13 04:22:42 -05001758 if {![eof $fd]} return
1759 set to_clear {}
1760 close $fd
Shawn O. Pearce8f525482006-11-14 01:29:32 -05001761 if {[incr rescan_active -1] > 0} return
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001762
Shawn O. Pearce24263b72006-11-13 16:06:38 -05001763 prune_selection
Shawn O. Pearcef7f8d322006-11-13 04:22:42 -05001764 unlock_index
1765 display_all_files
Alexander Gavrilov7cf45662008-11-16 21:46:48 +03001766 if {$current_diff_path ne {}} { reshow_diff $after }
1767 if {$current_diff_path eq {}} { select_first_diff $after }
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001768}
1769
Shawn O. Pearce24263b72006-11-13 16:06:38 -05001770proc prune_selection {} {
1771 global file_states selected_paths
1772
1773 foreach path [array names selected_paths] {
1774 if {[catch {set still_here $file_states($path)}]} {
1775 unset selected_paths($path)
1776 }
1777 }
1778}
1779
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001780######################################################################
1781##
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001782## ui helpers
1783
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001784proc mapicon {w state path} {
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001785 global all_icons
1786
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001787 if {[catch {set r $all_icons($state$w)}]} {
1788 puts "error: no icon for $w state={$state} $path"
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001789 return file_plain
1790 }
1791 return $r
1792}
1793
1794proc mapdesc {state path} {
1795 global all_descs
1796
1797 if {[catch {set r $all_descs($state)}]} {
1798 puts "error: no desc for state={$state} $path"
1799 return $state
1800 }
1801 return $r
1802}
1803
Shawn O. Pearce699d5602007-07-05 23:16:13 -04001804proc ui_status {msg} {
Shawn O. Pearce906ab7f2007-10-02 12:27:32 -04001805 global main_status
1806 if {[info exists main_status]} {
1807 $main_status show $msg
1808 }
Shawn O. Pearce699d5602007-07-05 23:16:13 -04001809}
1810
1811proc ui_ready {{test {}}} {
Shawn O. Pearce906ab7f2007-10-02 12:27:32 -04001812 global main_status
1813 if {[info exists main_status]} {
1814 $main_status show [mc "Ready."] $test
1815 }
Shawn O. Pearce699d5602007-07-05 23:16:13 -04001816}
1817
Shawn O. Pearce68e009d2006-11-11 17:59:34 -05001818proc escape_path {path} {
Shawn O. Pearce42b922f2007-02-08 17:13:51 -05001819 regsub -all {\\} $path "\\\\" path
Shawn O. Pearce68e009d2006-11-11 17:59:34 -05001820 regsub -all "\n" $path "\\n" path
1821 return $path
1822}
1823
Shawn O. Pearce16403d02006-11-11 21:52:06 -05001824proc short_path {path} {
1825 return [escape_path [lindex [file split $path] end]]
1826}
1827
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001828set next_icon_id 0
Shawn O. Pearce51cc47f2006-11-19 01:20:42 -05001829set null_sha1 [string repeat 0 40]
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001830
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001831proc merge_state {path new_state {head_info {}} {index_info {}}} {
Shawn O. Pearce51cc47f2006-11-19 01:20:42 -05001832 global file_states next_icon_id null_sha1
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001833
Shawn O. Pearce6b292672006-11-07 19:58:37 -05001834 set s0 [string index $new_state 0]
1835 set s1 [string index $new_state 1]
1836
1837 if {[catch {set info $file_states($path)}]} {
1838 set state __
1839 set icon n[incr next_icon_id]
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001840 } else {
Shawn O. Pearce6b292672006-11-07 19:58:37 -05001841 set state [lindex $info 0]
1842 set icon [lindex $info 1]
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001843 if {$head_info eq {}} {set head_info [lindex $info 2]}
1844 if {$index_info eq {}} {set index_info [lindex $info 3]}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001845 }
1846
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001847 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1848 elseif {$s0 eq {_}} {set s0 _}
1849
1850 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1851 elseif {$s1 eq {_}} {set s1 _}
1852
Shawn O. Pearce51cc47f2006-11-19 01:20:42 -05001853 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1854 set head_info [list 0 $null_sha1]
1855 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001856 && $head_info eq {}} {
1857 set head_info $index_info
Jens Lehmann7ec2b692009-12-07 21:35:59 +01001858 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1859 set index_info $head_info
1860 set head_info {}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001861 }
1862
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05001863 set file_states($path) [list $s0$s1 $icon \
1864 $head_info $index_info \
1865 ]
Shawn O. Pearce6b292672006-11-07 19:58:37 -05001866 return $state
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001867}
1868
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001869proc display_file_helper {w path icon_name old_m new_m} {
1870 global file_lists
1871
1872 if {$new_m eq {_}} {
Shawn O. Pearce156b2922007-01-25 22:38:59 -05001873 set lno [lsearch -sorted -exact $file_lists($w) $path]
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001874 if {$lno >= 0} {
1875 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1876 incr lno
1877 $w conf -state normal
1878 $w delete $lno.0 [expr {$lno + 1}].0
1879 $w conf -state disabled
1880 }
1881 } elseif {$old_m eq {_} && $new_m ne {_}} {
1882 lappend file_lists($w) $path
1883 set file_lists($w) [lsort -unique $file_lists($w)]
Shawn O. Pearce156b2922007-01-25 22:38:59 -05001884 set lno [lsearch -sorted -exact $file_lists($w) $path]
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001885 incr lno
1886 $w conf -state normal
1887 $w image create $lno.0 \
1888 -align center -padx 5 -pady 1 \
1889 -name $icon_name \
1890 -image [mapicon $w $new_m $path]
1891 $w insert $lno.1 "[escape_path $path]\n"
1892 $w conf -state disabled
1893 } elseif {$old_m ne $new_m} {
1894 $w conf -state normal
1895 $w image conf $icon_name -image [mapicon $w $new_m $path]
1896 $w conf -state disabled
1897 }
1898}
1899
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001900proc display_file {path state} {
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001901 global file_states selected_paths
1902 global ui_index ui_workdir
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05001903
1904 set old_m [merge_state $path $state]
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001905 set s $file_states($path)
1906 set new_m [lindex $s 0]
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001907 set icon_name [lindex $s 1]
1908
Shawn O. Pearce079d0d52007-01-21 13:18:11 -05001909 set o [string index $old_m 0]
1910 set n [string index $new_m 0]
1911 if {$o eq {U}} {
1912 set o _
Shawn O. Pearce3b4db3c2007-01-21 12:30:51 -05001913 }
Shawn O. Pearce079d0d52007-01-21 13:18:11 -05001914 if {$n eq {U}} {
1915 set n _
1916 }
1917 display_file_helper $ui_index $path $icon_name $o $n
Shawn O. Pearce3b4db3c2007-01-21 12:30:51 -05001918
Shawn O. Pearce079d0d52007-01-21 13:18:11 -05001919 if {[string index $old_m 0] eq {U}} {
1920 set o U
Shawn O. Pearce3b4db3c2007-01-21 12:30:51 -05001921 } else {
Shawn O. Pearcea4b17862007-01-21 13:25:06 -05001922 set o [string index $old_m 1]
Shawn O. Pearce3b4db3c2007-01-21 12:30:51 -05001923 }
Shawn O. Pearce079d0d52007-01-21 13:18:11 -05001924 if {[string index $new_m 0] eq {U}} {
1925 set n U
1926 } else {
1927 set n [string index $new_m 1]
1928 }
1929 display_file_helper $ui_workdir $path $icon_name $o $n
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001930
Shawn O. Pearcee7348172006-11-23 21:40:45 -05001931 if {$new_m eq {__}} {
Shawn O. Pearcee7348172006-11-23 21:40:45 -05001932 unset file_states($path)
1933 catch {unset selected_paths($path)}
Shawn O. Pearcee7348172006-11-23 21:40:45 -05001934 }
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001935}
Shawn O. Pearcee7348172006-11-23 21:40:45 -05001936
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001937proc display_all_files_helper {w path icon_name m} {
1938 global file_lists
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001939
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001940 lappend file_lists($w) $path
1941 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1942 $w image create end \
1943 -align center -padx 5 -pady 1 \
1944 -name $icon_name \
1945 -image [mapicon $w $m $path]
1946 $w insert end "[escape_path $path]\n"
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001947}
1948
Dan Zwelldd6451f2009-08-11 13:50:00 -05001949set files_warning 0
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001950proc display_all_files {} {
Shawn O. Pearce08126652007-01-20 22:06:51 -05001951 global ui_index ui_workdir
Shawn O. Pearce24263b72006-11-13 16:06:38 -05001952 global file_states file_lists
Shawn O. Pearce833eda72007-01-20 23:46:53 -05001953 global last_clicked
Dan Zwelldd6451f2009-08-11 13:50:00 -05001954 global files_warning
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001955
1956 $ui_index conf -state normal
Shawn O. Pearce08126652007-01-20 22:06:51 -05001957 $ui_workdir conf -state normal
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001958
Shawn O. Pearce7f1df792006-11-11 18:38:00 -05001959 $ui_index delete 0.0 end
Shawn O. Pearce08126652007-01-20 22:06:51 -05001960 $ui_workdir delete 0.0 end
Shawn O. Pearce24263b72006-11-13 16:06:38 -05001961 set last_clicked {}
Shawn O. Pearce7f1df792006-11-11 18:38:00 -05001962
Shawn O. Pearce62aac802006-11-11 20:00:35 -05001963 set file_lists($ui_index) [list]
Shawn O. Pearce08126652007-01-20 22:06:51 -05001964 set file_lists($ui_workdir) [list]
Shawn O. Pearce62aac802006-11-11 20:00:35 -05001965
Dan Zwelldd6451f2009-08-11 13:50:00 -05001966 set to_display [lsort [array names file_states]]
1967 set display_limit [get_config gui.maxfilesdisplayed]
Csaba Kiralya117fa22014-12-15 16:38:00 +01001968 set displayed 0
Dan Zwelldd6451f2009-08-11 13:50:00 -05001969 foreach path $to_display {
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05001970 set s $file_states($path)
1971 set m [lindex $s 0]
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001972 set icon_name [lindex $s 1]
1973
Csaba Kiralya117fa22014-12-15 16:38:00 +01001974 if {$displayed > $display_limit && [string index $m 1] eq {O} } {
1975 if {!$files_warning} {
1976 # do not repeatedly warn:
1977 set files_warning 1
1978 info_popup [mc "Display limit (gui.maxfilesdisplayed = %s) reached, not showing all %s files." \
1979 $display_limit [llength $to_display]]
1980 }
1981 continue
1982 }
1983
Shawn O. Pearce3b4db3c2007-01-21 12:30:51 -05001984 set s [string index $m 0]
1985 if {$s ne {U} && $s ne {_}} {
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001986 display_all_files_helper $ui_index $path \
Shawn O. Pearce3b4db3c2007-01-21 12:30:51 -05001987 $icon_name $s
Shawn O. Pearce24263b72006-11-13 16:06:38 -05001988 }
Shawn O. Pearce3b4db3c2007-01-21 12:30:51 -05001989
1990 if {[string index $m 0] eq {U}} {
1991 set s U
1992 } else {
1993 set s [string index $m 1]
1994 }
1995 if {$s ne {_}} {
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05001996 display_all_files_helper $ui_workdir $path \
Shawn O. Pearce3b4db3c2007-01-21 12:30:51 -05001997 $icon_name $s
Csaba Kiralya117fa22014-12-15 16:38:00 +01001998 incr displayed
Shawn O. Pearce24263b72006-11-13 16:06:38 -05001999 }
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002000 }
2001
Shawn O. Pearce93f654d2006-11-07 19:30:54 -05002002 $ui_index conf -state disabled
Shawn O. Pearce08126652007-01-20 22:06:51 -05002003 $ui_workdir conf -state disabled
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002004}
2005
Shawn O. Pearce35874c12007-01-29 00:50:41 -05002006######################################################################
2007##
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002008## icons
2009
2010set filemask {
2011#define mask_width 14
2012#define mask_height 15
2013static unsigned char mask_bits[] = {
2014 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2015 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2016 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2017}
2018
2019image create bitmap file_plain -background white -foreground black -data {
2020#define plain_width 14
2021#define plain_height 15
2022static unsigned char plain_bits[] = {
2023 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2024 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2025 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2026} -maskdata $filemask
2027
2028image create bitmap file_mod -background white -foreground blue -data {
2029#define mod_width 14
2030#define mod_height 15
2031static unsigned char mod_bits[] = {
2032 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2033 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2034 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2035} -maskdata $filemask
2036
Shawn O. Pearce131f5032006-11-06 16:07:32 -05002037image create bitmap file_fulltick -background white -foreground "#007000" -data {
2038#define file_fulltick_width 14
2039#define file_fulltick_height 15
2040static unsigned char file_fulltick_bits[] = {
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002041 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2042 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2043 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2044} -maskdata $filemask
2045
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002046image create bitmap file_question -background white -foreground black -data {
2047#define file_question_width 14
2048#define file_question_height 15
2049static unsigned char file_question_bits[] = {
2050 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2051 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2052 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2053} -maskdata $filemask
2054
2055image create bitmap file_removed -background white -foreground red -data {
2056#define file_removed_width 14
2057#define file_removed_height 15
2058static unsigned char file_removed_bits[] = {
2059 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2060 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2061 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2062} -maskdata $filemask
2063
2064image create bitmap file_merge -background white -foreground blue -data {
2065#define file_merge_width 14
2066#define file_merge_height 15
2067static unsigned char file_merge_bits[] = {
2068 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2069 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2070 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2071} -maskdata $filemask
2072
Gustaf Hendebye681cb72008-08-22 22:10:27 +02002073image create bitmap file_statechange -background white -foreground green -data {
Bert Wesargbf5fe3f2010-12-09 21:46:21 +01002074#define file_statechange_width 14
2075#define file_statechange_height 15
Gustaf Hendebye681cb72008-08-22 22:10:27 +02002076static unsigned char file_statechange_bits[] = {
2077 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
2078 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
2079 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2080} -maskdata $filemask
2081
Shawn O. Pearce6b292672006-11-07 19:58:37 -05002082set ui_index .vpane.files.index.list
Shawn O. Pearce08126652007-01-20 22:06:51 -05002083set ui_workdir .vpane.files.workdir.list
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05002084
2085set all_icons(_$ui_index) file_plain
Peter Oberndorfer0602de42010-01-24 19:54:19 +01002086set all_icons(A$ui_index) file_plain
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05002087set all_icons(M$ui_index) file_fulltick
2088set all_icons(D$ui_index) file_removed
2089set all_icons(U$ui_index) file_merge
Gustaf Hendebye681cb72008-08-22 22:10:27 +02002090set all_icons(T$ui_index) file_statechange
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05002091
2092set all_icons(_$ui_workdir) file_plain
2093set all_icons(M$ui_workdir) file_mod
2094set all_icons(D$ui_workdir) file_question
Shawn O. Pearce3b4db3c2007-01-21 12:30:51 -05002095set all_icons(U$ui_workdir) file_merge
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05002096set all_icons(O$ui_workdir) file_plain
Gustaf Hendebye681cb72008-08-22 22:10:27 +02002097set all_icons(T$ui_workdir) file_statechange
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05002098
Shawn O. Pearce131f5032006-11-06 16:07:32 -05002099set max_status_desc 0
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002100foreach i {
Christian Stimming1ac17952007-07-21 14:21:34 +02002101 {__ {mc "Unmodified"}}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002102
Christian Stimming1ac17952007-07-21 14:21:34 +02002103 {_M {mc "Modified, not staged"}}
2104 {M_ {mc "Staged for commit"}}
2105 {MM {mc "Portions staged for commit"}}
2106 {MD {mc "Staged for commit, missing"}}
Shawn O. Pearceac391602007-01-20 23:00:28 -05002107
Gustaf Hendebye681cb72008-08-22 22:10:27 +02002108 {_T {mc "File type changed, not staged"}}
Bert Wesarg7587f4d2010-12-09 21:46:23 +01002109 {MT {mc "File type changed, old type staged for commit"}}
2110 {AT {mc "File type changed, old type staged for commit"}}
Gustaf Hendebye681cb72008-08-22 22:10:27 +02002111 {T_ {mc "File type changed, staged"}}
Bert Wesarg7587f4d2010-12-09 21:46:23 +01002112 {TM {mc "File type change staged, modification not staged"}}
2113 {TD {mc "File type change staged, file missing"}}
Gustaf Hendebye681cb72008-08-22 22:10:27 +02002114
Christian Stimming1ac17952007-07-21 14:21:34 +02002115 {_O {mc "Untracked, not staged"}}
2116 {A_ {mc "Staged for commit"}}
2117 {AM {mc "Portions staged for commit"}}
2118 {AD {mc "Staged for commit, missing"}}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002119
Christian Stimming1ac17952007-07-21 14:21:34 +02002120 {_D {mc "Missing"}}
2121 {D_ {mc "Staged for removal"}}
2122 {DO {mc "Staged for removal, still present"}}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002123
Alexander Gavrilovff515d82008-08-31 01:00:49 +04002124 {_U {mc "Requires merge resolution"}}
Christian Stimming1ac17952007-07-21 14:21:34 +02002125 {U_ {mc "Requires merge resolution"}}
2126 {UU {mc "Requires merge resolution"}}
2127 {UM {mc "Requires merge resolution"}}
2128 {UD {mc "Requires merge resolution"}}
Alexander Gavrilovff515d82008-08-31 01:00:49 +04002129 {UT {mc "Requires merge resolution"}}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002130 } {
Christian Stimming1ac17952007-07-21 14:21:34 +02002131 set text [eval [lindex $i 1]]
2132 if {$max_status_desc < [string length $text]} {
2133 set max_status_desc [string length $text]
Shawn O. Pearce131f5032006-11-06 16:07:32 -05002134 }
Christian Stimming1ac17952007-07-21 14:21:34 +02002135 set all_descs([lindex $i 0]) $text
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002136}
Shawn O. Pearce21e409a2007-01-20 22:45:19 -05002137unset i
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002138
2139######################################################################
2140##
2141## util
2142
Shawn O. Pearce35874c12007-01-29 00:50:41 -05002143proc scrollbar2many {list mode args} {
2144 foreach w $list {eval $w $mode $args}
2145}
2146
2147proc many2scrollbar {list mode sb top bottom} {
2148 $sb set $top $bottom
2149 foreach w $list {$w $mode moveto $top}
2150}
2151
Shawn O. Pearceb4946932006-11-12 00:40:38 -05002152proc incr_font_size {font {amt 1}} {
2153 set sz [font configure $font -size]
2154 incr sz $amt
2155 font configure $font -size $sz
2156 font configure ${font}bold -size $sz
Shawn O. Pearcedebcd0f2007-06-02 17:15:56 -04002157 font configure ${font}italic -size $sz
Shawn O. Pearceb4946932006-11-12 00:40:38 -05002158}
2159
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002160######################################################################
2161##
2162## ui commands
2163
Christian Stimming1ac17952007-07-21 14:21:34 +02002164set starting_gitk_msg [mc "Starting gitk... please wait..."]
Shawn O. Pearcecc4b1c02006-11-06 23:47:05 -05002165
Jens Lehmann25476c62010-01-02 17:58:49 +01002166proc do_gitk {revs {is_submodule false}} {
2167 global current_diff_path file_states current_diff_side ui_index
Giuseppe Bilottaa9fa11f2010-01-24 00:59:00 +01002168 global _gitdir _gitworktree
Jens Lehmann25476c62010-01-02 17:58:49 +01002169
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -05002170 # -- Always start gitk through whatever we were loaded with. This
2171 # lets us bypass using shell process on Windows systems.
2172 #
Shawn O. Pearce79317e52008-07-29 22:36:58 -07002173 set exe [_which gitk -script]
Shawn O. Pearce02efd482007-07-09 02:10:39 -04002174 set cmd [list [info nameofexecutable] $exe]
Abhijit Menon-Sen15430be2008-07-24 18:58:53 +05302175 if {$exe eq {}} {
2176 error_popup [mc "Couldn't find gitk in PATH"]
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002177 } else {
Shawn O. Pearce501e4c62007-10-02 12:24:44 -04002178 global env
2179
Shawn O. Pearce501e4c62007-10-02 12:24:44 -04002180 set pwd [pwd]
Shawn O. Pearce501e4c62007-10-02 12:24:44 -04002181
Jens Lehmann25476c62010-01-02 17:58:49 +01002182 if {!$is_submodule} {
Giuseppe Bilotta29e55732010-01-23 11:03:35 +01002183 if {![is_bare]} {
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01002184 cd $_gitworktree
2185 }
Jens Lehmann25476c62010-01-02 17:58:49 +01002186 } else {
2187 cd $current_diff_path
2188 if {$revs eq {--}} {
2189 set s $file_states($current_diff_path)
2190 set old_sha1 {}
2191 set new_sha1 {}
2192 switch -glob -- [lindex $s 0] {
2193 M_ { set old_sha1 [lindex [lindex $s 2] 1] }
2194 _M { set old_sha1 [lindex [lindex $s 3] 1] }
2195 MM {
2196 if {$current_diff_side eq $ui_index} {
2197 set old_sha1 [lindex [lindex $s 2] 1]
2198 set new_sha1 [lindex [lindex $s 3] 1]
2199 } else {
2200 set old_sha1 [lindex [lindex $s 3] 1]
2201 }
2202 }
2203 }
2204 set revs $old_sha1...$new_sha1
2205 }
Giuseppe Bilottaa9fa11f2010-01-24 00:59:00 +01002206 # GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2207 # we've been using for the main repository, so unset them.
2208 # TODO we could make life easier (start up faster?) for gitk
2209 # by setting these to the appropriate values to allow gitk
2210 # to skip the heuristics to find their proper value
2211 unset env(GIT_DIR)
2212 unset env(GIT_WORK_TREE)
Jens Lehmann25476c62010-01-02 17:58:49 +01002213 }
Peter Kreftinge27d1062010-01-21 13:15:17 +01002214 eval exec $cmd $revs "--" "--" &
Shawn O. Pearce501e4c62007-10-02 12:24:44 -04002215
Giuseppe Bilottaa9fa11f2010-01-24 00:59:00 +01002216 set env(GIT_DIR) $_gitdir
2217 set env(GIT_WORK_TREE) $_gitworktree
Jens Lehmann25476c62010-01-02 17:58:49 +01002218 cd $pwd
2219
2220 ui_status $::starting_gitk_msg
2221 after 10000 {
2222 ui_ready $starting_gitk_msg
2223 }
2224 }
2225}
2226
2227proc do_git_gui {} {
2228 global current_diff_path
2229
2230 # -- Always start git gui through whatever we were loaded with. This
2231 # lets us bypass using shell process on Windows systems.
2232 #
Jens Lehmann831cc7e2010-01-28 22:20:39 +01002233 set exe [list [_which git]]
Jens Lehmann25476c62010-01-02 17:58:49 +01002234 if {$exe eq {}} {
2235 error_popup [mc "Couldn't find git gui in PATH"]
2236 } else {
2237 global env
Giuseppe Bilottaa9fa11f2010-01-24 00:59:00 +01002238 global _gitdir _gitworktree
Jens Lehmann25476c62010-01-02 17:58:49 +01002239
Giuseppe Bilottaa9fa11f2010-01-24 00:59:00 +01002240 # see note in do_gitk about unsetting these vars when
2241 # running tools in a submodule
2242 unset env(GIT_DIR)
2243 unset env(GIT_WORK_TREE)
Jens Lehmann25476c62010-01-02 17:58:49 +01002244
2245 set pwd [pwd]
2246 cd $current_diff_path
2247
2248 eval exec $exe gui &
2249
Giuseppe Bilottaa9fa11f2010-01-24 00:59:00 +01002250 set env(GIT_DIR) $_gitdir
2251 set env(GIT_WORK_TREE) $_gitworktree
Shawn O. Pearce501e4c62007-10-02 12:24:44 -04002252 cd $pwd
2253
Shawn O. Pearce02efd482007-07-09 02:10:39 -04002254 ui_status $::starting_gitk_msg
Shawn O. Pearced0752422006-11-21 20:33:09 -05002255 after 10000 {
Shawn O. Pearce699d5602007-07-05 23:16:13 -04002256 ui_ready $starting_gitk_msg
Shawn O. Pearced0752422006-11-21 20:33:09 -05002257 }
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002258 }
2259}
2260
Petr Baudisafd54242008-09-25 00:05:53 +02002261proc do_explore {} {
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01002262 global _gitworktree
Petr Baudisafd54242008-09-25 00:05:53 +02002263 set explorer {}
2264 if {[is_Cygwin] || [is_Windows]} {
2265 set explorer "explorer.exe"
2266 } elseif {[is_MacOSX]} {
2267 set explorer "open"
2268 } else {
2269 # freedesktop.org-conforming system is our best shot
2270 set explorer "xdg-open"
2271 }
Markus Heidelberg2e0cda62010-02-25 01:14:22 +01002272 eval exec $explorer [list [file nativename $_gitworktree]] &
Petr Baudisafd54242008-09-25 00:05:53 +02002273}
2274
Shawn O. Pearceb5834d72006-11-12 02:27:28 -05002275set is_quitting 0
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04002276set ret_code 1
Shawn O. Pearcec4fe7722006-11-11 19:32:24 -05002277
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04002278proc terminate_me {win} {
2279 global ret_code
2280 if {$win ne {.}} return
2281 exit $ret_code
2282}
2283
2284proc do_quit {{rc {1}}} {
Shawn O. Pearcec950c662007-01-20 21:48:56 -05002285 global ui_comm is_quitting repo_config commit_type
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -04002286 global GITGUI_BCK_exists GITGUI_BCK_i
Shawn O. Pearce95b002e2008-02-07 02:35:25 -05002287 global ui_comm_spell
Pat Thoytsc80d7be2010-01-26 00:05:31 +00002288 global ret_code use_ttk
Shawn O. Pearcec4fe7722006-11-11 19:32:24 -05002289
Shawn O. Pearceb5834d72006-11-12 02:27:28 -05002290 if {$is_quitting} return
2291 set is_quitting 1
Shawn O. Pearce131f5032006-11-06 16:07:32 -05002292
Shawn O. Pearcedb7f34d2007-02-08 17:47:17 -05002293 if {[winfo exists $ui_comm]} {
2294 # -- Stash our current commit buffer.
2295 #
2296 set save [gitdir GITGUI_MSG]
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -04002297 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
2298 file rename -force [gitdir GITGUI_BCK] $save
2299 set GITGUI_BCK_exists 0
Shawn O. Pearcedb7f34d2007-02-08 17:47:17 -05002300 } else {
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -04002301 set msg [string trim [$ui_comm get 0.0 end]]
2302 regsub -all -line {[ \r\t]+$} $msg {} msg
2303 if {(![string match amend* $commit_type]
2304 || [$ui_comm edit modified])
2305 && $msg ne {}} {
2306 catch {
2307 set fd [open $save w]
Pat Thoytsfda1ba02012-04-19 11:19:58 +01002308 fconfigure $fd -encoding utf-8
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -04002309 puts -nonewline $fd $msg
2310 close $fd
2311 }
2312 } else {
2313 catch {file delete $save}
2314 }
2315 }
2316
Shawn O. Pearce95b002e2008-02-07 02:35:25 -05002317 # -- Cancel our spellchecker if its running.
2318 #
2319 if {[info exists ui_comm_spell]} {
2320 $ui_comm_spell stop
2321 }
2322
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -04002323 # -- Remove our editor backup, its not needed.
2324 #
2325 after cancel $GITGUI_BCK_i
2326 if {$GITGUI_BCK_exists} {
2327 catch {file delete [gitdir GITGUI_BCK]}
Shawn O. Pearce131f5032006-11-06 16:07:32 -05002328 }
Shawn O. Pearce131f5032006-11-06 16:07:32 -05002329
Shawn O. Pearcedb7f34d2007-02-08 17:47:17 -05002330 # -- Stash our current window geometry into this repository.
2331 #
Alexey Borzenkoved7b6032009-09-08 22:39:33 +04002332 set cfg_wmstate [wm state .]
2333 if {[catch {set rc_wmstate $repo_config(gui.wmstate)}]} {
2334 set rc_wmstate {}
2335 }
2336 if {$cfg_wmstate ne $rc_wmstate} {
2337 catch {git config gui.wmstate $cfg_wmstate}
2338 }
2339 if {$cfg_wmstate eq {zoomed}} {
2340 # on Windows wm geometry will lie about window
2341 # position (but not size) when window is zoomed
2342 # restore the window before querying wm geometry
2343 wm state . normal
2344 }
Shawn O. Pearcedb7f34d2007-02-08 17:47:17 -05002345 set cfg_geometry [list]
2346 lappend cfg_geometry [wm geometry .]
Pat Thoytsc80d7be2010-01-26 00:05:31 +00002347 if {$use_ttk} {
2348 lappend cfg_geometry [.vpane sashpos 0]
2349 lappend cfg_geometry [.vpane.files sashpos 0]
2350 } else {
2351 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2352 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2353 }
Shawn O. Pearcedb7f34d2007-02-08 17:47:17 -05002354 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2355 set rc_geometry {}
2356 }
2357 if {$cfg_geometry ne $rc_geometry} {
Shawn O. Pearce81347222007-02-12 22:48:56 -05002358 catch {git config gui.geometry $cfg_geometry}
Shawn O. Pearcedb7f34d2007-02-08 17:47:17 -05002359 }
Shawn O. Pearce51f4d162006-11-12 03:47:00 -05002360 }
2361
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04002362 set ret_code $rc
Jindrich Makovicka60204dd2009-12-04 10:28:44 +01002363
2364 # Briefly enable send again, working around Tk bug
2365 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2366 tk appname [appname]
2367
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002368 destroy .
2369}
2370
2371proc do_rescan {} {
Shawn O. Pearce699d5602007-07-05 23:16:13 -04002372 rescan ui_ready
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002373}
2374
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04002375proc ui_do_rescan {} {
Alexander Gavrilov7cf45662008-11-16 21:46:48 +03002376 rescan {force_first_diff ui_ready}
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04002377}
2378
Shawn O. Pearce6e27d822006-11-06 20:03:36 -05002379proc do_commit {} {
Shawn O. Pearceec6b4242006-11-06 20:50:59 -05002380 commit_tree
Shawn O. Pearce6e27d822006-11-06 20:03:36 -05002381}
2382
Alexander Gavrilov7cf45662008-11-16 21:46:48 +03002383proc next_diff {{after {}}} {
Abhijit Menon-Sen8a965b82008-06-13 03:42:10 +05302384 global next_diff_p next_diff_w next_diff_i
Alexander Gavrilov7cf45662008-11-16 21:46:48 +03002385 show_diff $next_diff_p $next_diff_w {} {} $after
Alexander Gavrilov29853b92008-08-31 01:02:56 +04002386}
2387
2388proc find_anchor_pos {lst name} {
2389 set lid [lsearch -sorted -exact $lst $name]
2390
2391 if {$lid == -1} {
2392 set lid 0
2393 foreach lname $lst {
2394 if {$lname >= $name} break
2395 incr lid
2396 }
2397 }
2398
2399 return $lid
2400}
2401
2402proc find_file_from {flist idx delta path mmask} {
2403 global file_states
2404
2405 set len [llength $flist]
2406 while {$idx >= 0 && $idx < $len} {
2407 set name [lindex $flist $idx]
2408
2409 if {$name ne $path && [info exists file_states($name)]} {
2410 set state [lindex $file_states($name) 0]
2411
2412 if {$mmask eq {} || [regexp $mmask $state]} {
2413 return $idx
2414 }
2415 }
2416
2417 incr idx $delta
2418 }
2419
2420 return {}
2421}
2422
2423proc find_next_diff {w path {lno {}} {mmask {}}} {
2424 global next_diff_p next_diff_w next_diff_i
2425 global file_lists ui_index ui_workdir
2426
2427 set flist $file_lists($w)
2428 if {$lno eq {}} {
2429 set lno [find_anchor_pos $flist $path]
2430 } else {
2431 incr lno -1
2432 }
2433
2434 if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} {
2435 if {$w eq $ui_index} {
2436 set mmask "^$mmask"
2437 } else {
2438 set mmask "$mmask\$"
2439 }
2440 }
2441
2442 set idx [find_file_from $flist $lno 1 $path $mmask]
2443 if {$idx eq {}} {
2444 incr lno -1
2445 set idx [find_file_from $flist $lno -1 $path $mmask]
2446 }
2447
2448 if {$idx ne {}} {
2449 set next_diff_w $w
2450 set next_diff_p [lindex $flist $idx]
2451 set next_diff_i [expr {$idx+1}]
2452 return 1
2453 } else {
2454 return 0
2455 }
2456}
2457
2458proc next_diff_after_action {w path {lno {}} {mmask {}}} {
2459 global current_diff_path
2460
2461 if {$path ne $current_diff_path} {
2462 return {}
2463 } elseif {[find_next_diff $w $path $lno $mmask]} {
2464 return {next_diff;}
2465 } else {
2466 return {reshow_diff;}
2467 }
2468}
2469
Alexander Gavrilov7cf45662008-11-16 21:46:48 +03002470proc select_first_diff {after} {
Alexander Gavrilov29853b92008-08-31 01:02:56 +04002471 global ui_workdir
2472
2473 if {[find_next_diff $ui_workdir {} 1 {^_?U}] ||
2474 [find_next_diff $ui_workdir {} 1 {[^O]$}]} {
Alexander Gavrilov7cf45662008-11-16 21:46:48 +03002475 next_diff $after
2476 } else {
2477 uplevel #0 $after
Alexander Gavrilov29853b92008-08-31 01:02:56 +04002478 }
Abhijit Menon-Sen8a965b82008-06-13 03:42:10 +05302479}
2480
Alexander Gavrilov7cf45662008-11-16 21:46:48 +03002481proc force_first_diff {after} {
2482 global ui_workdir current_diff_path file_states
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04002483
2484 if {[info exists file_states($current_diff_path)]} {
2485 set state [lindex $file_states($current_diff_path) 0]
Alexander Gavrilov7cf45662008-11-16 21:46:48 +03002486 } else {
2487 set state {OO}
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04002488 }
2489
Alexander Gavrilov7cf45662008-11-16 21:46:48 +03002490 set reselect 0
2491 if {[string first {U} $state] >= 0} {
2492 # Already a conflict, do nothing
2493 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} {
2494 set reselect 1
2495 } elseif {[string index $state 1] ne {O}} {
2496 # Already a diff & no conflicts, do nothing
2497 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} {
2498 set reselect 1
2499 }
2500
2501 if {$reselect} {
2502 next_diff $after
2503 } else {
2504 uplevel #0 $after
2505 }
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04002506}
2507
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002508proc toggle_or_diff {w x y} {
Shawn O. Pearce20a53c02007-01-21 11:37:58 -05002509 global file_states file_lists current_diff_path ui_index ui_workdir
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002510 global last_clicked selected_paths
Shawn O. Pearce131f5032006-11-06 16:07:32 -05002511
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002512 set pos [split [$w index @$x,$y] .]
2513 set lno [lindex $pos 0]
2514 set col [lindex $pos 1]
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002515 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2516 if {$path eq {}} {
2517 set last_clicked {}
2518 return
2519 }
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002520
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002521 set last_clicked [list $w $lno]
2522 array unset selected_paths
2523 $ui_index tag remove in_sel 0.0 end
Shawn O. Pearce08126652007-01-20 22:06:51 -05002524 $ui_workdir tag remove in_sel 0.0 end
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002525
Alexander Gavrilov3e348382008-09-20 12:19:18 +04002526 # Determine the state of the file
Alexander Gavrilov617ceee2008-08-31 00:54:19 +04002527 if {[info exists file_states($path)]} {
2528 set state [lindex $file_states($path) 0]
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04002529 } else {
2530 set state {__}
Alexander Gavrilov617ceee2008-08-31 00:54:19 +04002531 }
2532
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04002533 # Restage the file, or simply show the diff
Richard Quirkcead78e2008-06-20 16:58:15 +02002534 if {$col == 0 && $y > 1} {
Alexander Gavrilov3e348382008-09-20 12:19:18 +04002535 # Conflicts need special handling
2536 if {[string first {U} $state] >= 0} {
Alexander Gavrilov0aea2842008-09-30 12:12:16 +04002537 # $w must always be $ui_workdir, but...
2538 if {$w ne $ui_workdir} { set lno {} }
2539 merge_stage_workdir $path $lno
Alexander Gavrilov3e348382008-09-20 12:19:18 +04002540 return
2541 }
2542
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04002543 if {[string index $state 1] eq {O}} {
2544 set mmask {}
2545 } else {
2546 set mmask {[^O]}
2547 }
2548
2549 set after [next_diff_after_action $w $path $lno $mmask]
Abhijit Menon-Sen8a965b82008-06-13 03:42:10 +05302550
Shawn O. Pearcede5f6d52007-01-20 23:10:30 -05002551 if {$w eq $ui_index} {
Shawn O. Pearce74d18d22006-11-19 00:37:49 -05002552 update_indexinfo \
Shawn O. Pearce93e912c2007-01-20 23:07:04 -05002553 "Unstaging [short_path $path] from commit" \
Shawn O. Pearce74d18d22006-11-19 00:37:49 -05002554 [list $path] \
Shawn O. Pearce699d5602007-07-05 23:16:13 -04002555 [concat $after [list ui_ready]]
Shawn O. Pearcede5f6d52007-01-20 23:10:30 -05002556 } elseif {$w eq $ui_workdir} {
Shawn O. Pearce74d18d22006-11-19 00:37:49 -05002557 update_index \
Shawn O. Pearce4d583c82007-01-20 19:07:46 -05002558 "Adding [short_path $path]" \
Shawn O. Pearce74d18d22006-11-19 00:37:49 -05002559 [list $path] \
Shawn O. Pearce699d5602007-07-05 23:16:13 -04002560 [concat $after [list ui_ready]]
Shawn O. Pearce74d18d22006-11-19 00:37:49 -05002561 }
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002562 } else {
Bert Wesarga8ca7862011-10-14 10:19:26 +02002563 set selected_paths($path) 1
Shawn O. Pearce03e4ec52006-11-11 17:52:16 -05002564 show_diff $path $w $lno
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002565 }
2566}
2567
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002568proc add_one_to_selection {w x y} {
Shawn O. Pearce833eda72007-01-20 23:46:53 -05002569 global file_lists last_clicked selected_paths
Shawn O. Pearce7f1df792006-11-11 18:38:00 -05002570
Shawn O. Pearce833eda72007-01-20 23:46:53 -05002571 set lno [lindex [split [$w index @$x,$y] .] 0]
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002572 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2573 if {$path eq {}} {
2574 set last_clicked {}
2575 return
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002576 }
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002577
Shawn O. Pearce833eda72007-01-20 23:46:53 -05002578 if {$last_clicked ne {}
2579 && [lindex $last_clicked 0] ne $w} {
2580 array unset selected_paths
2581 [lindex $last_clicked 0] tag remove in_sel 0.0 end
2582 }
2583
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002584 set last_clicked [list $w $lno]
2585 if {[catch {set in_sel $selected_paths($path)}]} {
2586 set in_sel 0
2587 }
2588 if {$in_sel} {
2589 unset selected_paths($path)
2590 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2591 } else {
2592 set selected_paths($path) 1
2593 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2594 }
2595}
2596
2597proc add_range_to_selection {w x y} {
Shawn O. Pearce833eda72007-01-20 23:46:53 -05002598 global file_lists last_clicked selected_paths
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002599
2600 if {[lindex $last_clicked 0] ne $w} {
2601 toggle_or_diff $w $x $y
2602 return
2603 }
2604
Shawn O. Pearce833eda72007-01-20 23:46:53 -05002605 set lno [lindex [split [$w index @$x,$y] .] 0]
Shawn O. Pearce24263b72006-11-13 16:06:38 -05002606 set lc [lindex $last_clicked 1]
2607 if {$lc < $lno} {
2608 set begin $lc
2609 set end $lno
2610 } else {
2611 set begin $lno
2612 set end $lc
2613 }
2614
2615 foreach path [lrange $file_lists($w) \
2616 [expr {$begin - 1}] \
2617 [expr {$end - 1}]] {
2618 set selected_paths($path) 1
2619 }
2620 $w tag add in_sel $begin.0 [expr {$end + 1}].0
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002621}
2622
Jonathan del Strotherc91ee2b2008-04-01 11:54:03 +01002623proc show_more_context {} {
2624 global repo_config
2625 if {$repo_config(gui.diffcontext) < 99} {
2626 incr repo_config(gui.diffcontext)
2627 reshow_diff
2628 }
2629}
2630
2631proc show_less_context {} {
2632 global repo_config
Clemens Buchacher55ba8a32008-08-30 18:45:27 +02002633 if {$repo_config(gui.diffcontext) > 1} {
Jonathan del Strotherc91ee2b2008-04-01 11:54:03 +01002634 incr repo_config(gui.diffcontext) -1
2635 reshow_diff
2636 }
2637}
2638
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002639######################################################################
2640##
Shawn O. Pearce92148d82006-11-12 05:27:00 -05002641## ui construction
2642
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002643set ui_comm {}
2644
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002645# -- Menu Bar
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05002646#
Shawn O. Pearceb4946932006-11-12 00:40:38 -05002647menu .mbar -tearoff 0
Daniel A. Steffena91be3f2008-08-16 03:20:09 +02002648if {[is_MacOSX]} {
2649 # -- Apple Menu (Mac OS X only)
2650 #
2651 .mbar add cascade -label Apple -menu .mbar.apple
2652 menu .mbar.apple
2653}
Christian Stimming1ac17952007-07-21 14:21:34 +02002654.mbar add cascade -label [mc Repository] -menu .mbar.repository
2655.mbar add cascade -label [mc Edit] -menu .mbar.edit
Shawn O. Pearce64a906f2007-02-08 18:10:05 -05002656if {[is_enabled branch]} {
Christian Stimming1ac17952007-07-21 14:21:34 +02002657 .mbar add cascade -label [mc Branch] -menu .mbar.branch
Shawn O. Pearce700a65c2006-11-24 17:30:12 -05002658}
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002659if {[is_enabled multicommit] || [is_enabled singlecommit]} {
Harri Ilari Tapio Liusvaaraa9813cb2007-09-12 23:02:35 +03002660 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002661}
Shawn O. Pearce64a906f2007-02-08 18:10:05 -05002662if {[is_enabled transport]} {
Christian Stimming1ac17952007-07-21 14:21:34 +02002663 .mbar add cascade -label [mc Merge] -menu .mbar.merge
Shawn O. Pearce6bdf5e52007-10-07 22:23:54 -07002664 .mbar add cascade -label [mc Remote] -menu .mbar.remote
Shawn O. Pearce4ccdab02006-11-12 16:20:36 -05002665}
Alexander Gavrilov0ce76de2008-11-16 21:46:49 +03002666if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2667 .mbar add cascade -label [mc Tools] -menu .mbar.tools
2668}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002669
Shawn O. Pearcea4abfa62006-11-20 23:01:47 -05002670# -- Repository Menu
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05002671#
Shawn O. Pearcea4abfa62006-11-20 23:01:47 -05002672menu .mbar.repository
Shawn O. Pearce35874c12007-01-29 00:50:41 -05002673
Giuseppe Bilotta29e55732010-01-23 11:03:35 +01002674if {![is_bare]} {
2675 .mbar.repository add command \
2676 -label [mc "Explore Working Copy"] \
2677 -command {do_explore}
Pat Thoyts224cce82013-09-12 21:15:19 +01002678}
2679
2680if {[is_Windows]} {
2681 .mbar.repository add command \
2682 -label [mc "Git Bash"] \
2683 -command {eval exec [auto_execok start] \
2684 [list "Git Bash" bash --login -l &]}
2685}
2686
2687if {[is_Windows] || ![is_bare]} {
Giuseppe Bilotta29e55732010-01-23 11:03:35 +01002688 .mbar.repository add separator
2689}
Petr Baudisafd54242008-09-25 00:05:53 +02002690
2691.mbar.repository add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02002692 -label [mc "Browse Current Branch's Files"] \
Shawn O. Pearcec74b6c62007-05-08 20:33:47 -04002693 -command {browser::new $current_branch}
Shawn O. Pearcea8139882007-07-23 01:11:08 -04002694set ui_browse_current [.mbar.repository index last]
Shawn O. Pearce8e891fa2007-07-18 01:39:27 -04002695.mbar.repository add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02002696 -label [mc "Browse Branch Files..."] \
Shawn O. Pearce8e891fa2007-07-18 01:39:27 -04002697 -command browser_open::dialog
Shawn O. Pearce35874c12007-01-29 00:50:41 -05002698.mbar.repository add separator
2699
Shawn O. Pearced0752422006-11-21 20:33:09 -05002700.mbar.repository add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02002701 -label [mc "Visualize Current Branch's History"] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002702 -command {do_gitk $current_branch}
Shawn O. Pearcea8139882007-07-23 01:11:08 -04002703set ui_visualize_current [.mbar.repository index last]
Shawn O. Pearce5753ef12007-01-25 13:01:16 -05002704.mbar.repository add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02002705 -label [mc "Visualize All Branch History"] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002706 -command {do_gitk --all}
Shawn O. Pearced0752422006-11-21 20:33:09 -05002707.mbar.repository add separator
Shawn O. Pearce75e355d2006-11-20 22:22:10 -05002708
Shawn O. Pearcea8139882007-07-23 01:11:08 -04002709proc current_branch_write {args} {
2710 global current_branch
2711 .mbar.repository entryconf $::ui_browse_current \
Christian Stimming1ac17952007-07-21 14:21:34 +02002712 -label [mc "Browse %s's Files" $current_branch]
Shawn O. Pearcea8139882007-07-23 01:11:08 -04002713 .mbar.repository entryconf $::ui_visualize_current \
Christian Stimming1ac17952007-07-21 14:21:34 +02002714 -label [mc "Visualize %s's History" $current_branch]
Shawn O. Pearcea8139882007-07-23 01:11:08 -04002715}
2716trace add variable current_branch write current_branch_write
2717
Shawn O. Pearcecf25ddc2007-02-08 18:03:41 -05002718if {[is_enabled multicommit]} {
Christian Stimming1ac17952007-07-21 14:21:34 +02002719 .mbar.repository add command -label [mc "Database Statistics"] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002720 -command do_stats
Shawn O. Pearce0fd49d02007-01-24 15:21:01 -05002721
Christian Stimming1ac17952007-07-21 14:21:34 +02002722 .mbar.repository add command -label [mc "Compress Database"] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002723 -command do_gc
Shawn O. Pearce4aca7402006-11-15 22:35:26 -05002724
Christian Stimming1ac17952007-07-21 14:21:34 +02002725 .mbar.repository add command -label [mc "Verify Database"] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002726 -command do_fsck_objects
Shawn O. Pearce444f92d2006-11-20 21:43:41 -05002727
Shawn O. Pearcea4abfa62006-11-20 23:01:47 -05002728 .mbar.repository add separator
Shawn O. Pearce75e355d2006-11-20 22:22:10 -05002729
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -05002730 if {[is_Cygwin]} {
2731 .mbar.repository add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02002732 -label [mc "Create Desktop Icon"] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002733 -command do_cygwin_shortcut
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -05002734 } elseif {[is_Windows]} {
Shawn O. Pearcea4abfa62006-11-20 23:01:47 -05002735 .mbar.repository add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02002736 -label [mc "Create Desktop Icon"] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002737 -command do_windows_shortcut
Shawn O. Pearce06c31112006-11-18 00:31:00 -05002738 } elseif {[is_MacOSX]} {
Shawn O. Pearcea4abfa62006-11-20 23:01:47 -05002739 .mbar.repository add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02002740 -label [mc "Create Desktop Icon"] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002741 -command do_macosx_app
Shawn O. Pearce4aca7402006-11-15 22:35:26 -05002742 }
Shawn O. Pearce4ccdab02006-11-12 16:20:36 -05002743}
Shawn O. Pearce85ab3132006-11-25 03:38:39 -05002744
Soeren Finsteraf894942008-07-07 18:50:13 +02002745if {[is_MacOSX]} {
2746 proc ::tk::mac::Quit {args} { do_quit }
2747} else {
2748 .mbar.repository add command -label [mc Quit] \
2749 -command do_quit \
2750 -accelerator $M1T-Q
2751}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002752
Shawn O. Pearce98616712006-11-11 15:51:41 -05002753# -- Edit Menu
2754#
2755menu .mbar.edit
Christian Stimming1ac17952007-07-21 14:21:34 +02002756.mbar.edit add command -label [mc Undo] \
Shawn O. Pearce98616712006-11-11 15:51:41 -05002757 -command {catch {[focus] edit undo}} \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002758 -accelerator $M1T-Z
Christian Stimming1ac17952007-07-21 14:21:34 +02002759.mbar.edit add command -label [mc Redo] \
Shawn O. Pearce98616712006-11-11 15:51:41 -05002760 -command {catch {[focus] edit redo}} \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002761 -accelerator $M1T-Y
Shawn O. Pearce98616712006-11-11 15:51:41 -05002762.mbar.edit add separator
Christian Stimming1ac17952007-07-21 14:21:34 +02002763.mbar.edit add command -label [mc Cut] \
Shawn O. Pearce98616712006-11-11 15:51:41 -05002764 -command {catch {tk_textCut [focus]}} \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002765 -accelerator $M1T-X
Christian Stimming1ac17952007-07-21 14:21:34 +02002766.mbar.edit add command -label [mc Copy] \
Shawn O. Pearce98616712006-11-11 15:51:41 -05002767 -command {catch {tk_textCopy [focus]}} \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002768 -accelerator $M1T-C
Christian Stimming1ac17952007-07-21 14:21:34 +02002769.mbar.edit add command -label [mc Paste] \
Shawn O. Pearce98616712006-11-11 15:51:41 -05002770 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002771 -accelerator $M1T-V
Christian Stimming1ac17952007-07-21 14:21:34 +02002772.mbar.edit add command -label [mc Delete] \
Shawn O. Pearce98616712006-11-11 15:51:41 -05002773 -command {catch {[focus] delete sel.first sel.last}} \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002774 -accelerator Del
Shawn O. Pearce98616712006-11-11 15:51:41 -05002775.mbar.edit add separator
Christian Stimming1ac17952007-07-21 14:21:34 +02002776.mbar.edit add command -label [mc "Select All"] \
Shawn O. Pearce98616712006-11-11 15:51:41 -05002777 -command {catch {[focus] tag add sel 0.0 end}} \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002778 -accelerator $M1T-A
Shawn O. Pearce98616712006-11-11 15:51:41 -05002779
Shawn O. Pearce85ab3132006-11-25 03:38:39 -05002780# -- Branch Menu
2781#
Shawn O. Pearce64a906f2007-02-08 18:10:05 -05002782if {[is_enabled branch]} {
Shawn O. Pearce700a65c2006-11-24 17:30:12 -05002783 menu .mbar.branch
2784
Christian Stimming1ac17952007-07-21 14:21:34 +02002785 .mbar.branch add command -label [mc "Create..."] \
Shawn O. Pearceb1fa2bf2007-07-03 22:57:18 -04002786 -command branch_create::dialog \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002787 -accelerator $M1T-N
Shawn O. Pearce700a65c2006-11-24 17:30:12 -05002788 lappend disable_on_lock [list .mbar.branch entryconf \
2789 [.mbar.branch index last] -state]
2790
Christian Stimming1ac17952007-07-21 14:21:34 +02002791 .mbar.branch add command -label [mc "Checkout..."] \
Shawn O. Pearced41b43e2007-07-08 18:40:56 -04002792 -command branch_checkout::dialog \
2793 -accelerator $M1T-O
2794 lappend disable_on_lock [list .mbar.branch entryconf \
2795 [.mbar.branch index last] -state]
2796
Christian Stimming1ac17952007-07-21 14:21:34 +02002797 .mbar.branch add command -label [mc "Rename..."] \
Shawn O. Pearce61f82ce2007-05-28 12:52:57 -04002798 -command branch_rename::dialog
2799 lappend disable_on_lock [list .mbar.branch entryconf \
2800 [.mbar.branch index last] -state]
2801
Christian Stimming1ac17952007-07-21 14:21:34 +02002802 .mbar.branch add command -label [mc "Delete..."] \
Shawn O. Pearce3206c632007-07-03 23:33:59 -04002803 -command branch_delete::dialog
Shawn O. Pearce700a65c2006-11-24 17:30:12 -05002804 lappend disable_on_lock [list .mbar.branch entryconf \
2805 [.mbar.branch index last] -state]
Shawn O. Pearcefd234df2007-02-26 11:22:10 -05002806
Christian Stimming1ac17952007-07-21 14:21:34 +02002807 .mbar.branch add command -label [mc "Reset..."] \
Shawn O. Pearcea6c9b082007-05-02 13:56:27 -04002808 -command merge::reset_hard
Shawn O. Pearcefd234df2007-02-26 11:22:10 -05002809 lappend disable_on_lock [list .mbar.branch entryconf \
2810 [.mbar.branch index last] -state]
Shawn O. Pearce700a65c2006-11-24 17:30:12 -05002811}
2812
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002813# -- Commit Menu
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05002814#
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04002815proc commit_btn_caption {} {
2816 if {[is_enabled nocommit]} {
2817 return [mc "Done"]
2818 } else {
2819 return [mc Commit@@verb]
2820 }
2821}
2822
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002823if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2824 menu .mbar.commit
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05002825
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07002826 if {![is_enabled nocommit]} {
2827 .mbar.commit add radiobutton \
2828 -label [mc "New Commit"] \
2829 -command do_select_commit_type \
2830 -variable selected_commit_type \
2831 -value new
2832 lappend disable_on_lock \
2833 [list .mbar.commit entryconf [.mbar.commit index last] -state]
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05002834
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07002835 .mbar.commit add radiobutton \
2836 -label [mc "Amend Last Commit"] \
2837 -command do_select_commit_type \
2838 -variable selected_commit_type \
2839 -value amend
2840 lappend disable_on_lock \
2841 [list .mbar.commit entryconf [.mbar.commit index last] -state]
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05002842
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07002843 .mbar.commit add separator
2844 }
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05002845
Christian Stimming1ac17952007-07-21 14:21:34 +02002846 .mbar.commit add command -label [mc Rescan] \
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04002847 -command ui_do_rescan \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002848 -accelerator F5
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002849 lappend disable_on_lock \
2850 [list .mbar.commit entryconf [.mbar.commit index last] -state]
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05002851
Christian Stimming1ac17952007-07-21 14:21:34 +02002852 .mbar.commit add command -label [mc "Stage To Commit"] \
Shawn O. Pearcecd16a6c2007-11-08 02:22:21 -05002853 -command do_add_selection \
2854 -accelerator $M1T-T
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002855 lappend disable_on_lock \
2856 [list .mbar.commit entryconf [.mbar.commit index last] -state]
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05002857
Christian Stimming1ac17952007-07-21 14:21:34 +02002858 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002859 -command do_add_all \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002860 -accelerator $M1T-I
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002861 lappend disable_on_lock \
2862 [list .mbar.commit entryconf [.mbar.commit index last] -state]
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05002863
Christian Stimming1ac17952007-07-21 14:21:34 +02002864 .mbar.commit add command -label [mc "Unstage From Commit"] \
Vitaly _Vi Shukelab677c662009-12-31 15:32:53 +02002865 -command do_unstage_selection \
2866 -accelerator $M1T-U
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002867 lappend disable_on_lock \
2868 [list .mbar.commit entryconf [.mbar.commit index last] -state]
Shawn O. Pearcee7348172006-11-23 21:40:45 -05002869
Christian Stimming1ac17952007-07-21 14:21:34 +02002870 .mbar.commit add command -label [mc "Revert Changes"] \
Vitaly _Vi Shukelab677c662009-12-31 15:32:53 +02002871 -command do_revert_selection \
2872 -accelerator $M1T-J
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002873 lappend disable_on_lock \
2874 [list .mbar.commit entryconf [.mbar.commit index last] -state]
Shawn O. Pearcee7348172006-11-23 21:40:45 -05002875
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002876 .mbar.commit add separator
Shawn O. Pearce1461c5f2006-11-19 00:29:55 -05002877
Jonathan del Strotherc91ee2b2008-04-01 11:54:03 +01002878 .mbar.commit add command -label [mc "Show Less Context"] \
2879 -command show_less_context \
Michele Ballabio729ffa52008-04-04 23:04:42 +02002880 -accelerator $M1T-\-
Jonathan del Strotherc91ee2b2008-04-01 11:54:03 +01002881
2882 .mbar.commit add command -label [mc "Show More Context"] \
2883 -command show_more_context \
Michele Ballabio729ffa52008-04-04 23:04:42 +02002884 -accelerator $M1T-=
Jonathan del Strotherc91ee2b2008-04-01 11:54:03 +01002885
2886 .mbar.commit add separator
2887
Shawn O. Pearceed70e4d2008-09-26 07:44:40 -07002888 if {![is_enabled nocommitmsg]} {
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07002889 .mbar.commit add command -label [mc "Sign Off"] \
2890 -command do_signoff \
2891 -accelerator $M1T-S
2892 }
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05002893
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04002894 .mbar.commit add command -label [commit_btn_caption] \
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002895 -command do_commit \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002896 -accelerator $M1T-Return
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05002897 lappend disable_on_lock \
2898 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2899}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05002900
Shawn O. Pearce9b28a8b2007-02-26 11:17:11 -05002901# -- Merge Menu
2902#
2903if {[is_enabled branch]} {
2904 menu .mbar.merge
Christian Stimming1ac17952007-07-21 14:21:34 +02002905 .mbar.merge add command -label [mc "Local Merge..."] \
Shawn O. Pearcea870ddc2007-07-19 00:39:23 -04002906 -command merge::dialog \
2907 -accelerator $M1T-M
Shawn O. Pearce9b28a8b2007-02-26 11:17:11 -05002908 lappend disable_on_lock \
2909 [list .mbar.merge entryconf [.mbar.merge index last] -state]
Christian Stimming1ac17952007-07-21 14:21:34 +02002910 .mbar.merge add command -label [mc "Abort Merge..."] \
Shawn O. Pearcea6c9b082007-05-02 13:56:27 -04002911 -command merge::reset_hard
Shawn O. Pearce9b28a8b2007-02-26 11:17:11 -05002912 lappend disable_on_lock \
2913 [list .mbar.merge entryconf [.mbar.merge index last] -state]
Shawn O. Pearce9b28a8b2007-02-26 11:17:11 -05002914}
2915
2916# -- Transport Menu
2917#
2918if {[is_enabled transport]} {
Shawn O. Pearce6bdf5e52007-10-07 22:23:54 -07002919 menu .mbar.remote
Shawn O. Pearce9b28a8b2007-02-26 11:17:11 -05002920
Shawn O. Pearce6bdf5e52007-10-07 22:23:54 -07002921 .mbar.remote add command \
Petr Baudisba6485e2008-09-24 22:44:01 +02002922 -label [mc "Add..."] \
2923 -command remote_add::dialog \
2924 -accelerator $M1T-A
2925 .mbar.remote add command \
Shawn O. Pearce6bdf5e52007-10-07 22:23:54 -07002926 -label [mc "Push..."] \
Shawn O. Pearce840bcfa2007-07-05 22:15:00 -04002927 -command do_push_anywhere \
2928 -accelerator $M1T-P
Shawn O. Pearce6bdf5e52007-10-07 22:23:54 -07002929 .mbar.remote add command \
Petr Baudis3c1c2a02008-09-24 22:43:59 +02002930 -label [mc "Delete Branch..."] \
Shawn O. Pearceaa252f12007-05-28 15:23:32 -04002931 -command remote_branch_delete::dialog
Shawn O. Pearce9b28a8b2007-02-26 11:17:11 -05002932}
2933
Shawn O. Pearce0c8d7832006-11-21 02:33:56 -05002934if {[is_MacOSX]} {
Daniel A. Steffena91be3f2008-08-16 03:20:09 +02002935 proc ::tk::mac::ShowPreferences {} {do_options}
Shawn O. Pearce0c8d7832006-11-21 02:33:56 -05002936} else {
2937 # -- Edit Menu
2938 #
2939 .mbar.edit add separator
Christian Stimming1ac17952007-07-21 14:21:34 +02002940 .mbar.edit add command -label [mc "Options..."] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002941 -command do_options
Shawn O. Pearce273984f2007-01-28 20:00:36 -05002942}
Shawn O. Pearce557afe82006-12-07 22:07:38 -05002943
Alexander Gavrilov0ce76de2008-11-16 21:46:49 +03002944# -- Tools Menu
2945#
2946if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2947 set tools_menubar .mbar.tools
2948 menu $tools_menubar
2949 $tools_menubar add separator
2950 $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog
2951 $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog
2952 set tools_tailcnt 3
2953 if {[array names repo_config guitool.*.cmd] ne {}} {
2954 tools_populate_all
2955 }
2956}
2957
Shawn O. Pearce273984f2007-01-28 20:00:36 -05002958# -- Help Menu
2959#
Christian Stimming1ac17952007-07-21 14:21:34 +02002960.mbar add cascade -label [mc Help] -menu .mbar.help
Shawn O. Pearce273984f2007-01-28 20:00:36 -05002961menu .mbar.help
Shawn O. Pearce0c8d7832006-11-21 02:33:56 -05002962
Daniel A. Steffena91be3f2008-08-16 03:20:09 +02002963if {[is_MacOSX]} {
2964 .mbar.apple add command -label [mc "About %s" [appname]] \
2965 -command do_about
2966 .mbar.apple add separator
2967} else {
Christian Stimming1ac17952007-07-21 14:21:34 +02002968 .mbar.help add command -label [mc "About %s" [appname]] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04002969 -command do_about
Shawn O. Pearce0c8d7832006-11-21 02:33:56 -05002970}
Daniel A. Steffena91be3f2008-08-16 03:20:09 +02002971. configure -menu .mbar
Petr Baudis2db21e72008-09-24 23:57:16 +02002972
Markus Heidelberg3eb56822009-04-05 03:48:21 +02002973set doc_path [githtmldir]
2974if {$doc_path ne {}} {
2975 set doc_path [file join $doc_path index.html]
Shawn O. Pearce273984f2007-01-28 20:00:36 -05002976
Markus Heidelberg3eb56822009-04-05 03:48:21 +02002977 if {[is_Cygwin]} {
2978 set doc_path [exec cygpath --mixed $doc_path]
2979 }
Shawn O. Pearce273984f2007-01-28 20:00:36 -05002980}
2981
Shawn O. Pearce273984f2007-01-28 20:00:36 -05002982if {[file isfile $doc_path]} {
2983 set doc_url "file:$doc_path"
2984} else {
2985 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2986}
2987
Petr Baudis2db21e72008-09-24 23:57:16 +02002988proc start_browser {url} {
2989 git "web--browse" $url
Shawn O. Pearce273984f2007-01-28 20:00:36 -05002990}
Petr Baudis2db21e72008-09-24 23:57:16 +02002991
2992.mbar.help add command -label [mc "Online Documentation"] \
2993 -command [list start_browser $doc_url]
Alexander Gavrilov98a68462008-10-15 13:28:20 +04002994
2995.mbar.help add command -label [mc "Show SSH Key"] \
2996 -command do_ssh_key
2997
Petr Baudis2db21e72008-09-24 23:57:16 +02002998unset doc_path doc_url
Shawn O. Pearce82aa2352006-11-20 23:55:51 -05002999
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05003000# -- Standard bindings
3001#
Shawn O. Pearce39fa2a92007-06-11 23:52:43 -04003002wm protocol . WM_DELETE_WINDOW do_quit
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05003003bind all <$M1B-Key-q> do_quit
3004bind all <$M1B-Key-Q> do_quit
3005bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
3006bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
3007
Shawn O. Pearce3e45ee12007-05-08 22:36:01 -04003008set subcommand_args {}
3009proc usage {} {
Pat Thoytsea475032010-08-08 00:07:01 +01003010 set s "usage: $::argv0 $::subcommand $::subcommand_args"
3011 if {[tk windowingsystem] eq "win32"} {
3012 wm withdraw .
Pat Thoyts7ae1e722010-10-05 23:39:54 +01003013 tk_messageBox -icon info -message $s \
3014 -title [mc "Usage"]
Pat Thoytsea475032010-08-08 00:07:01 +01003015 } else {
3016 puts stderr $s
3017 }
Shawn O. Pearce3e45ee12007-05-08 22:36:01 -04003018 exit 1
3019}
3020
Alexander Gavrilov95e706b2008-12-06 20:21:54 +03003021proc normalize_relpath {path} {
3022 set elements {}
3023 foreach item [file split $path] {
3024 if {$item eq {.}} continue
3025 if {$item eq {..} && [llength $elements] > 0
3026 && [lindex $elements end] ne {..}} {
3027 set elements [lrange $elements 0 end-1]
3028 continue
3029 }
3030 lappend elements $item
3031 }
3032 return [eval file join $elements]
3033}
3034
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05003035# -- Not a normal commit type invocation? Do that instead!
3036#
Shawn O. Pearce258871d2007-02-08 19:41:32 -05003037switch -- $subcommand {
Shawn O. Pearce85d2d592007-07-18 00:53:14 -04003038browser -
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05003039blame {
Alexander Gavrilovf7078b42008-08-23 12:32:20 +04003040 if {$subcommand eq "blame"} {
3041 set subcommand_args {[--line=<num>] rev? path}
3042 } else {
3043 set subcommand_args {rev? path}
3044 }
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04003045 if {$argv eq {}} usage
Shawn O. Pearcea0db0d62007-05-08 22:48:47 -04003046 set head {}
Shawn O. Pearce3e45ee12007-05-08 22:36:01 -04003047 set path {}
Alexander Gavrilovf7078b42008-08-23 12:32:20 +04003048 set jump_spec {}
Shawn O. Pearce3e45ee12007-05-08 22:36:01 -04003049 set is_path 0
3050 foreach a $argv {
John Keeping2f38dd02013-04-27 14:24:16 +01003051 set p [file join $_prefix $a]
Andrew Wonge3d06ca2012-10-02 12:25:14 -04003052
John Keeping2f38dd02013-04-27 14:24:16 +01003053 if {$is_path || [file exists $p]} {
Andrew Wonge3d06ca2012-10-02 12:25:14 -04003054 if {$path ne {}} usage
John Keeping2f38dd02013-04-27 14:24:16 +01003055 set path [normalize_relpath $p]
Andrew Wonge3d06ca2012-10-02 12:25:14 -04003056 break
Shawn O. Pearce3e45ee12007-05-08 22:36:01 -04003057 } elseif {$a eq {--}} {
3058 if {$path ne {}} {
Shawn O. Pearcea0db0d62007-05-08 22:48:47 -04003059 if {$head ne {}} usage
3060 set head $path
Shawn O. Pearce3e45ee12007-05-08 22:36:01 -04003061 set path {}
3062 }
3063 set is_path 1
Alexander Gavrilovf7078b42008-08-23 12:32:20 +04003064 } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
3065 if {$jump_spec ne {} || $head ne {}} usage
3066 set jump_spec [list $lnum]
Shawn O. Pearcea0db0d62007-05-08 22:48:47 -04003067 } elseif {$head eq {}} {
3068 if {$head ne {}} usage
3069 set head $a
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04003070 set is_path 1
Shawn O. Pearce3e45ee12007-05-08 22:36:01 -04003071 } else {
3072 usage
3073 }
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05003074 }
Shawn O. Pearce3e45ee12007-05-08 22:36:01 -04003075 unset is_path
3076
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04003077 if {$head ne {} && $path eq {}} {
Andrew Wongdf46eda2012-10-02 12:25:15 -04003078 if {[string index $head 0] eq {/}} {
3079 set path [normalize_relpath $head]
3080 set head {}
3081 } else {
3082 set path [normalize_relpath $_prefix$head]
3083 set head {}
3084 }
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04003085 }
3086
Shawn O. Pearcea0db0d62007-05-08 22:48:47 -04003087 if {$head eq {}} {
Shawn O. Pearced41b43e2007-07-08 18:40:56 -04003088 load_current_branch
Shawn O. Pearcea0db0d62007-05-08 22:48:47 -04003089 } else {
Shawn O. Pearce02087ab2007-07-08 21:19:59 -04003090 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
3091 if {[catch {
3092 set head [git rev-parse --verify $head]
3093 } err]} {
Pat Thoyts7ae1e722010-10-05 23:39:54 +01003094 if {[tk windowingsystem] eq "win32"} {
3095 tk_messageBox -icon error -title [mc Error] -message $err
3096 } else {
3097 puts stderr $err
3098 }
Shawn O. Pearce02087ab2007-07-08 21:19:59 -04003099 exit 1
3100 }
3101 }
Shawn O. Pearcea0db0d62007-05-08 22:48:47 -04003102 set current_branch $head
Shawn O. Pearce3e45ee12007-05-08 22:36:01 -04003103 }
Shawn O. Pearcea0db0d62007-05-08 22:48:47 -04003104
Pat Thoyts2810a582010-08-02 13:42:45 +01003105 wm deiconify .
Shawn O. Pearce85d2d592007-07-18 00:53:14 -04003106 switch -- $subcommand {
3107 browser {
Alexander Gavrilovf7078b42008-08-23 12:32:20 +04003108 if {$jump_spec ne {}} usage
Shawn O. Pearce85d2d592007-07-18 00:53:14 -04003109 if {$head eq {}} {
3110 if {$path ne {} && [file isdirectory $path]} {
3111 set head $current_branch
3112 } else {
3113 set head $path
3114 set path {}
3115 }
3116 }
3117 browser::new $head $path
Shawn O. Pearcec52c9452007-07-17 23:58:56 -04003118 }
Shawn O. Pearce85d2d592007-07-18 00:53:14 -04003119 blame {
3120 if {$head eq {} && ![file exists $path]} {
Pat Thoyts78077772010-08-08 00:07:43 +01003121 catch {wm withdraw .}
3122 tk_messageBox \
3123 -icon error \
3124 -type ok \
3125 -title [mc "git-gui: fatal error"] \
3126 -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
Shawn O. Pearce85d2d592007-07-18 00:53:14 -04003127 exit 1
3128 }
Alexander Gavrilovf7078b42008-08-23 12:32:20 +04003129 blame::new $head $path $jump_spec
Shawn O. Pearce85d2d592007-07-18 00:53:14 -04003130 }
3131 }
Shawn O. Pearce258871d2007-02-08 19:41:32 -05003132 return
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05003133}
Shawn O. Pearce258871d2007-02-08 19:41:32 -05003134citool -
3135gui {
3136 if {[llength $argv] != 0} {
Pat Thoyts7ae1e722010-10-05 23:39:54 +01003137 usage
Shawn O. Pearce258871d2007-02-08 19:41:32 -05003138 }
3139 # fall through to setup UI for commits
3140}
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05003141default {
Pat Thoyts7ae1e722010-10-05 23:39:54 +01003142 set err "usage: $argv0 \[{blame|browser|citool}\]"
3143 if {[tk windowingsystem] eq "win32"} {
3144 wm withdraw .
3145 tk_messageBox -icon error -message $err \
3146 -title [mc "Usage"]
3147 } else {
3148 puts stderr $err
3149 }
Shawn O. Pearce2ebba522007-02-08 19:10:52 -05003150 exit 1
3151}
3152}
3153
Shawn O. Pearce8553b772006-11-24 15:38:18 -05003154# -- Branch Control
3155#
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003156${NS}::frame .branch
3157if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
3158${NS}::label .branch.l1 \
Christian Stimming1ac17952007-07-21 14:21:34 +02003159 -text [mc "Current Branch:"] \
Shawn O. Pearce8553b772006-11-24 15:38:18 -05003160 -anchor w \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04003161 -justify left
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003162${NS}::label .branch.cb \
Shawn O. Pearce8553b772006-11-24 15:38:18 -05003163 -textvariable current_branch \
3164 -anchor w \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04003165 -justify left
Shawn O. Pearce8553b772006-11-24 15:38:18 -05003166pack .branch.l1 -side left
3167pack .branch.cb -side left -fill x
3168pack .branch -side top -fill x
3169
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003170# -- Main Window Layout
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05003171#
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003172${NS}::panedwindow .vpane -orient horizontal
3173${NS}::panedwindow .vpane.files -orient vertical
3174if {$use_ttk} {
3175 .vpane add .vpane.files
3176} else {
3177 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3178}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003179pack .vpane -anchor n -side top -fill both -expand 1
3180
3181# -- Index File List
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05003182#
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003183${NS}::frame .vpane.files.index -height 100 -width 200
3184tlabel .vpane.files.index.title \
3185 -text [mc "Staged Changes (Will Commit)"] \
Philipp A. Hartmannc382fdd2008-03-05 17:54:22 +01003186 -background lightgreen -foreground black
3187text $ui_index -background white -foreground black \
3188 -borderwidth 0 \
Shawn O. Pearcec5a1eb82007-01-21 17:50:42 -05003189 -width 20 -height 10 \
Shawn O. Pearce3c236972007-01-21 14:58:01 -05003190 -wrap none \
Shawn O. Pearce6c6dd012006-11-11 20:33:30 -05003191 -cursor $cursor_ptr \
Shawn O. Pearce3c236972007-01-21 14:58:01 -05003192 -xscrollcommand {.vpane.files.index.sx set} \
3193 -yscrollcommand {.vpane.files.index.sy set} \
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003194 -state disabled
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003195${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3196${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003197pack .vpane.files.index.title -side top -fill x
Shawn O. Pearce3c236972007-01-21 14:58:01 -05003198pack .vpane.files.index.sx -side bottom -fill x
3199pack .vpane.files.index.sy -side right -fill y
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003200pack $ui_index -side left -fill both -expand 1
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003201
Shawn O. Pearce08126652007-01-20 22:06:51 -05003202# -- Working Directory File List
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05003203#
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003204${NS}::frame .vpane.files.workdir -height 100 -width 200
3205tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
Philipp A. Hartmannc382fdd2008-03-05 17:54:22 +01003206 -background lightsalmon -foreground black
3207text $ui_workdir -background white -foreground black \
3208 -borderwidth 0 \
Shawn O. Pearcec5a1eb82007-01-21 17:50:42 -05003209 -width 20 -height 10 \
Shawn O. Pearce3c236972007-01-21 14:58:01 -05003210 -wrap none \
Shawn O. Pearce6c6dd012006-11-11 20:33:30 -05003211 -cursor $cursor_ptr \
Shawn O. Pearce3c236972007-01-21 14:58:01 -05003212 -xscrollcommand {.vpane.files.workdir.sx set} \
3213 -yscrollcommand {.vpane.files.workdir.sy set} \
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003214 -state disabled
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003215${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3216${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
Shawn O. Pearce08126652007-01-20 22:06:51 -05003217pack .vpane.files.workdir.title -side top -fill x
Shawn O. Pearce3c236972007-01-21 14:58:01 -05003218pack .vpane.files.workdir.sx -side bottom -fill x
3219pack .vpane.files.workdir.sy -side right -fill y
Shawn O. Pearce08126652007-01-20 22:06:51 -05003220pack $ui_workdir -side left -fill both -expand 1
Johannes Sixta0592d32007-10-10 20:50:40 -04003221
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003222.vpane.files add .vpane.files.workdir
3223.vpane.files add .vpane.files.index
3224if {!$use_ttk} {
3225 .vpane.files paneconfigure .vpane.files.workdir -sticky news
3226 .vpane.files paneconfigure .vpane.files.index -sticky news
3227}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003228
Shawn O. Pearce08126652007-01-20 22:06:51 -05003229foreach i [list $ui_index $ui_workdir] {
Shawn O. Pearce3849bfb2007-09-16 23:12:19 -04003230 rmsel_tag $i
3231 $i tag conf in_diff -background [$i tag cget in_sel -background]
Shawn O. Pearce24263b72006-11-13 16:06:38 -05003232}
3233unset i
Shawn O. Pearce131f5032006-11-06 16:07:32 -05003234
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003235# -- Diff and Commit Area
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05003236#
Max Kirillov02f6cfb2014-01-15 01:58:09 +02003237if {$have_tk85} {
3238 ${NS}::panedwindow .vpane.lower -orient vertical
3239 ${NS}::frame .vpane.lower.commarea
3240 ${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1 -height 500
3241 .vpane.lower add .vpane.lower.diff
3242 .vpane.lower add .vpane.lower.commarea
3243 .vpane add .vpane.lower
3244 if {$use_ttk} {
3245 .vpane.lower pane .vpane.lower.diff -weight 1
3246 .vpane.lower pane .vpane.lower.commarea -weight 0
3247 } else {
3248 .vpane.lower paneconfigure .vpane.lower.diff -stretch always
3249 .vpane.lower paneconfigure .vpane.lower.commarea -stretch never
3250 }
Max Kirillov918dbf52013-08-21 06:38:40 +03003251} else {
Max Kirillov02f6cfb2014-01-15 01:58:09 +02003252 frame .vpane.lower -height 300 -width 400
3253 frame .vpane.lower.commarea
3254 frame .vpane.lower.diff -relief sunken -borderwidth 1
3255 pack .vpane.lower.diff -fill both -expand 1
3256 pack .vpane.lower.commarea -side bottom -fill x
3257 .vpane add .vpane.lower
3258 .vpane paneconfigure .vpane.lower -sticky nsew
Max Kirillov918dbf52013-08-21 06:38:40 +03003259}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003260
3261# -- Commit Area Buttons
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05003262#
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003263${NS}::frame .vpane.lower.commarea.buttons
3264${NS}::label .vpane.lower.commarea.buttons.l -text {} \
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003265 -anchor w \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04003266 -justify left
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003267pack .vpane.lower.commarea.buttons.l -side top -fill x
3268pack .vpane.lower.commarea.buttons -side left -fill y
Shawn O. Pearce131f5032006-11-06 16:07:32 -05003269
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003270${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04003271 -command ui_do_rescan
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003272pack .vpane.lower.commarea.buttons.rescan -side top -fill x
Shawn O. Pearce390adae2006-11-11 19:40:33 -05003273lappend disable_on_lock \
3274 {.vpane.lower.commarea.buttons.rescan conf -state}
Shawn O. Pearce131f5032006-11-06 16:07:32 -05003275
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003276${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04003277 -command do_add_all
Shawn O. Pearce7fe7e732006-11-08 22:48:34 -05003278pack .vpane.lower.commarea.buttons.incall -side top -fill x
Shawn O. Pearce390adae2006-11-11 19:40:33 -05003279lappend disable_on_lock \
3280 {.vpane.lower.commarea.buttons.incall conf -state}
Shawn O. Pearce131f5032006-11-06 16:07:32 -05003281
Shawn O. Pearceed70e4d2008-09-26 07:44:40 -07003282if {![is_enabled nocommitmsg]} {
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003283 ${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07003284 -command do_signoff
3285 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3286}
Shawn O. Pearce131f5032006-11-06 16:07:32 -05003287
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003288${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04003289 -command do_commit
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003290pack .vpane.lower.commarea.buttons.commit -side top -fill x
Shawn O. Pearce390adae2006-11-11 19:40:33 -05003291lappend disable_on_lock \
3292 {.vpane.lower.commarea.buttons.commit conf -state}
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003293
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07003294if {![is_enabled nocommit]} {
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003295 ${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07003296 -command do_push_anywhere
3297 pack .vpane.lower.commarea.buttons.push -side top -fill x
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04003298}
3299
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003300# -- Commit Message Buffer
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05003301#
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003302${NS}::frame .vpane.lower.commarea.buffer
3303${NS}::frame .vpane.lower.commarea.buffer.header
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003304set ui_comm .vpane.lower.commarea.buffer.t
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05003305set ui_coml .vpane.lower.commarea.buffer.header.l
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07003306
3307if {![is_enabled nocommit]} {
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003308 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07003309 -text [mc "New Commit"] \
3310 -command do_select_commit_type \
3311 -variable selected_commit_type \
3312 -value new
3313 lappend disable_on_lock \
3314 [list .vpane.lower.commarea.buffer.header.new conf -state]
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003315 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07003316 -text [mc "Amend Last Commit"] \
3317 -command do_select_commit_type \
3318 -variable selected_commit_type \
3319 -value amend
3320 lappend disable_on_lock \
3321 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3322}
3323
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003324${NS}::label $ui_coml \
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003325 -anchor w \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04003326 -justify left
Shawn O. Pearce4539eac2006-11-18 02:50:58 -05003327proc trace_commit_type {varname args} {
3328 global ui_coml commit_type
3329 switch -glob -- $commit_type {
Christian Stimming1ac17952007-07-21 14:21:34 +02003330 initial {set txt [mc "Initial Commit Message:"]}
3331 amend {set txt [mc "Amended Commit Message:"]}
3332 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
3333 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
3334 merge {set txt [mc "Merge Commit Message:"]}
3335 * {set txt [mc "Commit Message:"]}
Shawn O. Pearce4539eac2006-11-18 02:50:58 -05003336 }
3337 $ui_coml conf -text $txt
3338}
3339trace add variable commit_type write trace_commit_type
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05003340pack $ui_coml -side left -fill x
Shawn O. Pearce1e02b322008-09-24 09:48:20 -07003341
3342if {![is_enabled nocommit]} {
3343 pack .vpane.lower.commarea.buffer.header.amend -side right
3344 pack .vpane.lower.commarea.buffer.header.new -side right
3345}
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05003346
Philipp A. Hartmannc382fdd2008-03-05 17:54:22 +01003347text $ui_comm -background white -foreground black \
3348 -borderwidth 1 \
Shawn O. Pearce98616712006-11-11 15:51:41 -05003349 -undo true \
Shawn O. Pearceb2c6fcf2006-11-11 16:16:25 -05003350 -maxundo 20 \
Shawn O. Pearce98616712006-11-11 15:51:41 -05003351 -autoseparators true \
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003352 -relief sunken \
Adam PiÄ…tyszek11027d52008-03-06 20:38:40 +01003353 -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
Shawn O. Pearceb4946932006-11-12 00:40:38 -05003354 -font font_diff \
Shawn O. Pearce6c6dd012006-11-11 20:33:30 -05003355 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003356${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
Shawn O. Pearce390adae2006-11-11 19:40:33 -05003357 -command [list $ui_comm yview]
Shawn O. Pearce24ac9b72006-11-18 20:59:49 -05003358pack .vpane.lower.commarea.buffer.header -side top -fill x
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003359pack .vpane.lower.commarea.buffer.sby -side right -fill y
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003360pack $ui_comm -side left -fill y
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003361pack .vpane.lower.commarea.buffer -side left -fill y
3362
Shawn O. Pearce0e794312006-11-11 20:24:23 -05003363# -- Commit Message Buffer Context Menu
3364#
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003365set ctxm .vpane.lower.commarea.buffer.ctxm
3366menu $ctxm -tearoff 0
3367$ctxm add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02003368 -label [mc Cut] \
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003369 -command {tk_textCut $ui_comm}
3370$ctxm add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02003371 -label [mc Copy] \
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003372 -command {tk_textCopy $ui_comm}
3373$ctxm add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02003374 -label [mc Paste] \
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003375 -command {tk_textPaste $ui_comm}
3376$ctxm add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02003377 -label [mc Delete] \
Markus Heidelbergbf516ec2009-03-29 15:29:23 +01003378 -command {catch {$ui_comm delete sel.first sel.last}}
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003379$ctxm add separator
3380$ctxm add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02003381 -label [mc "Select All"] \
Shawn O. Pearce75e78c82007-01-22 18:31:12 -05003382 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003383$ctxm add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02003384 -label [mc "Copy All"] \
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003385 -command {
Shawn O. Pearce0e794312006-11-11 20:24:23 -05003386 $ui_comm tag add sel 0.0 end
3387 tk_textCopy $ui_comm
3388 $ui_comm tag remove sel 0.0 end
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003389 }
3390$ctxm add separator
3391$ctxm add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02003392 -label [mc "Sign Off"] \
Shawn O. Pearce0e794312006-11-11 20:24:23 -05003393 -command do_signoff
Shawn O. Pearce95b002e2008-02-07 02:35:25 -05003394set ui_comm_ctxm $ctxm
Shawn O. Pearce0e794312006-11-11 20:24:23 -05003395
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003396# -- Diff Header
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05003397#
Shawn O. Pearce20a53c02007-01-21 11:37:58 -05003398proc trace_current_diff_path {varname args} {
3399 global current_diff_path diff_actions file_states
3400 if {$current_diff_path eq {}} {
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003401 set s {}
3402 set f {}
3403 set p {}
3404 set o disabled
3405 } else {
Shawn O. Pearce20a53c02007-01-21 11:37:58 -05003406 set p $current_diff_path
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003407 set s [mapdesc [lindex $file_states($p) 0] $p]
Christian Stimming1ac17952007-07-21 14:21:34 +02003408 set f [mc "File:"]
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003409 set p [escape_path $p]
3410 set o normal
3411 }
3412
3413 .vpane.lower.diff.header.status configure -text $s
3414 .vpane.lower.diff.header.file configure -text $f
3415 .vpane.lower.diff.header.path configure -text $p
3416 foreach w $diff_actions {
3417 uplevel #0 $w $o
3418 }
3419}
Shawn O. Pearce20a53c02007-01-21 11:37:58 -05003420trace add variable current_diff_path write trace_current_diff_path
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003421
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003422gold_frame .vpane.lower.diff.header
3423tlabel .vpane.lower.diff.header.status \
Matthijs Melchior9adccb02007-06-05 23:50:02 +02003424 -background gold \
Philipp A. Hartmannc382fdd2008-03-05 17:54:22 +01003425 -foreground black \
Shawn O. Pearce3e7b0e12006-11-12 22:06:37 -05003426 -width $max_status_desc \
3427 -anchor w \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04003428 -justify left
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003429tlabel .vpane.lower.diff.header.file \
Matthijs Melchior9adccb02007-06-05 23:50:02 +02003430 -background gold \
Philipp A. Hartmannc382fdd2008-03-05 17:54:22 +01003431 -foreground black \
Shawn O. Pearcefce89e42006-11-13 00:48:44 -05003432 -anchor w \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04003433 -justify left
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003434tlabel .vpane.lower.diff.header.path \
Matthijs Melchior9adccb02007-06-05 23:50:02 +02003435 -background gold \
Philipp A. Hartmannc382fdd2008-03-05 17:54:22 +01003436 -foreground black \
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003437 -anchor w \
Shawn O. Pearce7416bbc2007-04-28 23:14:08 -04003438 -justify left
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003439pack .vpane.lower.diff.header.status -side left
3440pack .vpane.lower.diff.header.file -side left
3441pack .vpane.lower.diff.header.path -fill x
3442set ctxm .vpane.lower.diff.header.ctxm
3443menu $ctxm -tearoff 0
3444$ctxm add command \
Christian Stimming1ac17952007-07-21 14:21:34 +02003445 -label [mc Copy] \
Shawn O. Pearcefce89e42006-11-13 00:48:44 -05003446 -command {
3447 clipboard clear
3448 clipboard append \
3449 -format STRING \
3450 -type STRING \
Shawn O. Pearce20a53c02007-01-21 11:37:58 -05003451 -- $current_diff_path
Shawn O. Pearcefce89e42006-11-13 00:48:44 -05003452 }
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003453lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3454bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003455
3456# -- Diff Body
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05003457#
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003458${NS}::frame .vpane.lower.diff.body
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003459set ui_diff .vpane.lower.diff.body.t
Philipp A. Hartmannc382fdd2008-03-05 17:54:22 +01003460text $ui_diff -background white -foreground black \
3461 -borderwidth 0 \
Vietor Liuacb91082009-10-16 17:41:26 +08003462 -width 80 -height 5 -wrap none \
Shawn O. Pearceb4946932006-11-12 00:40:38 -05003463 -font font_diff \
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003464 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3465 -yscrollcommand {.vpane.lower.diff.body.sby set} \
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003466 -state disabled
Pat Thoytsc7440862010-10-27 23:37:31 +01003467catch {$ui_diff configure -tabstyle wordprocessor}
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003468${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003469 -command [list $ui_diff xview]
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003470${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
Shawn O. Pearce0fb8f9c2006-11-07 20:27:46 -05003471 -command [list $ui_diff yview]
3472pack .vpane.lower.diff.body.sbx -side bottom -fill x
3473pack .vpane.lower.diff.body.sby -side right -fill y
3474pack $ui_diff -side left -fill both -expand 1
3475pack .vpane.lower.diff.header -side top -fill x
3476pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3477
Pat Thoyts8f855992010-10-22 16:14:38 +01003478foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3479 $ui_diff tag configure clr4$n -background $c
3480 $ui_diff tag configure clri4$n -foreground $c
3481 $ui_diff tag configure clr3$n -foreground $c
3482 $ui_diff tag configure clri3$n -background $c
3483}
3484$ui_diff tag configure clr1 -font font_diffbold
Pat Thoyts9af64132010-11-19 10:00:49 +00003485$ui_diff tag configure clr4 -underline 1
Pat Thoyts8f855992010-10-22 16:14:38 +01003486
Bert Wesarg88b21c22010-12-06 22:01:01 +00003487$ui_diff tag conf d_info -foreground blue -font font_diffbold
3488
Shawn O. Pearce30b14ed2007-01-24 21:30:23 -05003489$ui_diff tag conf d_cr -elide true
Pat Thoyts8f855992010-10-22 16:14:38 +01003490$ui_diff tag conf d_@ -font font_diffbold
Shawn O. Pearceca521562007-01-21 14:49:45 -05003491$ui_diff tag conf d_+ -foreground {#00a000}
Shawn O. Pearcefec4a782007-01-21 13:12:02 -05003492$ui_diff tag conf d_- -foreground red
3493
Shawn O. Pearceca521562007-01-21 14:49:45 -05003494$ui_diff tag conf d_++ -foreground {#00a000}
Shawn O. Pearcefec4a782007-01-21 13:12:02 -05003495$ui_diff tag conf d_-- -foreground red
3496$ui_diff tag conf d_+s \
Shawn O. Pearceca521562007-01-21 14:49:45 -05003497 -foreground {#00a000} \
3498 -background {#e2effa}
Shawn O. Pearcefec4a782007-01-21 13:12:02 -05003499$ui_diff tag conf d_-s \
3500 -foreground red \
Shawn O. Pearceca521562007-01-21 14:49:45 -05003501 -background {#e2effa}
Shawn O. Pearcefec4a782007-01-21 13:12:02 -05003502$ui_diff tag conf d_s+ \
Shawn O. Pearceca521562007-01-21 14:49:45 -05003503 -foreground {#00a000} \
3504 -background ivory1
Shawn O. Pearcefec4a782007-01-21 13:12:02 -05003505$ui_diff tag conf d_s- \
3506 -foreground red \
Shawn O. Pearceca521562007-01-21 14:49:45 -05003507 -background ivory1
Shawn O. Pearcefec4a782007-01-21 13:12:02 -05003508
Bert Wesarg45903072010-11-16 10:21:52 +01003509$ui_diff tag conf d< \
Shawn O. Pearcefec4a782007-01-21 13:12:02 -05003510 -foreground orange \
3511 -font font_diffbold
Bert Wesarg45903072010-11-16 10:21:52 +01003512$ui_diff tag conf d= \
Shawn O. Pearcefec4a782007-01-21 13:12:02 -05003513 -foreground orange \
3514 -font font_diffbold
Bert Wesarg45903072010-11-16 10:21:52 +01003515$ui_diff tag conf d> \
Shawn O. Pearcefec4a782007-01-21 13:12:02 -05003516 -foreground orange \
3517 -font font_diffbold
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003518
Shawn O. Pearceca521562007-01-21 14:49:45 -05003519$ui_diff tag raise sel
3520
Shawn O. Pearce0e794312006-11-11 20:24:23 -05003521# -- Diff Body Context Menu
3522#
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003523
3524proc create_common_diff_popup {ctxm} {
3525 $ctxm add command \
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003526 -label [mc Refresh] \
3527 -command reshow_diff
3528 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3529 $ctxm add command \
3530 -label [mc Copy] \
3531 -command {tk_textCopy $ui_diff}
3532 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3533 $ctxm add command \
3534 -label [mc "Select All"] \
3535 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
3536 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3537 $ctxm add command \
3538 -label [mc "Copy All"] \
3539 -command {
3540 $ui_diff tag add sel 0.0 end
3541 tk_textCopy $ui_diff
3542 $ui_diff tag remove sel 0.0 end
3543 }
3544 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3545 $ctxm add separator
3546 $ctxm add command \
3547 -label [mc "Decrease Font Size"] \
3548 -command {incr_font_size font_diff -1}
3549 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3550 $ctxm add command \
3551 -label [mc "Increase Font Size"] \
3552 -command {incr_font_size font_diff 1}
3553 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3554 $ctxm add separator
Alexander Gavrilov3fe01622008-09-18 01:07:34 +04003555 set emenu $ctxm.enc
3556 menu $emenu
3557 build_encoding_menu $emenu [list force_diff_encoding]
3558 $ctxm add cascade \
3559 -label [mc "Encoding"] \
3560 -menu $emenu
3561 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3562 $ctxm add separator
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003563 $ctxm add command -label [mc "Options..."] \
3564 -command do_options
3565}
3566
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003567set ctxm .vpane.lower.diff.body.ctxm
3568menu $ctxm -tearoff 0
3569$ctxm add command \
Johannes Sixtfba60722007-12-13 15:39:21 +01003570 -label [mc "Apply/Reverse Hunk"] \
3571 -command {apply_hunk $cursorX $cursorY}
3572set ui_diff_applyhunk [$ctxm index last]
3573lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
Johannes Sixt58219882008-06-27 09:22:01 +02003574$ctxm add command \
3575 -label [mc "Apply/Reverse Line"] \
Jeff Eplerff07c3b2009-12-07 18:22:43 -06003576 -command {apply_range_or_line $cursorX $cursorY; do_rescan}
Johannes Sixt58219882008-06-27 09:22:01 +02003577set ui_diff_applyline [$ctxm index last]
3578lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
Johannes Sixtfba60722007-12-13 15:39:21 +01003579$ctxm add separator
Jens Lehmann25476c62010-01-02 17:58:49 +01003580$ctxm add command \
3581 -label [mc "Show Less Context"] \
3582 -command show_less_context
3583lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3584$ctxm add command \
3585 -label [mc "Show More Context"] \
3586 -command show_more_context
3587lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3588$ctxm add separator
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003589create_common_diff_popup $ctxm
3590
3591set ctxmmg .vpane.lower.diff.body.ctxmmg
3592menu $ctxmmg -tearoff 0
3593$ctxmmg add command \
Alexander Gavrilov7e306822008-08-31 00:56:51 +04003594 -label [mc "Run Merge Tool"] \
3595 -command {merge_resolve_tool}
3596lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3597$ctxmmg add separator
3598$ctxmmg add command \
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003599 -label [mc "Use Remote Version"] \
3600 -command {merge_resolve_one 3}
3601lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3602$ctxmmg add command \
3603 -label [mc "Use Local Version"] \
3604 -command {merge_resolve_one 2}
3605lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3606$ctxmmg add command \
3607 -label [mc "Revert To Base"] \
3608 -command {merge_resolve_one 1}
3609lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3610$ctxmmg add separator
Jens Lehmann25476c62010-01-02 17:58:49 +01003611$ctxmmg add command \
3612 -label [mc "Show Less Context"] \
3613 -command show_less_context
3614lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3615$ctxmmg add command \
3616 -label [mc "Show More Context"] \
3617 -command show_more_context
3618lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3619$ctxmmg add separator
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003620create_common_diff_popup $ctxmmg
3621
Jens Lehmann25476c62010-01-02 17:58:49 +01003622set ctxmsm .vpane.lower.diff.body.ctxmsm
3623menu $ctxmsm -tearoff 0
3624$ctxmsm add command \
3625 -label [mc "Visualize These Changes In The Submodule"] \
3626 -command {do_gitk -- true}
3627lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3628$ctxmsm add command \
3629 -label [mc "Visualize Current Branch History In The Submodule"] \
3630 -command {do_gitk {} true}
3631lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3632$ctxmsm add command \
3633 -label [mc "Visualize All Branch History In The Submodule"] \
3634 -command {do_gitk --all true}
3635lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3636$ctxmsm add separator
3637$ctxmsm add command \
3638 -label [mc "Start git gui In The Submodule"] \
3639 -command {do_git_gui}
3640lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3641$ctxmsm add separator
3642create_common_diff_popup $ctxmsm
3643
Clément Poulain1fbacca2010-07-30 09:11:02 +01003644proc has_textconv {path} {
3645 if {[is_config_false gui.textconv]} {
3646 return 0
3647 }
3648 set filter [gitattr $path diff set]
3649 set textconv [get_config [join [list diff $filter textconv] .]]
3650 if {$filter ne {set} && $textconv ne {}} {
3651 return 1
3652 } else {
3653 return 0
3654 }
3655}
3656
Jens Lehmann25476c62010-01-02 17:58:49 +01003657proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
Shawn O. Pearcece015c22007-08-21 02:22:53 -04003658 global current_diff_path file_states
Shawn O. Pearce83751fc2007-07-23 00:36:39 -04003659 set ::cursorX $x
3660 set ::cursorY $y
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003661 if {[info exists file_states($current_diff_path)]} {
3662 set state [lindex $file_states($current_diff_path) 0]
Shawn O. Pearcea25c5182007-01-24 21:20:57 -05003663 } else {
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003664 set state {__}
Shawn O. Pearcea25c5182007-01-24 21:20:57 -05003665 }
Alexander Gavrilovff515d82008-08-31 01:00:49 +04003666 if {[string first {U} $state] >= 0} {
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003667 tk_popup $ctxmmg $X $Y
Jens Lehmann25476c62010-01-02 17:58:49 +01003668 } elseif {$::is_submodule_diff} {
3669 tk_popup $ctxmsm $X $Y
Shawn O. Pearce047d94d2007-09-02 15:38:04 -04003670 } else {
Jeff Eplerff07c3b2009-12-07 18:22:43 -06003671 set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003672 if {$::ui_index eq $::current_diff_side} {
3673 set l [mc "Unstage Hunk From Commit"]
Jeff Eplerff07c3b2009-12-07 18:22:43 -06003674 if {$has_range} {
3675 set t [mc "Unstage Lines From Commit"]
3676 } else {
3677 set t [mc "Unstage Line From Commit"]
3678 }
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003679 } else {
3680 set l [mc "Stage Hunk For Commit"]
Jeff Eplerff07c3b2009-12-07 18:22:43 -06003681 if {$has_range} {
3682 set t [mc "Stage Lines For Commit"]
3683 } else {
3684 set t [mc "Stage Line For Commit"]
3685 }
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003686 }
Jens Lehmann25476c62010-01-02 17:58:49 +01003687 if {$::is_3way_diff
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003688 || $current_diff_path eq {}
3689 || {__} eq $state
3690 || {_O} eq $state
Bert Wesarg7587f4d2010-12-09 21:46:23 +01003691 || [string match {?T} $state]
3692 || [string match {T?} $state]
Clément Poulain1fbacca2010-07-30 09:11:02 +01003693 || [has_textconv $current_diff_path]} {
Alexander Gavrilov042c2322008-08-31 00:55:45 +04003694 set s disabled
3695 } else {
3696 set s normal
3697 }
3698 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
3699 $ctxm entryconf $::ui_diff_applyline -state $s -label $t
3700 tk_popup $ctxm $X $Y
Shawn O. Pearce9c9f5fa2007-08-23 02:44:13 -04003701 }
Shawn O. Pearce83751fc2007-07-23 00:36:39 -04003702}
Jens Lehmann25476c62010-01-02 17:58:49 +01003703bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
Shawn O. Pearce0e794312006-11-11 20:24:23 -05003704
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003705# -- Status Bar
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003706#
Shawn O. Pearce51530d12007-07-08 22:06:33 -04003707set main_status [::status_bar::new .status]
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003708pack .status -anchor w -side bottom -fill x
Christian Stimming1ac17952007-07-21 14:21:34 +02003709$main_status show [mc "Initializing..."]
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003710
Shawn O. Pearce2d195162006-11-08 23:42:51 -05003711# -- Load geometry
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003712#
Pat Thoyts2810a582010-08-02 13:42:45 +01003713proc on_ttk_pane_mapped {w pane pos} {
3714 bind $w <Map> {}
3715 after 0 [list after idle [list $w sashpos $pane $pos]]
Pat Thoytsc80d7be2010-01-26 00:05:31 +00003716}
Pat Thoyts2810a582010-08-02 13:42:45 +01003717proc on_tk_pane_mapped {w pane x y} {
3718 bind $w <Map> {}
3719 after 0 [list after idle [list $w sash place $pane $x $y]]
3720}
3721proc on_application_mapped {} {
3722 global repo_config use_ttk
3723 bind . <Map> {}
3724 set gm $repo_config(gui.geometry)
3725 if {$use_ttk} {
3726 bind .vpane <Map> \
3727 [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
3728 bind .vpane.files <Map> \
3729 [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
3730 } else {
3731 bind .vpane <Map> \
3732 [list on_tk_pane_mapped %W 0 \
3733 [lindex $gm 1] \
3734 [lindex [.vpane sash coord 0] 1]]
3735 bind .vpane.files <Map> \
3736 [list on_tk_pane_mapped %W 0 \
3737 [lindex [.vpane.files sash coord 0] 0] \
3738 [lindex $gm 2]]
3739 }
3740 wm geometry . [lindex $gm 0]
3741}
3742if {[info exists repo_config(gui.geometry)]} {
3743 bind . <Map> [list on_application_mapped]
3744 wm geometry . [lindex $repo_config(gui.geometry) 0]
Shawn O. Pearce390adae2006-11-11 19:40:33 -05003745}
Shawn O. Pearce2d195162006-11-08 23:42:51 -05003746
Alexey Borzenkoved7b6032009-09-08 22:39:33 +04003747# -- Load window state
3748#
Pat Thoyts2810a582010-08-02 13:42:45 +01003749if {[info exists repo_config(gui.wmstate)]} {
3750 catch {wm state . $repo_config(gui.wmstate)}
Alexey Borzenkoved7b6032009-09-08 22:39:33 +04003751}
3752
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003753# -- Key Bindings
Shawn O. Pearcee8ab6442006-11-15 18:55:05 -05003754#
Shawn O. Pearceec6b4242006-11-06 20:50:59 -05003755bind $ui_comm <$M1B-Key-Return> {do_commit;break}
Shawn O. Pearcecd16a6c2007-11-08 02:22:21 -05003756bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
3757bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
Vitaly _Vi Shukelab677c662009-12-31 15:32:53 +02003758bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
3759bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
3760bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
3761bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
Shawn O. Pearce93e912c2007-01-20 23:07:04 -05003762bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3763bind $ui_comm <$M1B-Key-I> {do_add_all;break}
Shawn O. Pearce98616712006-11-11 15:51:41 -05003764bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3765bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3766bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3767bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3768bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3769bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3770bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3771bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
Michele Ballabio729ffa52008-04-04 23:04:42 +02003772bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
3773bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
3774bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
3775bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
3776bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
Shawn O. Pearce98616712006-11-11 15:51:41 -05003777
3778bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3779bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3780bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3781bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3782bind $ui_diff <$M1B-Key-v> {break}
3783bind $ui_diff <$M1B-Key-V> {break}
3784bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3785bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
Vitaly _Vi Shukela44e88ce2012-09-15 02:36:41 +03003786bind $ui_diff <$M1B-Key-j> {do_revert_selection;break}
3787bind $ui_diff <$M1B-Key-J> {do_revert_selection;break}
Shawn O. Pearceb2c6fcf2006-11-11 16:16:25 -05003788bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3789bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3790bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3791bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
Shawn O. Pearce60aa0652007-05-01 15:51:09 -04003792bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
3793bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
3794bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
3795bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
3796bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
3797bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
Shawn O. Pearce23effa72007-01-25 12:57:57 -05003798bind $ui_diff <Button-1> {focus %W}
Shawn O. Pearce49b86f02006-11-11 15:16:01 -05003799
Shawn O. Pearce64a906f2007-02-08 18:10:05 -05003800if {[is_enabled branch]} {
Shawn O. Pearceb1fa2bf2007-07-03 22:57:18 -04003801 bind . <$M1B-Key-n> branch_create::dialog
3802 bind . <$M1B-Key-N> branch_create::dialog
Shawn O. Pearced41b43e2007-07-08 18:40:56 -04003803 bind . <$M1B-Key-o> branch_checkout::dialog
3804 bind . <$M1B-Key-O> branch_checkout::dialog
Shawn O. Pearcea870ddc2007-07-19 00:39:23 -04003805 bind . <$M1B-Key-m> merge::dialog
3806 bind . <$M1B-Key-M> merge::dialog
Shawn O. Pearcebd29ebc2007-01-21 01:34:55 -05003807}
Shawn O. Pearce840bcfa2007-07-05 22:15:00 -04003808if {[is_enabled transport]} {
3809 bind . <$M1B-Key-p> do_push_anywhere
3810 bind . <$M1B-Key-P> do_push_anywhere
3811}
Shawn O. Pearcebd29ebc2007-01-21 01:34:55 -05003812
Alexander Gavrilov8056cc42008-08-31 01:04:10 +04003813bind . <Key-F5> ui_do_rescan
3814bind . <$M1B-Key-r> ui_do_rescan
3815bind . <$M1B-Key-R> ui_do_rescan
Shawn O. Pearce07123f42006-11-07 02:57:46 -05003816bind . <$M1B-Key-s> do_signoff
3817bind . <$M1B-Key-S> do_signoff
Shawn O. Pearcecd16a6c2007-11-08 02:22:21 -05003818bind . <$M1B-Key-t> do_add_selection
3819bind . <$M1B-Key-T> do_add_selection
Vitaly _Vi Shukela44e88ce2012-09-15 02:36:41 +03003820bind . <$M1B-Key-u> do_unstage_selection
3821bind . <$M1B-Key-U> do_unstage_selection
Heiko Voigtd6db1bb2010-01-29 16:57:48 +01003822bind . <$M1B-Key-j> do_revert_selection
3823bind . <$M1B-Key-J> do_revert_selection
Shawn O. Pearce93e912c2007-01-20 23:07:04 -05003824bind . <$M1B-Key-i> do_add_all
3825bind . <$M1B-Key-I> do_add_all
Michele Ballabio729ffa52008-04-04 23:04:42 +02003826bind . <$M1B-Key-minus> {show_less_context;break}
3827bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
3828bind . <$M1B-Key-equal> {show_more_context;break}
3829bind . <$M1B-Key-plus> {show_more_context;break}
3830bind . <$M1B-Key-KP_Add> {show_more_context;break}
Shawn O. Pearce07123f42006-11-07 02:57:46 -05003831bind . <$M1B-Key-Return> do_commit
Shawn O. Pearce08126652007-01-20 22:06:51 -05003832foreach i [list $ui_index $ui_workdir] {
Shawn O. Pearce24263b72006-11-13 16:06:38 -05003833 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3834 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3835 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003836}
Shawn O. Pearce62aac802006-11-11 20:00:35 -05003837unset i
3838
3839set file_lists($ui_index) [list]
Shawn O. Pearce08126652007-01-20 22:06:51 -05003840set file_lists($ui_workdir) [list]
Shawn O. Pearcea49c67d2006-11-18 03:27:23 -05003841
Giuseppe Bilotta21985a12010-01-23 11:03:34 +01003842wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
Shawn O. Pearcecb07fc22006-11-06 14:20:27 -05003843focus -force $ui_comm
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003844
Shawn O. Pearce85ab3132006-11-25 03:38:39 -05003845# -- Warn the user about environmental problems. Cygwin's Tcl
3846# does *not* pass its env array onto any processes it spawns.
3847# This means that git processes get none of our environment.
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003848#
Shawn O. Pearce20ddfca2007-01-28 20:58:47 -05003849if {[is_Cygwin]} {
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003850 set ignored_env 0
3851 set suggest_user {}
Michele Ballabioc8c48542007-09-13 15:19:05 +02003852 set msg [mc "Possible environment issues exist.
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003853
3854The following environment variables are probably
3855going to be ignored by any Git subprocess run
Michele Ballabioc8c48542007-09-13 15:19:05 +02003856by %s:
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003857
Michele Ballabioc8c48542007-09-13 15:19:05 +02003858" [appname]]
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003859 foreach name [array names env] {
3860 switch -regexp -- $name {
3861 {^GIT_INDEX_FILE$} -
3862 {^GIT_OBJECT_DIRECTORY$} -
3863 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3864 {^GIT_DIFF_OPTS$} -
3865 {^GIT_EXTERNAL_DIFF$} -
3866 {^GIT_PAGER$} -
3867 {^GIT_TRACE$} -
3868 {^GIT_CONFIG$} -
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003869 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3870 append msg " - $name\n"
3871 incr ignored_env
3872 }
3873 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3874 append msg " - $name\n"
3875 incr ignored_env
3876 set suggest_user $name
3877 }
3878 }
3879 }
3880 if {$ignored_env > 0} {
Michele Ballabioc8c48542007-09-13 15:19:05 +02003881 append msg [mc "
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003882This is due to a known issue with the
Michele Ballabioc8c48542007-09-13 15:19:05 +02003883Tcl binary distributed by Cygwin."]
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003884
3885 if {$suggest_user ne {}} {
Michele Ballabioc8c48542007-09-13 15:19:05 +02003886 append msg [mc "
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003887
Michele Ballabioc8c48542007-09-13 15:19:05 +02003888A good replacement for %s
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003889is placing values for the user.name and
3890user.email settings into your personal
3891~/.gitconfig file.
Michele Ballabioc8c48542007-09-13 15:19:05 +02003892" $suggest_user]
Shawn O. Pearce1d8b3cb2006-11-21 15:28:14 -05003893 }
3894 warn_popup $msg
3895 }
3896 unset ignored_env msg suggest_user name
3897}
3898
Shawn O. Pearce85ab3132006-11-25 03:38:39 -05003899# -- Only initialize complex UI if we are going to stay running.
3900#
Shawn O. Pearce64a906f2007-02-08 18:10:05 -05003901if {[is_enabled transport]} {
Shawn O. Pearce4ccdab02006-11-12 16:20:36 -05003902 load_all_remotes
Shawn O. Pearce85ab3132006-11-25 03:38:39 -05003903
Shawn O. Pearce6bdf5e52007-10-07 22:23:54 -07003904 set n [.mbar.remote index end]
Petr Baudis8329bd02008-09-24 22:44:00 +02003905 populate_remotes_menu
Shawn O. Pearce6bdf5e52007-10-07 22:23:54 -07003906 set n [expr {[.mbar.remote index end] - $n}]
3907 if {$n > 0} {
Alexander Gavrilov7e09b152008-07-27 10:34:21 +04003908 if {[.mbar.remote type 0] eq "tearoff"} { incr n }
Shawn O. Pearce6bdf5e52007-10-07 22:23:54 -07003909 .mbar.remote insert $n separator
3910 }
3911 unset n
Shawn O. Pearce4ccdab02006-11-12 16:20:36 -05003912}
Shawn O. Pearce85ab3132006-11-25 03:38:39 -05003913
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -04003914if {[winfo exists $ui_comm]} {
Pat Thoytsfda1ba02012-04-19 11:19:58 +01003915 set GITGUI_BCK_exists [load_message GITGUI_BCK utf-8]
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -04003916
3917 # -- If both our backup and message files exist use the
3918 # newer of the two files to initialize the buffer.
3919 #
3920 if {$GITGUI_BCK_exists} {
3921 set m [gitdir GITGUI_MSG]
3922 if {[file isfile $m]} {
3923 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
3924 catch {file delete [gitdir GITGUI_MSG]}
3925 } else {
3926 $ui_comm delete 0.0 end
3927 $ui_comm edit reset
3928 $ui_comm edit modified false
3929 catch {file delete [gitdir GITGUI_BCK]}
3930 set GITGUI_BCK_exists 0
3931 }
3932 }
3933 unset m
3934 }
3935
3936 proc backup_commit_buffer {} {
3937 global ui_comm GITGUI_BCK_exists
3938
3939 set m [$ui_comm edit modified]
3940 if {$m || $GITGUI_BCK_exists} {
3941 set msg [string trim [$ui_comm get 0.0 end]]
3942 regsub -all -line {[ \r\t]+$} $msg {} msg
3943
3944 if {$msg eq {}} {
3945 if {$GITGUI_BCK_exists} {
3946 catch {file delete [gitdir GITGUI_BCK]}
3947 set GITGUI_BCK_exists 0
3948 }
3949 } elseif {$m} {
3950 catch {
3951 set fd [open [gitdir GITGUI_BCK] w]
Pat Thoytsfda1ba02012-04-19 11:19:58 +01003952 fconfigure $fd -encoding utf-8
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -04003953 puts -nonewline $fd $msg
3954 close $fd
3955 set GITGUI_BCK_exists 1
3956 }
3957 }
3958
3959 $ui_comm edit modified false
3960 }
3961
3962 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
3963 }
3964
3965 backup_commit_buffer
Shawn O. Pearce95b002e2008-02-07 02:35:25 -05003966
3967 # -- If the user has aspell available we can drive it
3968 # in pipe mode to spellcheck the commit message.
3969 #
3970 set spell_cmd [list |]
3971 set spell_dict [get_config gui.spellingdictionary]
3972 lappend spell_cmd aspell
3973 if {$spell_dict ne {}} {
3974 lappend spell_cmd --master=$spell_dict
3975 }
3976 lappend spell_cmd --mode=none
3977 lappend spell_cmd --encoding=utf-8
3978 lappend spell_cmd pipe
3979 if {$spell_dict eq {none}
3980 || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} {
3981 bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y]
3982 } else {
3983 set ui_comm_spell [spellcheck::init \
3984 $spell_fd \
3985 $ui_comm \
3986 $ui_comm_ctxm \
3987 ]
3988 }
3989 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -04003990}
3991
Shawn O. Pearce53716a72006-11-18 03:31:25 -05003992lock_index begin-read
Shawn O. Pearce301dfaa2007-07-17 23:09:31 -04003993if {![winfo ismapped .]} {
3994 wm deiconify .
3995}
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04003996after 1 {
3997 if {[is_enabled initialamend]} {
3998 force_amend
3999 } else {
4000 do_rescan
4001 }
4002
4003 if {[is_enabled nocommitmsg]} {
4004 $ui_comm configure -state disabled -background gray
4005 }
4006}
Pat Thoytsaf867682011-11-29 09:27:17 +00004007if {[is_enabled multicommit] && ![is_config_false gui.gcwarning]} {
Shawn O. Pearce3972b982007-07-17 23:20:56 -04004008 after 1000 hint_gc
4009}
Alexander Gavrilov1e65c622008-09-12 22:43:49 +04004010if {[is_enabled retcode]} {
4011 bind . <Destroy> {+terminate_me %W}
4012}
Petr Baudisbb4812b2008-09-25 00:07:02 +02004013if {$picked && [is_config_true gui.autoexplore]} {
4014 do_explore
4015}
Pat Thoytsc80d7be2010-01-26 00:05:31 +00004016
4017# Local variables:
4018# mode: tcl
4019# indent-tabs-mode: t
4020# tab-width: 4
4021# End: