]>
Commit | Line | Data |
---|---|---|
bd11b82d | 1 | #!/bin/sh |
cb07fc2a | 2 | # Tcl ignores the next line -*- tcl -*- \ |
4e817d1a SP |
3 | if test "z$*" = zversion \ |
4 | || test "z$*" = z--version; \ | |
5 | then \ | |
6 | echo 'git-gui version @@GITGUI_VERSION@@'; \ | |
7 | exit; \ | |
8 | fi; \ | |
2f7c9a7f SP |
9 | argv0=$0; \ |
10 | exec wish "$argv0" -- "$@" | |
cb07fc2a | 11 | |
7e81d4ee | 12 | set appvers {@@GITGUI_VERSION@@} |
d6db1ad5 | 13 | set copyright [encoding convertfrom utf-8 { |
a9813cb5 | 14 | Copyright © 2006, 2007 Shawn Pearce, et. al. |
bdc9ea20 | 15 | |
0499b24a SP |
16 | This program is free software; you can redistribute it and/or modify |
17 | it under the terms of the GNU General Public License as published by | |
18 | the Free Software Foundation; either version 2 of the License, or | |
19 | (at your option) any later version. | |
20 | ||
21 | This program is distributed in the hope that it will be useful, | |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
25 | ||
26 | You should have received a copy of the GNU General Public License | |
27 | along with this program; if not, write to the Free Software | |
d6db1ad5 | 28 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}] |
cb07fc2a | 29 | |
f522c9b5 | 30 | ###################################################################### |
cfb07cca SP |
31 | ## |
32 | ## Tcl/Tk sanity check | |
33 | ||
34 | if {[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 \ | |
c8c4854b | 41 | -title [mc "git-gui: fatal error"] \ |
cfb07cca SP |
42 | -message $err |
43 | exit 1 | |
44 | } | |
45 | ||
63c4024f | 46 | catch {rename send {}} ; # What an evil concept... |
cff93397 | 47 | |
fc703c20 SP |
48 | ###################################################################### |
49 | ## | |
50 | ## locate our library | |
51 | ||
52 | set oguilib {@@GITGUI_LIBDIR@@} | |
53 | set oguirel {@@GITGUI_RELATIVE@@} | |
54 | if {$oguirel eq {1}} { | |
9534c9fb JS |
55 | set oguilib [file dirname [file normalize $argv0]] |
56 | if {[file tail $oguilib] eq {git-core}} { | |
57 | set oguilib [file dirname $oguilib] | |
58 | } | |
59 | set oguilib [file dirname $oguilib] | |
fc703c20 | 60 | set oguilib [file join $oguilib share git-gui lib] |
d4b0ccd9 | 61 | set oguimsg [file join $oguilib msgs] |
fc703c20 SP |
62 | } elseif {[string match @@* $oguirel]} { |
63 | set oguilib [file join [file dirname [file normalize $argv0]] lib] | |
d4b0ccd9 SP |
64 | set oguimsg [file join [file dirname [file normalize $argv0]] po] |
65 | } else { | |
66 | set oguimsg [file join $oguilib msgs] | |
fc703c20 SP |
67 | } |
68 | unset oguirel | |
69 | ||
cd12901b SP |
70 | ###################################################################### |
71 | ## | |
72 | ## enable verbose loading? | |
73 | ||
74 | if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} { | |
75 | unset _verbose | |
76 | rename auto_load real__auto_load | |
77 | proc auto_load {name args} { | |
78 | puts stderr "auto_load $name" | |
79 | return [uplevel 1 real__auto_load $name $args] | |
80 | } | |
81 | rename source real__source | |
82 | proc source {name} { | |
83 | puts stderr "source $name" | |
84 | uplevel 1 real__source $name | |
85 | } | |
86 | } | |
87 | ||
c950c66e | 88 | ###################################################################### |
d4b0ccd9 SP |
89 | ## |
90 | ## Internationalization (i18n) through msgcat and gettext. See | |
91 | ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html | |
92 | ||
93 | package require msgcat | |
146d73a3 | 94 | |
ab0d33c4 | 95 | proc _mc_trim {fmt} { |
146d73a3 SP |
96 | set cmk [string first @@ $fmt] |
97 | if {$cmk > 0} { | |
ab0d33c4 | 98 | return [string range $fmt 0 [expr {$cmk - 1}]] |
146d73a3 | 99 | } |
ab0d33c4 SP |
100 | return $fmt |
101 | } | |
102 | ||
103 | proc mc {en_fmt args} { | |
104 | set fmt [_mc_trim [::msgcat::mc $en_fmt]] | |
105 | if {[catch {set msg [eval [list format $fmt] $args]} err]} { | |
106 | set msg [eval [list format [_mc_trim $en_fmt]] $args] | |
107 | } | |
108 | return $msg | |
146d73a3 SP |
109 | } |
110 | ||
31bb1d1b SP |
111 | proc strcat {args} { |
112 | return [join $args {}] | |
113 | } | |
114 | ||
d4b0ccd9 SP |
115 | ::msgcat::mcload $oguimsg |
116 | unset oguimsg | |
117 | ||
118 | ###################################################################### | |
c950c66e SP |
119 | ## |
120 | ## read only globals | |
121 | ||
0b2bc460 | 122 | set _appname {Git Gui} |
c950c66e | 123 | set _gitdir {} |
20ddfcaa | 124 | set _gitexec {} |
c950c66e | 125 | set _reponame {} |
20ddfcaa | 126 | set _iscygwin {} |
0b812616 | 127 | set _search_path {} |
c950c66e | 128 | |
16dd62ac SP |
129 | set _trace [lsearch -exact $argv --trace] |
130 | if {$_trace >= 0} { | |
131 | set argv [lreplace $argv $_trace $_trace] | |
132 | set _trace 1 | |
133 | } else { | |
134 | set _trace 0 | |
135 | } | |
136 | ||
c950c66e SP |
137 | proc appname {} { |
138 | global _appname | |
139 | return $_appname | |
140 | } | |
141 | ||
c2758a17 | 142 | proc gitdir {args} { |
c950c66e | 143 | global _gitdir |
c2758a17 SP |
144 | if {$args eq {}} { |
145 | return $_gitdir | |
146 | } | |
0b812616 | 147 | return [eval [list file join $_gitdir] $args] |
c950c66e SP |
148 | } |
149 | ||
20ddfcaa SP |
150 | proc gitexec {args} { |
151 | global _gitexec | |
152 | if {$_gitexec eq {}} { | |
81347223 | 153 | if {[catch {set _gitexec [git --exec-path]} err]} { |
20ddfcaa SP |
154 | error "Git not installed?\n\n$err" |
155 | } | |
0b812616 SP |
156 | if {[is_Cygwin]} { |
157 | set _gitexec [exec cygpath \ | |
158 | --windows \ | |
159 | --absolute \ | |
160 | $_gitexec] | |
161 | } else { | |
162 | set _gitexec [file normalize $_gitexec] | |
163 | } | |
20ddfcaa SP |
164 | } |
165 | if {$args eq {}} { | |
166 | return $_gitexec | |
167 | } | |
0b812616 | 168 | return [eval [list file join $_gitexec] $args] |
20ddfcaa SP |
169 | } |
170 | ||
c950c66e | 171 | proc reponame {} { |
d36cd968 | 172 | return $::_reponame |
c950c66e | 173 | } |
da5239dc | 174 | |
20ddfcaa | 175 | proc is_MacOSX {} { |
20ddfcaa SP |
176 | if {[tk windowingsystem] eq {aqua}} { |
177 | return 1 | |
178 | } | |
179 | return 0 | |
180 | } | |
181 | ||
182 | proc is_Windows {} { | |
d36cd968 | 183 | if {$::tcl_platform(platform) eq {windows}} { |
20ddfcaa SP |
184 | return 1 |
185 | } | |
186 | return 0 | |
187 | } | |
188 | ||
189 | proc is_Cygwin {} { | |
d36cd968 | 190 | global _iscygwin |
20ddfcaa | 191 | if {$_iscygwin eq {}} { |
d36cd968 | 192 | if {$::tcl_platform(platform) eq {windows}} { |
20ddfcaa SP |
193 | if {[catch {set p [exec cygpath --windir]} err]} { |
194 | set _iscygwin 0 | |
195 | } else { | |
196 | set _iscygwin 1 | |
197 | } | |
198 | } else { | |
199 | set _iscygwin 0 | |
200 | } | |
201 | } | |
202 | return $_iscygwin | |
203 | } | |
204 | ||
cf25ddc8 SP |
205 | proc is_enabled {option} { |
206 | global enabled_options | |
207 | if {[catch {set on $enabled_options($option)}]} {return 0} | |
208 | return $on | |
209 | } | |
210 | ||
211 | proc enable_option {option} { | |
212 | global enabled_options | |
213 | set enabled_options($option) 1 | |
214 | } | |
215 | ||
216 | proc disable_option {option} { | |
217 | global enabled_options | |
218 | set enabled_options($option) 0 | |
219 | } | |
220 | ||
2d19516d SP |
221 | ###################################################################### |
222 | ## | |
223 | ## config | |
224 | ||
51f4d16b SP |
225 | proc is_many_config {name} { |
226 | switch -glob -- $name { | |
24f7c64b | 227 | gui.recentrepo - |
51f4d16b SP |
228 | remote.*.fetch - |
229 | remote.*.push | |
230 | {return 1} | |
231 | * | |
232 | {return 0} | |
233 | } | |
234 | } | |
2d19516d | 235 | |
c539449b SP |
236 | proc is_config_true {name} { |
237 | global repo_config | |
238 | if {[catch {set v $repo_config($name)}]} { | |
239 | return 0 | |
240 | } elseif {$v eq {true} || $v eq {1} || $v eq {yes}} { | |
241 | return 1 | |
242 | } else { | |
243 | return 0 | |
244 | } | |
245 | } | |
246 | ||
61f82ce7 SP |
247 | proc get_config {name} { |
248 | global repo_config | |
249 | if {[catch {set v $repo_config($name)}]} { | |
250 | return {} | |
251 | } else { | |
252 | return $v | |
253 | } | |
254 | } | |
255 | ||
81347223 SP |
256 | ###################################################################### |
257 | ## | |
258 | ## handy utils | |
259 | ||
16dd62ac SP |
260 | proc _trace_exec {cmd} { |
261 | if {!$::_trace} return | |
262 | set d {} | |
263 | foreach v $cmd { | |
264 | if {$d ne {}} { | |
265 | append d { } | |
266 | } | |
267 | if {[regexp {[ \t\r\n'"$?*]} $v]} { | |
268 | set v [sq $v] | |
269 | } | |
270 | append d $v | |
271 | } | |
272 | puts stderr $d | |
273 | } | |
274 | ||
0b812616 SP |
275 | proc _git_cmd {name} { |
276 | global _git_cmd_path | |
277 | ||
278 | if {[catch {set v $_git_cmd_path($name)}]} { | |
279 | switch -- $name { | |
70a7595c | 280 | version - |
0b812616 SP |
281 | --version - |
282 | --exec-path { return [list $::_git $name] } | |
283 | } | |
284 | ||
285 | set p [gitexec git-$name$::_search_exe] | |
286 | if {[file exists $p]} { | |
287 | set v [list $p] | |
c136f2b8 SP |
288 | } elseif {[is_Windows] && [file exists [gitexec git-$name]]} { |
289 | # Try to determine what sort of magic will make | |
290 | # git-$name go and do its thing, because native | |
291 | # Tcl on Windows doesn't know it. | |
0b812616 | 292 | # |
c136f2b8 SP |
293 | set p [gitexec git-$name] |
294 | set f [open $p r] | |
295 | set s [gets $f] | |
296 | close $f | |
297 | ||
6e4ba05c | 298 | switch -glob -- [lindex $s 0] { |
c136f2b8 SP |
299 | #!*sh { set i sh } |
300 | #!*perl { set i perl } | |
301 | #!*python { set i python } | |
302 | default { error "git-$name is not supported: $s" } | |
303 | } | |
304 | ||
305 | upvar #0 _$i interp | |
306 | if {![info exists interp]} { | |
307 | set interp [_which $i] | |
308 | } | |
309 | if {$interp eq {}} { | |
310 | error "git-$name requires $i (not in PATH)" | |
311 | } | |
6e4ba05c | 312 | set v [concat [list $interp] [lrange $s 1 end] [list $p]] |
0b812616 | 313 | } else { |
c6729890 SP |
314 | # Assume it is builtin to git somehow and we |
315 | # aren't actually able to see a file for it. | |
316 | # | |
317 | set v [list $::_git $name] | |
0b812616 SP |
318 | } |
319 | set _git_cmd_path($name) $v | |
320 | } | |
321 | return $v | |
322 | } | |
323 | ||
79317e5d | 324 | proc _which {what args} { |
0b812616 SP |
325 | global env _search_exe _search_path |
326 | ||
327 | if {$_search_path eq {}} { | |
299077fb | 328 | if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} { |
0b812616 SP |
329 | set _search_path [split [exec cygpath \ |
330 | --windows \ | |
331 | --path \ | |
332 | --absolute \ | |
333 | $env(PATH)] {;}] | |
334 | set _search_exe .exe | |
335 | } elseif {[is_Windows]} { | |
be700fe3 SP |
336 | set gitguidir [file dirname [info script]] |
337 | regsub -all ";" $gitguidir "\\;" gitguidir | |
338 | set env(PATH) "$gitguidir;$env(PATH)" | |
0b812616 SP |
339 | set _search_path [split $env(PATH) {;}] |
340 | set _search_exe .exe | |
341 | } else { | |
342 | set _search_path [split $env(PATH) :] | |
343 | set _search_exe {} | |
344 | } | |
345 | } | |
346 | ||
79317e5d SP |
347 | if {[is_Windows] && [lsearch -exact $args -script] >= 0} { |
348 | set suffix {} | |
349 | } else { | |
350 | set suffix $_search_exe | |
351 | } | |
352 | ||
0b812616 | 353 | foreach p $_search_path { |
79317e5d | 354 | set p [file join $p $what$suffix] |
0b812616 SP |
355 | if {[file exists $p]} { |
356 | return [file normalize $p] | |
357 | } | |
358 | } | |
359 | return {} | |
360 | } | |
361 | ||
6f62b4f7 SP |
362 | proc _lappend_nice {cmd_var} { |
363 | global _nice | |
364 | upvar $cmd_var cmd | |
365 | ||
366 | if {![info exists _nice]} { | |
367 | set _nice [_which nice] | |
368 | } | |
369 | if {$_nice ne {}} { | |
370 | lappend cmd $_nice | |
371 | } | |
372 | } | |
373 | ||
81347223 | 374 | proc git {args} { |
16dd62ac | 375 | set opt [list] |
0b812616 SP |
376 | |
377 | while {1} { | |
378 | switch -- [lindex $args 0] { | |
379 | --nice { | |
6f62b4f7 | 380 | _lappend_nice opt |
0b812616 SP |
381 | } |
382 | ||
383 | default { | |
384 | break | |
385 | } | |
386 | ||
387 | } | |
388 | ||
389 | set args [lrange $args 1 end] | |
390 | } | |
391 | ||
392 | set cmdp [_git_cmd [lindex $args 0]] | |
393 | set args [lrange $args 1 end] | |
394 | ||
16dd62ac SP |
395 | _trace_exec [concat $opt $cmdp $args] |
396 | set result [eval exec $opt $cmdp $args] | |
397 | if {$::_trace} { | |
398 | puts stderr "< $result" | |
399 | } | |
400 | return $result | |
0b812616 SP |
401 | } |
402 | ||
74c4763c | 403 | proc _open_stdout_stderr {cmd} { |
16dd62ac | 404 | _trace_exec $cmd |
74c4763c | 405 | if {[catch { |
16dd62ac | 406 | set fd [open [concat [list | ] $cmd] r] |
74c4763c SP |
407 | } err]} { |
408 | if { [lindex $cmd end] eq {2>@1} | |
409 | && $err eq {can not find channel named "1"} | |
410 | } { | |
411 | # Older versions of Tcl 8.4 don't have this 2>@1 IO | |
412 | # redirect operator. Fallback to |& cat for those. | |
413 | # The command was not actually started, so its safe | |
414 | # to try to start it a second time. | |
415 | # | |
416 | set fd [open [concat \ | |
16dd62ac | 417 | [list | ] \ |
74c4763c SP |
418 | [lrange $cmd 0 end-1] \ |
419 | [list |& cat] \ | |
420 | ] r] | |
421 | } else { | |
422 | error $err | |
423 | } | |
424 | } | |
6eb420ef | 425 | fconfigure $fd -eofchar {} |
74c4763c SP |
426 | return $fd |
427 | } | |
428 | ||
0b812616 | 429 | proc git_read {args} { |
16dd62ac | 430 | set opt [list] |
0b812616 SP |
431 | |
432 | while {1} { | |
433 | switch -- [lindex $args 0] { | |
434 | --nice { | |
6f62b4f7 | 435 | _lappend_nice opt |
0b812616 SP |
436 | } |
437 | ||
438 | --stderr { | |
439 | lappend args 2>@1 | |
440 | } | |
441 | ||
442 | default { | |
443 | break | |
444 | } | |
445 | ||
446 | } | |
447 | ||
448 | set args [lrange $args 1 end] | |
449 | } | |
450 | ||
451 | set cmdp [_git_cmd [lindex $args 0]] | |
452 | set args [lrange $args 1 end] | |
453 | ||
74c4763c | 454 | return [_open_stdout_stderr [concat $opt $cmdp $args]] |
0b812616 SP |
455 | } |
456 | ||
457 | proc git_write {args} { | |
16dd62ac | 458 | set opt [list] |
0b812616 SP |
459 | |
460 | while {1} { | |
461 | switch -- [lindex $args 0] { | |
462 | --nice { | |
6f62b4f7 | 463 | _lappend_nice opt |
0b812616 SP |
464 | } |
465 | ||
466 | default { | |
467 | break | |
468 | } | |
469 | ||
470 | } | |
471 | ||
472 | set args [lrange $args 1 end] | |
473 | } | |
474 | ||
475 | set cmdp [_git_cmd [lindex $args 0]] | |
476 | set args [lrange $args 1 end] | |
477 | ||
16dd62ac SP |
478 | _trace_exec [concat $opt $cmdp $args] |
479 | return [open [concat [list | ] $opt $cmdp $args] w] | |
81347223 SP |
480 | } |
481 | ||
ed76cb70 SP |
482 | proc githook_read {hook_name args} { |
483 | set pchook [gitdir hooks $hook_name] | |
484 | lappend args 2>@1 | |
485 | ||
fbc0e7ac | 486 | # On Windows [file executable] might lie so we need to ask |
ed76cb70 SP |
487 | # the shell if the hook is executable. Yes that's annoying. |
488 | # | |
fbc0e7ac | 489 | if {[is_Windows]} { |
ed76cb70 SP |
490 | upvar #0 _sh interp |
491 | if {![info exists interp]} { | |
492 | set interp [_which sh] | |
493 | } | |
494 | if {$interp eq {}} { | |
495 | error "hook execution requires sh (not in PATH)" | |
496 | } | |
497 | ||
498 | set scr {if test -x "$1";then exec "$@";fi} | |
16dd62ac | 499 | set sh_c [list $interp -c $scr $interp $pchook] |
ed76cb70 SP |
500 | return [_open_stdout_stderr [concat $sh_c $args]] |
501 | } | |
502 | ||
503 | if {[file executable $pchook]} { | |
16dd62ac | 504 | return [_open_stdout_stderr [concat [list $pchook] $args]] |
ed76cb70 SP |
505 | } |
506 | ||
507 | return {} | |
508 | } | |
509 | ||
e6131d30 AG |
510 | proc kill_file_process {fd} { |
511 | set process [pid $fd] | |
512 | ||
513 | catch { | |
514 | if {[is_Windows]} { | |
515 | # Use a Cygwin-specific flag to allow killing | |
516 | # native Windows processes | |
517 | exec kill -f $process | |
518 | } else { | |
519 | exec kill $process | |
520 | } | |
521 | } | |
522 | } | |
523 | ||
1ffca60f SP |
524 | proc gitattr {path attr default} { |
525 | if {[catch {set r [git check-attr $attr -- $path]}]} { | |
526 | set r unspecified | |
527 | } else { | |
528 | set r [join [lrange [split $r :] 2 end] :] | |
529 | regsub {^ } $r {} r | |
530 | } | |
531 | if {$r eq {unspecified}} { | |
532 | return $default | |
533 | } | |
534 | return $r | |
535 | } | |
536 | ||
7eafa2f1 SP |
537 | proc sq {value} { |
538 | regsub -all ' $value "'\\''" value | |
539 | return "'$value'" | |
540 | } | |
541 | ||
d41b43eb SP |
542 | proc load_current_branch {} { |
543 | global current_branch is_detached | |
544 | ||
fc4e8da7 | 545 | set fd [open [gitdir HEAD] r] |
311e02a4 | 546 | if {[gets $fd ref] < 1} { |
fc4e8da7 SP |
547 | set ref {} |
548 | } | |
549 | close $fd | |
311e02a4 SP |
550 | |
551 | set pfx {ref: refs/heads/} | |
552 | set len [string length $pfx] | |
553 | if {[string equal -length $len $pfx $ref]} { | |
554 | # We're on a branch. It might not exist. But | |
555 | # HEAD looks good enough to be a branch. | |
556 | # | |
d41b43eb SP |
557 | set current_branch [string range $ref $len end] |
558 | set is_detached 0 | |
311e02a4 SP |
559 | } else { |
560 | # Assume this is a detached head. | |
561 | # | |
d41b43eb SP |
562 | set current_branch HEAD |
563 | set is_detached 1 | |
311e02a4 | 564 | } |
fc4e8da7 SP |
565 | } |
566 | ||
2739291b SP |
567 | auto_load tk_optionMenu |
568 | rename tk_optionMenu real__tkOptionMenu | |
569 | proc tk_optionMenu {w varName args} { | |
570 | set m [eval real__tkOptionMenu $w $varName $args] | |
571 | $m configure -font font_ui | |
572 | $w configure -font font_ui | |
573 | return $m | |
574 | } | |
575 | ||
3849bfba SP |
576 | proc rmsel_tag {text} { |
577 | $text tag conf sel \ | |
578 | -background [$text cget -background] \ | |
579 | -foreground [$text cget -foreground] \ | |
580 | -borderwidth 0 | |
581 | $text tag conf in_sel -background lightgray | |
582 | bind $text <Motion> break | |
583 | return $text | |
584 | } | |
585 | ||
a4bee597 SP |
586 | set root_exists 0 |
587 | bind . <Visibility> { | |
588 | bind . <Visibility> {} | |
589 | set root_exists 1 | |
590 | } | |
591 | ||
1bdd8a15 SP |
592 | if {[is_Windows]} { |
593 | wm iconbitmap . -default $oguilib/git-gui.ico | |
594 | } | |
595 | ||
a4bee597 SP |
596 | ###################################################################### |
597 | ## | |
598 | ## config defaults | |
599 | ||
600 | set cursor_ptr arrow | |
601 | font create font_diff -family Courier -size 10 | |
602 | font create font_ui | |
603 | catch { | |
604 | label .dummy | |
605 | eval font configure font_ui [font actual [.dummy cget -font]] | |
606 | destroy .dummy | |
607 | } | |
608 | ||
609 | font create font_uiitalic | |
610 | font create font_uibold | |
611 | font create font_diffbold | |
612 | font create font_diffitalic | |
613 | ||
614 | foreach class {Button Checkbutton Entry Label | |
615 | Labelframe Listbox Menu Message | |
616 | Radiobutton Spinbox Text} { | |
617 | option add *$class.font font_ui | |
618 | } | |
619 | unset class | |
620 | ||
621 | if {[is_Windows] || [is_MacOSX]} { | |
622 | option add *Menu.tearOff 0 | |
623 | } | |
624 | ||
625 | if {[is_MacOSX]} { | |
626 | set M1B M1 | |
627 | set M1T Cmd | |
628 | } else { | |
629 | set M1B Control | |
630 | set M1T Ctrl | |
631 | } | |
632 | ||
633 | proc bind_button3 {w cmd} { | |
634 | bind $w <Any-Button-3> $cmd | |
635 | if {[is_MacOSX]} { | |
636 | # Mac OS X sends Button-2 on right click through three-button mouse, | |
637 | # or through trackpad right-clicking (two-finger touch + click). | |
638 | bind $w <Any-Button-2> $cmd | |
639 | bind $w <Control-Button-1> $cmd | |
640 | } | |
641 | } | |
642 | ||
643 | proc apply_config {} { | |
644 | global repo_config font_descs | |
645 | ||
646 | foreach option $font_descs { | |
647 | set name [lindex $option 0] | |
648 | set font [lindex $option 1] | |
649 | if {[catch { | |
48b8d2b3 | 650 | set need_weight 1 |
a4bee597 | 651 | foreach {cn cv} $repo_config(gui.$name) { |
48b8d2b3 SP |
652 | if {$cn eq {-weight}} { |
653 | set need_weight 0 | |
654 | } | |
655 | font configure $font $cn $cv | |
656 | } | |
657 | if {$need_weight} { | |
658 | font configure $font -weight normal | |
a4bee597 SP |
659 | } |
660 | } err]} { | |
661 | error_popup [strcat [mc "Invalid font specified in %s:" "gui.$name"] "\n\n$err"] | |
662 | } | |
663 | foreach {cn cv} [font configure $font] { | |
664 | font configure ${font}bold $cn $cv | |
665 | font configure ${font}italic $cn $cv | |
666 | } | |
667 | font configure ${font}bold -weight bold | |
668 | font configure ${font}italic -slant italic | |
669 | } | |
670 | } | |
671 | ||
fe70225d | 672 | set default_config(branch.autosetupmerge) true |
7e30682c AG |
673 | set default_config(merge.tool) {} |
674 | set default_config(merge.keepbackup) true | |
a4bee597 SP |
675 | set default_config(merge.diffstat) true |
676 | set default_config(merge.summary) false | |
677 | set default_config(merge.verbosity) 2 | |
678 | set default_config(user.name) {} | |
679 | set default_config(user.email) {} | |
680 | ||
72e6b002 | 681 | set default_config(gui.encoding) [encoding system] |
a4bee597 SP |
682 | set default_config(gui.matchtrackingbranch) false |
683 | set default_config(gui.pruneduringfetch) false | |
684 | set default_config(gui.trustmtime) false | |
57cae87b AG |
685 | set default_config(gui.fastcopyblame) false |
686 | set default_config(gui.copyblamethreshold) 40 | |
a9c80b83 | 687 | set default_config(gui.blamehistoryctx) 7 |
a4bee597 | 688 | set default_config(gui.diffcontext) 5 |
11027d54 | 689 | set default_config(gui.commitmsgwidth) 75 |
a4bee597 | 690 | set default_config(gui.newbranchtemplate) {} |
95b002ee | 691 | set default_config(gui.spellingdictionary) {} |
a4bee597 SP |
692 | set default_config(gui.fontui) [font configure font_ui] |
693 | set default_config(gui.fontdiff) [font configure font_diff] | |
694 | set font_descs { | |
695 | {fontui font_ui {mc "Main Font"}} | |
696 | {fontdiff font_diff {mc "Diff/Console Font"}} | |
697 | } | |
698 | ||
0b812616 SP |
699 | ###################################################################### |
700 | ## | |
701 | ## find git | |
702 | ||
703 | set _git [_which git] | |
704 | if {$_git eq {}} { | |
705 | catch {wm withdraw .} | |
183a1d14 SP |
706 | tk_messageBox \ |
707 | -icon error \ | |
708 | -type ok \ | |
709 | -title [mc "git-gui: fatal error"] \ | |
710 | -message [mc "Cannot find git in PATH."] | |
0b812616 SP |
711 | exit 1 |
712 | } | |
0b812616 | 713 | |
54acdd95 SP |
714 | ###################################################################### |
715 | ## | |
716 | ## version check | |
717 | ||
d6967022 | 718 | if {[catch {set _git_version [git --version]} err]} { |
54acdd95 | 719 | catch {wm withdraw .} |
875b7c93 SP |
720 | tk_messageBox \ |
721 | -icon error \ | |
722 | -type ok \ | |
c8c4854b | 723 | -title [mc "git-gui: fatal error"] \ |
875b7c93 | 724 | -message "Cannot determine Git version: |
54acdd95 SP |
725 | |
726 | $err | |
727 | ||
d6967022 SP |
728 | [appname] requires Git 1.5.0 or later." |
729 | exit 1 | |
730 | } | |
731 | if {![regsub {^git version } $_git_version {} _git_version]} { | |
732 | catch {wm withdraw .} | |
875b7c93 SP |
733 | tk_messageBox \ |
734 | -icon error \ | |
735 | -type ok \ | |
c8c4854b | 736 | -title [mc "git-gui: fatal error"] \ |
31bb1d1b | 737 | -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"] |
54acdd95 SP |
738 | exit 1 |
739 | } | |
301dfaa9 SP |
740 | |
741 | set _real_git_version $_git_version | |
2c2a3782 | 742 | regsub -- {[\-\.]dirty$} $_git_version {} _git_version |
d6967022 SP |
743 | regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version |
744 | regsub {\.rc[0-9]+$} $_git_version {} _git_version | |
91464dfb | 745 | regsub {\.GIT$} $_git_version {} _git_version |
96f11953 | 746 | regsub {\.[a-zA-Z]+\.[0-9]+$} $_git_version {} _git_version |
d6967022 | 747 | |
301dfaa9 SP |
748 | if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} { |
749 | catch {wm withdraw .} | |
750 | if {[tk_messageBox \ | |
751 | -icon warning \ | |
752 | -type yesno \ | |
753 | -default no \ | |
754 | -title "[appname]: warning" \ | |
1ac17950 | 755 | -message [mc "Git version cannot be determined. |
301dfaa9 | 756 | |
1ac17950 | 757 | %s claims it is version '%s'. |
301dfaa9 | 758 | |
1ac17950 | 759 | %s requires at least Git 1.5.0 or later. |
301dfaa9 | 760 | |
1ac17950 CS |
761 | Assume '%s' is version 1.5.0? |
762 | " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} { | |
301dfaa9 SP |
763 | set _git_version 1.5.0 |
764 | } else { | |
765 | exit 1 | |
766 | } | |
767 | } | |
768 | unset _real_git_version | |
769 | ||
d6967022 SP |
770 | proc git-version {args} { |
771 | global _git_version | |
772 | ||
773 | switch [llength $args] { | |
774 | 0 { | |
775 | return $_git_version | |
54acdd95 | 776 | } |
d6967022 SP |
777 | |
778 | 2 { | |
779 | set op [lindex $args 0] | |
780 | set vr [lindex $args 1] | |
781 | set cm [package vcompare $_git_version $vr] | |
782 | return [expr $cm $op 0] | |
783 | } | |
784 | ||
785 | 4 { | |
786 | set type [lindex $args 0] | |
787 | set name [lindex $args 1] | |
788 | set parm [lindex $args 2] | |
789 | set body [lindex $args 3] | |
790 | ||
791 | if {($type ne {proc} && $type ne {method})} { | |
792 | error "Invalid arguments to git-version" | |
793 | } | |
794 | if {[llength $body] < 2 || [lindex $body end-1] ne {default}} { | |
795 | error "Last arm of $type $name must be default" | |
796 | } | |
797 | ||
798 | foreach {op vr cb} [lrange $body 0 end-2] { | |
799 | if {[git-version $op $vr]} { | |
800 | return [uplevel [list $type $name $parm $cb]] | |
801 | } | |
802 | } | |
803 | ||
804 | return [uplevel [list $type $name $parm [lindex $body end]]] | |
805 | } | |
806 | ||
807 | default { | |
808 | error "git-version >= x" | |
809 | } | |
810 | ||
811 | } | |
812 | } | |
813 | ||
814 | if {[git-version < 1.5]} { | |
54acdd95 | 815 | catch {wm withdraw .} |
875b7c93 SP |
816 | tk_messageBox \ |
817 | -icon error \ | |
818 | -type ok \ | |
c8c4854b | 819 | -title [mc "git-gui: fatal error"] \ |
875b7c93 | 820 | -message "[appname] requires Git 1.5.0 or later. |
d6967022 SP |
821 | |
822 | You are using [git-version]: | |
823 | ||
824 | [git --version]" | |
54acdd95 SP |
825 | exit 1 |
826 | } | |
54acdd95 | 827 | |
875b7c93 SP |
828 | ###################################################################### |
829 | ## | |
830 | ## configure our library | |
831 | ||
875b7c93 SP |
832 | set idx [file join $oguilib tclIndex] |
833 | if {[catch {set fd [open $idx r]} err]} { | |
834 | catch {wm withdraw .} | |
835 | tk_messageBox \ | |
836 | -icon error \ | |
837 | -type ok \ | |
c8c4854b | 838 | -title [mc "git-gui: fatal error"] \ |
875b7c93 SP |
839 | -message $err |
840 | exit 1 | |
841 | } | |
842 | if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} { | |
843 | set idx [list] | |
844 | while {[gets $fd n] >= 0} { | |
845 | if {$n ne {} && ![string match #* $n]} { | |
846 | lappend idx $n | |
847 | } | |
848 | } | |
849 | } else { | |
850 | set idx {} | |
851 | } | |
852 | close $fd | |
853 | ||
854 | if {$idx ne {}} { | |
855 | set loaded [list] | |
856 | foreach p $idx { | |
857 | if {[lsearch -exact $loaded $p] >= 0} continue | |
858 | source [file join $oguilib $p] | |
859 | lappend loaded $p | |
860 | } | |
861 | unset loaded p | |
862 | } else { | |
863 | set auto_path [concat [list $oguilib] $auto_path] | |
864 | } | |
fc703c20 | 865 | unset -nocomplain idx fd |
875b7c93 | 866 | |
ba7cc660 | 867 | ###################################################################### |
69f85ffa SP |
868 | ## |
869 | ## config file parsing | |
870 | ||
f00d504a | 871 | git-version proc _parse_config {arr_name args} { |
85f7a94b SP |
872 | >= 1.5.3 { |
873 | upvar $arr_name arr | |
874 | array unset arr | |
875 | set buf {} | |
876 | catch { | |
a5bb31fb SP |
877 | set fd_rc [eval \ |
878 | [list git_read config] \ | |
879 | $args \ | |
880 | [list --null --list]] | |
85f7a94b SP |
881 | fconfigure $fd_rc -translation binary |
882 | set buf [read $fd_rc] | |
883 | close $fd_rc | |
884 | } | |
885 | foreach line [split $buf "\0"] { | |
886 | if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} { | |
887 | if {[is_many_config $name]} { | |
888 | lappend arr($name) $value | |
889 | } else { | |
890 | set arr($name) $value | |
891 | } | |
892 | } | |
893 | } | |
894 | } | |
f00d504a SP |
895 | default { |
896 | upvar $arr_name arr | |
897 | array unset arr | |
69f85ffa | 898 | catch { |
f00d504a | 899 | set fd_rc [eval [list git_read config --list] $args] |
69f85ffa SP |
900 | while {[gets $fd_rc line] >= 0} { |
901 | if {[regexp {^([^=]+)=(.*)$} $line line name value]} { | |
902 | if {[is_many_config $name]} { | |
f00d504a | 903 | lappend arr($name) $value |
69f85ffa | 904 | } else { |
f00d504a | 905 | set arr($name) $value |
69f85ffa SP |
906 | } |
907 | } | |
908 | } | |
909 | close $fd_rc | |
910 | } | |
911 | } | |
f00d504a | 912 | } |
69f85ffa | 913 | |
f00d504a SP |
914 | proc load_config {include_global} { |
915 | global repo_config global_config default_config | |
916 | ||
917 | if {$include_global} { | |
918 | _parse_config global_config --global | |
69f85ffa | 919 | } |
f00d504a | 920 | _parse_config repo_config |
69f85ffa SP |
921 | |
922 | foreach name [array names default_config] { | |
923 | if {[catch {set v $global_config($name)}]} { | |
924 | set global_config($name) $default_config($name) | |
925 | } | |
926 | if {[catch {set v $repo_config($name)}]} { | |
927 | set repo_config($name) $default_config($name) | |
928 | } | |
929 | } | |
930 | } | |
931 | ||
932 | ###################################################################### | |
ba7cc660 SP |
933 | ## |
934 | ## feature option selection | |
935 | ||
0b2bc460 | 936 | if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} { |
ba7cc660 SP |
937 | unset _junk |
938 | } else { | |
939 | set subcommand gui | |
940 | } | |
941 | if {$subcommand eq {gui.sh}} { | |
942 | set subcommand gui | |
943 | } | |
944 | if {$subcommand eq {gui} && [llength $argv] > 0} { | |
945 | set subcommand [lindex $argv 0] | |
946 | set argv [lrange $argv 1 end] | |
947 | } | |
948 | ||
949 | enable_option multicommit | |
950 | enable_option branch | |
951 | enable_option transport | |
c52c9452 | 952 | disable_option bare |
ba7cc660 SP |
953 | |
954 | switch -- $subcommand { | |
955 | browser - | |
956 | blame { | |
c52c9452 SP |
957 | enable_option bare |
958 | ||
ba7cc660 SP |
959 | disable_option multicommit |
960 | disable_option branch | |
961 | disable_option transport | |
962 | } | |
963 | citool { | |
964 | enable_option singlecommit | |
1e65c622 | 965 | enable_option retcode |
ba7cc660 SP |
966 | |
967 | disable_option multicommit | |
968 | disable_option branch | |
969 | disable_option transport | |
1e65c622 AG |
970 | |
971 | while {[llength $argv] > 0} { | |
972 | set a [lindex $argv 0] | |
973 | switch -- $a { | |
974 | --amend { | |
975 | enable_option initialamend | |
976 | } | |
977 | --nocommit { | |
978 | enable_option nocommit | |
979 | enable_option nocommitmsg | |
980 | } | |
981 | --commitmsg { | |
982 | disable_option nocommitmsg | |
983 | } | |
984 | default { | |
985 | break | |
986 | } | |
987 | } | |
988 | ||
989 | set argv [lrange $argv 1 end] | |
990 | } | |
ba7cc660 SP |
991 | } |
992 | } | |
993 | ||
2d19516d SP |
994 | ###################################################################### |
995 | ## | |
996 | ## repository setup | |
997 | ||
bb4812bc | 998 | set picked 0 |
c6127856 SP |
999 | if {[catch { |
1000 | set _gitdir $env(GIT_DIR) | |
1001 | set _prefix {} | |
1002 | }] | |
1003 | && [catch { | |
1004 | set _gitdir [git rev-parse --git-dir] | |
1005 | set _prefix [git rev-parse --show-prefix] | |
1006 | } err]} { | |
ab08b363 SP |
1007 | load_config 1 |
1008 | apply_config | |
1009 | choose_repository::pick | |
bb4812bc | 1010 | set picked 1 |
2d19516d | 1011 | } |
20ddfcaa | 1012 | if {![file isdirectory $_gitdir] && [is_Cygwin]} { |
2f7c9a7f | 1013 | catch {set _gitdir [exec cygpath --windows $_gitdir]} |
20ddfcaa | 1014 | } |
c950c66e | 1015 | if {![file isdirectory $_gitdir]} { |
dbccbbda | 1016 | catch {wm withdraw .} |
31bb1d1b | 1017 | error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"] |
dbccbbda SP |
1018 | exit 1 |
1019 | } | |
c80d25db SP |
1020 | if {$_prefix ne {}} { |
1021 | regsub -all {[^/]+/} $_prefix ../ cdup | |
1022 | if {[catch {cd $cdup} err]} { | |
1023 | catch {wm withdraw .} | |
31bb1d1b | 1024 | error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"] |
c80d25db SP |
1025 | exit 1 |
1026 | } | |
1027 | unset cdup | |
1028 | } elseif {![is_enabled bare]} { | |
c52c9452 SP |
1029 | if {[lindex [file split $_gitdir] end] ne {.git}} { |
1030 | catch {wm withdraw .} | |
31bb1d1b | 1031 | error_popup [strcat [mc "Cannot use funny .git directory:"] "\n\n$_gitdir"] |
c52c9452 SP |
1032 | exit 1 |
1033 | } | |
1034 | if {[catch {cd [file dirname $_gitdir]} err]} { | |
1035 | catch {wm withdraw .} | |
31bb1d1b | 1036 | error_popup [strcat [mc "No working directory"] " [file dirname $_gitdir]:\n\n$err"] |
c52c9452 SP |
1037 | exit 1 |
1038 | } | |
dbccbbda | 1039 | } |
c52c9452 SP |
1040 | set _reponame [file split [file normalize $_gitdir]] |
1041 | if {[lindex $_reponame end] eq {.git}} { | |
1042 | set _reponame [lindex $_reponame end-1] | |
1043 | } else { | |
1044 | set _reponame [lindex $_reponame end] | |
2d19516d | 1045 | } |
2d19516d | 1046 | |
372ef954 SP |
1047 | ###################################################################### |
1048 | ## | |
1049 | ## global init | |
1050 | ||
1051 | set current_diff_path {} | |
1052 | set current_diff_side {} | |
1053 | set diff_actions [list] | |
372ef954 SP |
1054 | |
1055 | set HEAD {} | |
1056 | set PARENT {} | |
1057 | set MERGE_HEAD [list] | |
1058 | set commit_type {} | |
1059 | set empty_tree {} | |
1060 | set current_branch {} | |
d41b43eb | 1061 | set is_detached 0 |
372ef954 | 1062 | set current_diff_path {} |
9c9f5fa9 | 1063 | set is_3way_diff 0 |
3e34838c | 1064 | set is_conflict_diff 0 |
372ef954 SP |
1065 | set selected_commit_type new |
1066 | ||
a9786bb4 AG |
1067 | set nullid "0000000000000000000000000000000000000000" |
1068 | set nullid2 "0000000000000000000000000000000000000001" | |
1069 | ||
cb07fc2a SP |
1070 | ###################################################################### |
1071 | ## | |
e210e674 | 1072 | ## task management |
cb07fc2a | 1073 | |
8f52548a | 1074 | set rescan_active 0 |
131f503b | 1075 | set diff_active 0 |
24263b77 | 1076 | set last_clicked {} |
131f503b | 1077 | |
e210e674 SP |
1078 | set disable_on_lock [list] |
1079 | set index_lock_type none | |
1080 | ||
1081 | proc lock_index {type} { | |
1082 | global index_lock_type disable_on_lock | |
131f503b | 1083 | |
043f7011 | 1084 | if {$index_lock_type eq {none}} { |
e210e674 SP |
1085 | set index_lock_type $type |
1086 | foreach w $disable_on_lock { | |
1087 | uplevel #0 $w disabled | |
1088 | } | |
1089 | return 1 | |
53716a7b | 1090 | } elseif {$index_lock_type eq "begin-$type"} { |
e210e674 | 1091 | set index_lock_type $type |
131f503b SP |
1092 | return 1 |
1093 | } | |
1094 | return 0 | |
1095 | } | |
cb07fc2a | 1096 | |
e210e674 SP |
1097 | proc unlock_index {} { |
1098 | global index_lock_type disable_on_lock | |
1099 | ||
1100 | set index_lock_type none | |
1101 | foreach w $disable_on_lock { | |
1102 | uplevel #0 $w normal | |
1103 | } | |
1104 | } | |
1105 | ||
1106 | ###################################################################### | |
1107 | ## | |
1108 | ## status | |
1109 | ||
f18e40a1 | 1110 | proc repository_state {ctvar hdvar mhvar} { |
c950c66e | 1111 | global current_branch |
f18e40a1 SP |
1112 | upvar $ctvar ct $hdvar hd $mhvar mh |
1113 | ||
1114 | set mh [list] | |
ec6b424a | 1115 | |
d41b43eb | 1116 | load_current_branch |
81347223 | 1117 | if {[catch {set hd [git rev-parse --verify HEAD]}]} { |
4539eacd | 1118 | set hd {} |
ec6b424a | 1119 | set ct initial |
f18e40a1 SP |
1120 | return |
1121 | } | |
1122 | ||
c2758a17 | 1123 | set merge_head [gitdir MERGE_HEAD] |
f18e40a1 | 1124 | if {[file exists $merge_head]} { |
ec6b424a | 1125 | set ct merge |
f18e40a1 SP |
1126 | set fd_mh [open $merge_head r] |
1127 | while {[gets $fd_mh line] >= 0} { | |
1128 | lappend mh $line | |
1129 | } | |
1130 | close $fd_mh | |
1131 | return | |
ec6b424a | 1132 | } |
f18e40a1 SP |
1133 | |
1134 | set ct normal | |
ec6b424a SP |
1135 | } |
1136 | ||
4539eacd SP |
1137 | proc PARENT {} { |
1138 | global PARENT empty_tree | |
1139 | ||
f18e40a1 SP |
1140 | set p [lindex $PARENT 0] |
1141 | if {$p ne {}} { | |
1142 | return $p | |
4539eacd SP |
1143 | } |
1144 | if {$empty_tree eq {}} { | |
81347223 | 1145 | set empty_tree [git mktree << {}] |
4539eacd SP |
1146 | } |
1147 | return $empty_tree | |
1148 | } | |
1149 | ||
1e65c622 AG |
1150 | proc force_amend {} { |
1151 | global selected_commit_type | |
1152 | global HEAD PARENT MERGE_HEAD commit_type | |
1153 | ||
1154 | repository_state newType newHEAD newMERGE_HEAD | |
1155 | set HEAD $newHEAD | |
1156 | set PARENT $newHEAD | |
1157 | set MERGE_HEAD $newMERGE_HEAD | |
1158 | set commit_type $newType | |
1159 | ||
1160 | set selected_commit_type amend | |
1161 | do_select_commit_type | |
1162 | } | |
1163 | ||
46aaf90b | 1164 | proc rescan {after {honor_trustmtime 1}} { |
f18e40a1 | 1165 | global HEAD PARENT MERGE_HEAD commit_type |
699d5601 | 1166 | global ui_index ui_workdir ui_comm |
8f52548a | 1167 | global rescan_active file_states |
cf25ddc8 | 1168 | global repo_config |
cb07fc2a | 1169 | |
8f52548a | 1170 | if {$rescan_active > 0 || ![lock_index read]} return |
cb07fc2a | 1171 | |
f18e40a1 | 1172 | repository_state newType newHEAD newMERGE_HEAD |
4539eacd | 1173 | if {[string match amend* $commit_type] |
f18e40a1 SP |
1174 | && $newType eq {normal} |
1175 | && $newHEAD eq $HEAD} { | |
e57ca85e | 1176 | } else { |
f18e40a1 SP |
1177 | set HEAD $newHEAD |
1178 | set PARENT $newHEAD | |
1179 | set MERGE_HEAD $newMERGE_HEAD | |
1180 | set commit_type $newType | |
e57ca85e SP |
1181 | } |
1182 | ||
cb07fc2a | 1183 | array unset file_states |
cb07fc2a | 1184 | |
1e0a92fd SP |
1185 | if {!$::GITGUI_BCK_exists && |
1186 | (![$ui_comm edit modified] | |
1187 | || [string trim [$ui_comm get 0.0 end]] eq {})} { | |
b2f3bb1b SP |
1188 | if {[string match amend* $commit_type]} { |
1189 | } elseif {[load_message GITGUI_MSG]} { | |
2cd1fd1f | 1190 | } elseif {[run_prepare_commit_msg_hook]} { |
131f503b SP |
1191 | } elseif {[load_message MERGE_MSG]} { |
1192 | } elseif {[load_message SQUASH_MSG]} { | |
1193 | } | |
b2c6fcf1 | 1194 | $ui_comm edit reset |
21d7744f | 1195 | $ui_comm edit modified false |
131f503b SP |
1196 | } |
1197 | ||
46aaf90b | 1198 | if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} { |
8f52548a | 1199 | rescan_stage2 {} $after |
e534f3a8 | 1200 | } else { |
8f52548a | 1201 | set rescan_active 1 |
1ac17950 | 1202 | ui_status [mc "Refreshing file status..."] |
0b812616 SP |
1203 | set fd_rf [git_read update-index \ |
1204 | -q \ | |
1205 | --unmerged \ | |
1206 | --ignore-missing \ | |
1207 | --refresh \ | |
1208 | ] | |
e534f3a8 | 1209 | fconfigure $fd_rf -blocking 0 -translation binary |
390adaea | 1210 | fileevent $fd_rf readable \ |
8f52548a | 1211 | [list rescan_stage2 $fd_rf $after] |
e534f3a8 | 1212 | } |
131f503b SP |
1213 | } |
1214 | ||
2fe167b6 | 1215 | if {[is_Cygwin]} { |
2fe167b6 SP |
1216 | set is_git_info_exclude {} |
1217 | proc have_info_exclude {} { | |
7f83aa2d | 1218 | global is_git_info_exclude |
2fe167b6 | 1219 | |
7f83aa2d SP |
1220 | if {$is_git_info_exclude eq {}} { |
1221 | if {[catch {exec test -f [gitdir info exclude]}]} { | |
1222 | set is_git_info_exclude 0 | |
1223 | } else { | |
1224 | set is_git_info_exclude 1 | |
2fe167b6 | 1225 | } |
2fe167b6 | 1226 | } |
7f83aa2d | 1227 | return $is_git_info_exclude |
2fe167b6 SP |
1228 | } |
1229 | } else { | |
1230 | proc have_info_exclude {} { | |
1231 | return [file readable [gitdir info exclude]] | |
1232 | } | |
1233 | } | |
1234 | ||
8f52548a | 1235 | proc rescan_stage2 {fd after} { |
4539eacd | 1236 | global rescan_active buf_rdi buf_rdf buf_rlo |
131f503b | 1237 | |
043f7011 | 1238 | if {$fd ne {}} { |
e534f3a8 SP |
1239 | read $fd |
1240 | if {![eof $fd]} return | |
1241 | close $fd | |
1242 | } | |
131f503b | 1243 | |
0b812616 | 1244 | set ls_others [list --exclude-per-directory=.gitignore] |
2fe167b6 SP |
1245 | if {[have_info_exclude]} { |
1246 | lappend ls_others "--exclude-from=[gitdir info exclude]" | |
cb07fc2a | 1247 | } |
94a4dd9b SP |
1248 | set user_exclude [get_config core.excludesfile] |
1249 | if {$user_exclude ne {} && [file readable $user_exclude]} { | |
1250 | lappend ls_others "--exclude-from=$user_exclude" | |
1251 | } | |
cb07fc2a | 1252 | |
868c8752 SP |
1253 | set buf_rdi {} |
1254 | set buf_rdf {} | |
1255 | set buf_rlo {} | |
1256 | ||
8f52548a | 1257 | set rescan_active 3 |
1ac17950 | 1258 | ui_status [mc "Scanning for modified files ..."] |
0b812616 SP |
1259 | set fd_di [git_read diff-index --cached -z [PARENT]] |
1260 | set fd_df [git_read diff-files -z] | |
1261 | set fd_lo [eval git_read ls-files --others -z $ls_others] | |
cb07fc2a | 1262 | |
51a989ba SP |
1263 | fconfigure $fd_di -blocking 0 -translation binary -encoding binary |
1264 | fconfigure $fd_df -blocking 0 -translation binary -encoding binary | |
1265 | fconfigure $fd_lo -blocking 0 -translation binary -encoding binary | |
8f52548a SP |
1266 | fileevent $fd_di readable [list read_diff_index $fd_di $after] |
1267 | fileevent $fd_df readable [list read_diff_files $fd_df $after] | |
1268 | fileevent $fd_lo readable [list read_ls_others $fd_lo $after] | |
cb07fc2a SP |
1269 | } |
1270 | ||
131f503b | 1271 | proc load_message {file} { |
c950c66e | 1272 | global ui_comm |
131f503b | 1273 | |
c2758a17 | 1274 | set f [gitdir $file] |
e57ca85e | 1275 | if {[file isfile $f]} { |
131f503b SP |
1276 | if {[catch {set fd [open $f r]}]} { |
1277 | return 0 | |
1278 | } | |
6eb420ef | 1279 | fconfigure $fd -eofchar {} |
e57ca85e | 1280 | set content [string trim [read $fd]] |
131f503b | 1281 | close $fd |
4e55d19a | 1282 | regsub -all -line {[ \r\t]+$} $content {} content |
131f503b SP |
1283 | $ui_comm delete 0.0 end |
1284 | $ui_comm insert end $content | |
1285 | return 1 | |
1286 | } | |
1287 | return 0 | |
1288 | } | |
1289 | ||
2cd1fd1f JW |
1290 | proc run_prepare_commit_msg_hook {} { |
1291 | global pch_error | |
1292 | ||
1293 | # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui | |
1294 | # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an | |
1295 | # empty file but existant file. | |
1296 | ||
1297 | set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a] | |
1298 | ||
1299 | if {[file isfile [gitdir MERGE_MSG]]} { | |
1300 | set pcm_source "merge" | |
1301 | set fd_mm [open [gitdir MERGE_MSG] r] | |
1302 | puts -nonewline $fd_pcm [read $fd_mm] | |
1303 | close $fd_mm | |
1304 | } elseif {[file isfile [gitdir SQUASH_MSG]]} { | |
1305 | set pcm_source "squash" | |
1306 | set fd_sm [open [gitdir SQUASH_MSG] r] | |
1307 | puts -nonewline $fd_pcm [read $fd_sm] | |
1308 | close $fd_sm | |
1309 | } else { | |
1310 | set pcm_source "" | |
1311 | } | |
1312 | ||
1313 | close $fd_pcm | |
1314 | ||
1315 | set fd_ph [githook_read prepare-commit-msg \ | |
1316 | [gitdir PREPARE_COMMIT_MSG] $pcm_source] | |
1317 | if {$fd_ph eq {}} { | |
1318 | catch {file delete [gitdir PREPARE_COMMIT_MSG]} | |
1319 | return 0; | |
1320 | } | |
1321 | ||
1322 | ui_status [mc "Calling prepare-commit-msg hook..."] | |
1323 | set pch_error {} | |
1324 | ||
1325 | fconfigure $fd_ph -blocking 0 -translation binary -eofchar {} | |
1326 | fileevent $fd_ph readable \ | |
1327 | [list prepare_commit_msg_hook_wait $fd_ph] | |
1328 | ||
1329 | return 1; | |
1330 | } | |
1331 | ||
1332 | proc prepare_commit_msg_hook_wait {fd_ph} { | |
1333 | global pch_error | |
1334 | ||
1335 | append pch_error [read $fd_ph] | |
1336 | fconfigure $fd_ph -blocking 1 | |
1337 | if {[eof $fd_ph]} { | |
1338 | if {[catch {close $fd_ph}]} { | |
1339 | ui_status [mc "Commit declined by prepare-commit-msg hook."] | |
1340 | hook_failed_popup prepare-commit-msg $pch_error | |
1341 | catch {file delete [gitdir PREPARE_COMMIT_MSG]} | |
1342 | exit 1 | |
1343 | } else { | |
1344 | load_message PREPARE_COMMIT_MSG | |
1345 | } | |
1346 | set pch_error {} | |
1347 | catch {file delete [gitdir PREPARE_COMMIT_MSG]} | |
1348 | return | |
1349 | } | |
1350 | fconfigure $fd_ph -blocking 0 | |
1351 | catch {file delete [gitdir PREPARE_COMMIT_MSG]} | |
1352 | } | |
1353 | ||
8f52548a | 1354 | proc read_diff_index {fd after} { |
cb07fc2a SP |
1355 | global buf_rdi |
1356 | ||
1357 | append buf_rdi [read $fd] | |
868c8752 SP |
1358 | set c 0 |
1359 | set n [string length $buf_rdi] | |
1360 | while {$c < $n} { | |
1361 | set z1 [string first "\0" $buf_rdi $c] | |
1362 | if {$z1 == -1} break | |
1363 | incr z1 | |
1364 | set z2 [string first "\0" $buf_rdi $z1] | |
1365 | if {$z2 == -1} break | |
1366 | ||
868c8752 | 1367 | incr c |
86291555 | 1368 | set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }] |
51a989ba | 1369 | set p [string range $buf_rdi $z1 [expr {$z2 - 1}]] |
1461c5f3 | 1370 | merge_state \ |
51a989ba | 1371 | [encoding convertfrom $p] \ |
86291555 SP |
1372 | [lindex $i 4]? \ |
1373 | [list [lindex $i 0] [lindex $i 2]] \ | |
1461c5f3 SP |
1374 | [list] |
1375 | set c $z2 | |
86291555 | 1376 | incr c |
cb07fc2a | 1377 | } |
868c8752 SP |
1378 | if {$c < $n} { |
1379 | set buf_rdi [string range $buf_rdi $c end] | |
1380 | } else { | |
1381 | set buf_rdi {} | |
1382 | } | |
1383 | ||
8f52548a | 1384 | rescan_done $fd buf_rdi $after |
cb07fc2a SP |
1385 | } |
1386 | ||
8f52548a | 1387 | proc read_diff_files {fd after} { |
cb07fc2a SP |
1388 | global buf_rdf |
1389 | ||
1390 | append buf_rdf [read $fd] | |
868c8752 SP |
1391 | set c 0 |
1392 | set n [string length $buf_rdf] | |
1393 | while {$c < $n} { | |
1394 | set z1 [string first "\0" $buf_rdf $c] | |
1395 | if {$z1 == -1} break | |
1396 | incr z1 | |
1397 | set z2 [string first "\0" $buf_rdf $z1] | |
1398 | if {$z2 == -1} break | |
1399 | ||
868c8752 | 1400 | incr c |
86291555 | 1401 | set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }] |
51a989ba | 1402 | set p [string range $buf_rdf $z1 [expr {$z2 - 1}]] |
1461c5f3 | 1403 | merge_state \ |
51a989ba | 1404 | [encoding convertfrom $p] \ |
86291555 | 1405 | ?[lindex $i 4] \ |
1461c5f3 | 1406 | [list] \ |
86291555 | 1407 | [list [lindex $i 0] [lindex $i 2]] |
1461c5f3 | 1408 | set c $z2 |
86291555 | 1409 | incr c |
868c8752 SP |
1410 | } |
1411 | if {$c < $n} { | |
1412 | set buf_rdf [string range $buf_rdf $c end] | |
1413 | } else { | |
1414 | set buf_rdf {} | |
cb07fc2a | 1415 | } |
868c8752 | 1416 | |
8f52548a | 1417 | rescan_done $fd buf_rdf $after |
cb07fc2a SP |
1418 | } |
1419 | ||
8f52548a | 1420 | proc read_ls_others {fd after} { |
cb07fc2a SP |
1421 | global buf_rlo |
1422 | ||
1423 | append buf_rlo [read $fd] | |
1424 | set pck [split $buf_rlo "\0"] | |
1425 | set buf_rlo [lindex $pck end] | |
1426 | foreach p [lrange $pck 0 end-1] { | |
89384101 SP |
1427 | set p [encoding convertfrom $p] |
1428 | if {[string index $p end] eq {/}} { | |
1429 | set p [string range $p 0 end-1] | |
1430 | } | |
1431 | merge_state $p ?O | |
cb07fc2a | 1432 | } |
8f52548a | 1433 | rescan_done $fd buf_rlo $after |
cb07fc2a SP |
1434 | } |
1435 | ||
8f52548a | 1436 | proc rescan_done {fd buf after} { |
f522c9b5 | 1437 | global rescan_active current_diff_path |
f7f8d322 | 1438 | global file_states repo_config |
7f1df79b | 1439 | upvar $buf to_clear |
cb07fc2a | 1440 | |
f7f8d322 SP |
1441 | if {![eof $fd]} return |
1442 | set to_clear {} | |
1443 | close $fd | |
8f52548a | 1444 | if {[incr rescan_active -1] > 0} return |
93f654df | 1445 | |
24263b77 | 1446 | prune_selection |
f7f8d322 SP |
1447 | unlock_index |
1448 | display_all_files | |
f522c9b5 | 1449 | if {$current_diff_path ne {}} reshow_diff |
29853b90 AG |
1450 | if {$current_diff_path eq {}} select_first_diff |
1451 | ||
8f52548a | 1452 | uplevel #0 $after |
cb07fc2a SP |
1453 | } |
1454 | ||
24263b77 SP |
1455 | proc prune_selection {} { |
1456 | global file_states selected_paths | |
1457 | ||
1458 | foreach path [array names selected_paths] { | |
1459 | if {[catch {set still_here $file_states($path)}]} { | |
1460 | unset selected_paths($path) | |
1461 | } | |
1462 | } | |
1463 | } | |
1464 | ||
cb07fc2a SP |
1465 | ###################################################################### |
1466 | ## | |
f522c9b5 | 1467 | ## ui helpers |
cb07fc2a | 1468 | |
f522c9b5 SP |
1469 | proc mapicon {w state path} { |
1470 | global all_icons | |
1471 | ||
1472 | if {[catch {set r $all_icons($state$w)}]} { | |
1473 | puts "error: no icon for $w state={$state} $path" | |
1474 | return file_plain | |
1475 | } | |
1476 | return $r | |
1477 | } | |
cb07fc2a | 1478 | |
f522c9b5 SP |
1479 | proc mapdesc {state path} { |
1480 | global all_descs | |
03e4ec53 | 1481 | |
f522c9b5 SP |
1482 | if {[catch {set r $all_descs($state)}]} { |
1483 | puts "error: no desc for state={$state} $path" | |
1484 | return $state | |
1485 | } | |
1486 | return $r | |
1487 | } | |
03e4ec53 | 1488 | |
699d5601 | 1489 | proc ui_status {msg} { |
906ab7f6 SP |
1490 | global main_status |
1491 | if {[info exists main_status]} { | |
1492 | $main_status show $msg | |
1493 | } | |
699d5601 SP |
1494 | } |
1495 | ||
1496 | proc ui_ready {{test {}}} { | |
906ab7f6 SP |
1497 | global main_status |
1498 | if {[info exists main_status]} { | |
1499 | $main_status show [mc "Ready."] $test | |
1500 | } | |
699d5601 SP |
1501 | } |
1502 | ||
f522c9b5 SP |
1503 | proc escape_path {path} { |
1504 | regsub -all {\\} $path "\\\\" path | |
1505 | regsub -all "\n" $path "\\n" path | |
1506 | return $path | |
cb07fc2a SP |
1507 | } |
1508 | ||
f522c9b5 SP |
1509 | proc short_path {path} { |
1510 | return [escape_path [lindex [file split $path] end]] | |
7f1df79b SP |
1511 | } |
1512 | ||
f522c9b5 SP |
1513 | set next_icon_id 0 |
1514 | set null_sha1 [string repeat 0 40] | |
16403d0b | 1515 | |
f522c9b5 SP |
1516 | proc merge_state {path new_state {head_info {}} {index_info {}}} { |
1517 | global file_states next_icon_id null_sha1 | |
16403d0b | 1518 | |
f522c9b5 SP |
1519 | set s0 [string index $new_state 0] |
1520 | set s1 [string index $new_state 1] | |
16403d0b | 1521 | |
f522c9b5 SP |
1522 | if {[catch {set info $file_states($path)}]} { |
1523 | set state __ | |
1524 | set icon n[incr next_icon_id] | |
1525 | } else { | |
1526 | set state [lindex $info 0] | |
1527 | set icon [lindex $info 1] | |
1528 | if {$head_info eq {}} {set head_info [lindex $info 2]} | |
1529 | if {$index_info eq {}} {set index_info [lindex $info 3]} | |
1530 | } | |
16403d0b | 1531 | |
f522c9b5 SP |
1532 | if {$s0 eq {?}} {set s0 [string index $state 0]} \ |
1533 | elseif {$s0 eq {_}} {set s0 _} | |
124355d3 | 1534 | |
f522c9b5 SP |
1535 | if {$s1 eq {?}} {set s1 [string index $state 1]} \ |
1536 | elseif {$s1 eq {_}} {set s1 _} | |
16403d0b | 1537 | |
f522c9b5 SP |
1538 | if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} { |
1539 | set head_info [list 0 $null_sha1] | |
1540 | } elseif {$s0 ne {_} && [string index $state 0] eq {_} | |
1541 | && $head_info eq {}} { | |
1542 | set head_info $index_info | |
1543 | } | |
16403d0b | 1544 | |
f522c9b5 SP |
1545 | set file_states($path) [list $s0$s1 $icon \ |
1546 | $head_info $index_info \ | |
1547 | ] | |
1548 | return $state | |
1549 | } | |
cb07fc2a | 1550 | |
f522c9b5 SP |
1551 | proc display_file_helper {w path icon_name old_m new_m} { |
1552 | global file_lists | |
cb07fc2a | 1553 | |
f522c9b5 | 1554 | if {$new_m eq {_}} { |
156b2921 | 1555 | set lno [lsearch -sorted -exact $file_lists($w) $path] |
5f8b70b1 | 1556 | if {$lno >= 0} { |
f522c9b5 | 1557 | set file_lists($w) [lreplace $file_lists($w) $lno $lno] |
5f8b70b1 | 1558 | incr lno |
f522c9b5 SP |
1559 | $w conf -state normal |
1560 | $w delete $lno.0 [expr {$lno + 1}].0 | |
1561 | $w conf -state disabled | |
03e4ec53 | 1562 | } |
f522c9b5 SP |
1563 | } elseif {$old_m eq {_} && $new_m ne {_}} { |
1564 | lappend file_lists($w) $path | |
1565 | set file_lists($w) [lsort -unique $file_lists($w)] | |
1566 | set lno [lsearch -sorted -exact $file_lists($w) $path] | |
1567 | incr lno | |
1568 | $w conf -state normal | |
1569 | $w image create $lno.0 \ | |
1570 | -align center -padx 5 -pady 1 \ | |
1571 | -name $icon_name \ | |
1572 | -image [mapicon $w $new_m $path] | |
1573 | $w insert $lno.1 "[escape_path $path]\n" | |
1574 | $w conf -state disabled | |
1575 | } elseif {$old_m ne $new_m} { | |
1576 | $w conf -state normal | |
1577 | $w image conf $icon_name -image [mapicon $w $new_m $path] | |
1578 | $w conf -state disabled | |
03e4ec53 | 1579 | } |
f522c9b5 SP |
1580 | } |
1581 | ||
1582 | proc display_file {path state} { | |
1583 | global file_states selected_paths | |
1584 | global ui_index ui_workdir | |
03e4ec53 | 1585 | |
f522c9b5 | 1586 | set old_m [merge_state $path $state] |
cb07fc2a | 1587 | set s $file_states($path) |
f522c9b5 SP |
1588 | set new_m [lindex $s 0] |
1589 | set icon_name [lindex $s 1] | |
82cb8706 | 1590 | |
f522c9b5 SP |
1591 | set o [string index $old_m 0] |
1592 | set n [string index $new_m 0] | |
1593 | if {$o eq {U}} { | |
1594 | set o _ | |
1595 | } | |
1596 | if {$n eq {U}} { | |
1597 | set n _ | |
cb07fc2a | 1598 | } |
f522c9b5 | 1599 | display_file_helper $ui_index $path $icon_name $o $n |
cb07fc2a | 1600 | |
f522c9b5 SP |
1601 | if {[string index $old_m 0] eq {U}} { |
1602 | set o U | |
1603 | } else { | |
1604 | set o [string index $old_m 1] | |
82cb8706 | 1605 | } |
f522c9b5 SP |
1606 | if {[string index $new_m 0] eq {U}} { |
1607 | set n U | |
1608 | } else { | |
1609 | set n [string index $new_m 1] | |
82cb8706 | 1610 | } |
f522c9b5 SP |
1611 | display_file_helper $ui_workdir $path $icon_name $o $n |
1612 | ||
1613 | if {$new_m eq {__}} { | |
1614 | unset file_states($path) | |
1615 | catch {unset selected_paths($path)} | |
cb07fc2a | 1616 | } |
f522c9b5 | 1617 | } |
cb07fc2a | 1618 | |
f522c9b5 SP |
1619 | proc display_all_files_helper {w path icon_name m} { |
1620 | global file_lists | |
1621 | ||
1622 | lappend file_lists($w) $path | |
1623 | set lno [expr {[lindex [split [$w index end] .] 0] - 1}] | |
1624 | $w image create end \ | |
1625 | -align center -padx 5 -pady 1 \ | |
1626 | -name $icon_name \ | |
1627 | -image [mapicon $w $m $path] | |
1628 | $w insert end "[escape_path $path]\n" | |
cb07fc2a SP |
1629 | } |
1630 | ||
f522c9b5 SP |
1631 | proc display_all_files {} { |
1632 | global ui_index ui_workdir | |
1633 | global file_states file_lists | |
1634 | global last_clicked | |
cb07fc2a | 1635 | |
f522c9b5 SP |
1636 | $ui_index conf -state normal |
1637 | $ui_workdir conf -state normal | |
cb07fc2a | 1638 | |
f522c9b5 SP |
1639 | $ui_index delete 0.0 end |
1640 | $ui_workdir delete 0.0 end | |
1641 | set last_clicked {} | |
cb07fc2a | 1642 | |
f522c9b5 SP |
1643 | set file_lists($ui_index) [list] |
1644 | set file_lists($ui_workdir) [list] | |
16403d0b | 1645 | |
f522c9b5 SP |
1646 | foreach path [lsort [array names file_states]] { |
1647 | set s $file_states($path) | |
1648 | set m [lindex $s 0] | |
1649 | set icon_name [lindex $s 1] | |
1650 | ||
1651 | set s [string index $m 0] | |
1652 | if {$s ne {U} && $s ne {_}} { | |
1653 | display_all_files_helper $ui_index $path \ | |
1654 | $icon_name $s | |
16403d0b | 1655 | } |
cb07fc2a | 1656 | |
f522c9b5 SP |
1657 | if {[string index $m 0] eq {U}} { |
1658 | set s U | |
1659 | } else { | |
1660 | set s [string index $m 1] | |
a25c5189 | 1661 | } |
f522c9b5 SP |
1662 | if {$s ne {_}} { |
1663 | display_all_files_helper $ui_workdir $path \ | |
1664 | $icon_name $s | |
a25c5189 SP |
1665 | } |
1666 | } | |
1667 | ||
f522c9b5 SP |
1668 | $ui_index conf -state disabled |
1669 | $ui_workdir conf -state disabled | |
a25c5189 SP |
1670 | } |
1671 | ||
ec6b424a SP |
1672 | ###################################################################### |
1673 | ## | |
f522c9b5 | 1674 | ## icons |
ec6b424a | 1675 | |
f522c9b5 SP |
1676 | set filemask { |
1677 | #define mask_width 14 | |
1678 | #define mask_height 15 | |
1679 | static unsigned char mask_bits[] = { | |
1680 | 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, | |
1681 | 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, | |
1682 | 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f}; | |
1683 | } | |
cb07fc2a SP |
1684 | |
1685 | image create bitmap file_plain -background white -foreground black -data { | |
1686 | #define plain_width 14 | |
1687 | #define plain_height 15 | |
1688 | static unsigned char plain_bits[] = { | |
1689 | 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10, | |
1690 | 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, | |
1691 | 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f}; | |
1692 | } -maskdata $filemask | |
1693 | ||
1694 | image create bitmap file_mod -background white -foreground blue -data { | |
1695 | #define mod_width 14 | |
1696 | #define mod_height 15 | |
1697 | static unsigned char mod_bits[] = { | |
1698 | 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10, | |
1699 | 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, | |
1700 | 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f}; | |
1701 | } -maskdata $filemask | |
1702 | ||
131f503b SP |
1703 | image create bitmap file_fulltick -background white -foreground "#007000" -data { |
1704 | #define file_fulltick_width 14 | |
1705 | #define file_fulltick_height 15 | |
1706 | static unsigned char file_fulltick_bits[] = { | |
cb07fc2a SP |
1707 | 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16, |
1708 | 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10, | |
1709 | 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f}; | |
1710 | } -maskdata $filemask | |
1711 | ||
1712 | image create bitmap file_parttick -background white -foreground "#005050" -data { | |
1713 | #define parttick_width 14 | |
1714 | #define parttick_height 15 | |
1715 | static unsigned char parttick_bits[] = { | |
1716 | 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10, | |
1717 | 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10, | |
1718 | 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f}; | |
1719 | } -maskdata $filemask | |
1720 | ||
1721 | image create bitmap file_question -background white -foreground black -data { | |
1722 | #define file_question_width 14 | |
1723 | #define file_question_height 15 | |
1724 | static unsigned char file_question_bits[] = { | |
1725 | 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13, | |
1726 | 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10, | |
1727 | 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f}; | |
1728 | } -maskdata $filemask | |
1729 | ||
1730 | image create bitmap file_removed -background white -foreground red -data { | |
1731 | #define file_removed_width 14 | |
1732 | #define file_removed_height 15 | |
1733 | static unsigned char file_removed_bits[] = { | |
1734 | 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10, | |
1735 | 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13, | |
1736 | 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f}; | |
1737 | } -maskdata $filemask | |
1738 | ||
1739 | image create bitmap file_merge -background white -foreground blue -data { | |
1740 | #define file_merge_width 14 | |
1741 | #define file_merge_height 15 | |
1742 | static unsigned char file_merge_bits[] = { | |
1743 | 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10, | |
1744 | 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, | |
1745 | 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f}; | |
1746 | } -maskdata $filemask | |
1747 | ||
e681cb7d GH |
1748 | image create bitmap file_statechange -background white -foreground green -data { |
1749 | #define file_merge_width 14 | |
1750 | #define file_merge_height 15 | |
1751 | static unsigned char file_statechange_bits[] = { | |
1752 | 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10, | |
1753 | 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, | |
1754 | 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f}; | |
1755 | } -maskdata $filemask | |
1756 | ||
6b292675 | 1757 | set ui_index .vpane.files.index.list |
0812665e | 1758 | set ui_workdir .vpane.files.workdir.list |
21e409ad SP |
1759 | |
1760 | set all_icons(_$ui_index) file_plain | |
1761 | set all_icons(A$ui_index) file_fulltick | |
1762 | set all_icons(M$ui_index) file_fulltick | |
1763 | set all_icons(D$ui_index) file_removed | |
1764 | set all_icons(U$ui_index) file_merge | |
e681cb7d | 1765 | set all_icons(T$ui_index) file_statechange |
21e409ad SP |
1766 | |
1767 | set all_icons(_$ui_workdir) file_plain | |
1768 | set all_icons(M$ui_workdir) file_mod | |
1769 | set all_icons(D$ui_workdir) file_question | |
3b4db3c1 | 1770 | set all_icons(U$ui_workdir) file_merge |
21e409ad | 1771 | set all_icons(O$ui_workdir) file_plain |
e681cb7d | 1772 | set all_icons(T$ui_workdir) file_statechange |
21e409ad | 1773 | |
131f503b | 1774 | set max_status_desc 0 |
cb07fc2a | 1775 | foreach i { |
1ac17950 CS |
1776 | {__ {mc "Unmodified"}} |
1777 | ||
1778 | {_M {mc "Modified, not staged"}} | |
1779 | {M_ {mc "Staged for commit"}} | |
1780 | {MM {mc "Portions staged for commit"}} | |
1781 | {MD {mc "Staged for commit, missing"}} | |
1782 | ||
e681cb7d GH |
1783 | {_T {mc "File type changed, not staged"}} |
1784 | {T_ {mc "File type changed, staged"}} | |
1785 | ||
1ac17950 CS |
1786 | {_O {mc "Untracked, not staged"}} |
1787 | {A_ {mc "Staged for commit"}} | |
1788 | {AM {mc "Portions staged for commit"}} | |
1789 | {AD {mc "Staged for commit, missing"}} | |
1790 | ||
1791 | {_D {mc "Missing"}} | |
1792 | {D_ {mc "Staged for removal"}} | |
1793 | {DO {mc "Staged for removal, still present"}} | |
1794 | ||
ff515d81 | 1795 | {_U {mc "Requires merge resolution"}} |
1ac17950 CS |
1796 | {U_ {mc "Requires merge resolution"}} |
1797 | {UU {mc "Requires merge resolution"}} | |
1798 | {UM {mc "Requires merge resolution"}} | |
1799 | {UD {mc "Requires merge resolution"}} | |
ff515d81 | 1800 | {UT {mc "Requires merge resolution"}} |
cb07fc2a | 1801 | } { |
1ac17950 CS |
1802 | set text [eval [lindex $i 1]] |
1803 | if {$max_status_desc < [string length $text]} { | |
1804 | set max_status_desc [string length $text] | |
131f503b | 1805 | } |
1ac17950 | 1806 | set all_descs([lindex $i 0]) $text |
cb07fc2a | 1807 | } |
21e409ad | 1808 | unset i |
cb07fc2a SP |
1809 | |
1810 | ###################################################################### | |
1811 | ## | |
1812 | ## util | |
1813 | ||
35874c16 SP |
1814 | proc scrollbar2many {list mode args} { |
1815 | foreach w $list {eval $w $mode $args} | |
1816 | } | |
1817 | ||
1818 | proc many2scrollbar {list mode sb top bottom} { | |
1819 | $sb set $top $bottom | |
1820 | foreach w $list {$w $mode moveto $top} | |
1821 | } | |
1822 | ||
b4946930 SP |
1823 | proc incr_font_size {font {amt 1}} { |
1824 | set sz [font configure $font -size] | |
1825 | incr sz $amt | |
1826 | font configure $font -size $sz | |
1827 | font configure ${font}bold -size $sz | |
debcd0fd | 1828 | font configure ${font}italic -size $sz |
b4946930 SP |
1829 | } |
1830 | ||
cb07fc2a SP |
1831 | ###################################################################### |
1832 | ## | |
1833 | ## ui commands | |
1834 | ||
1ac17950 | 1835 | set starting_gitk_msg [mc "Starting gitk... please wait..."] |
cc4b1c02 | 1836 | |
d0752429 | 1837 | proc do_gitk {revs} { |
20ddfcaa SP |
1838 | # -- Always start gitk through whatever we were loaded with. This |
1839 | # lets us bypass using shell process on Windows systems. | |
1840 | # | |
79317e5d | 1841 | set exe [_which gitk -script] |
02efd48f | 1842 | set cmd [list [info nameofexecutable] $exe] |
15430be5 AMS |
1843 | if {$exe eq {}} { |
1844 | error_popup [mc "Couldn't find gitk in PATH"] | |
cb07fc2a | 1845 | } else { |
501e4c6f SP |
1846 | global env |
1847 | ||
1848 | if {[info exists env(GIT_DIR)]} { | |
1849 | set old_GIT_DIR $env(GIT_DIR) | |
1850 | } else { | |
1851 | set old_GIT_DIR {} | |
1852 | } | |
1853 | ||
1854 | set pwd [pwd] | |
1855 | cd [file dirname [gitdir]] | |
1856 | set env(GIT_DIR) [file tail [gitdir]] | |
1857 | ||
02efd48f | 1858 | eval exec $cmd $revs & |
501e4c6f SP |
1859 | |
1860 | if {$old_GIT_DIR eq {}} { | |
1861 | unset env(GIT_DIR) | |
1862 | } else { | |
1863 | set env(GIT_DIR) $old_GIT_DIR | |
1864 | } | |
1865 | cd $pwd | |
1866 | ||
02efd48f | 1867 | ui_status $::starting_gitk_msg |
d0752429 | 1868 | after 10000 { |
699d5601 | 1869 | ui_ready $starting_gitk_msg |
d0752429 | 1870 | } |
cb07fc2a SP |
1871 | } |
1872 | } | |
1873 | ||
afd54240 PB |
1874 | proc do_explore {} { |
1875 | set explorer {} | |
1876 | if {[is_Cygwin] || [is_Windows]} { | |
1877 | set explorer "explorer.exe" | |
1878 | } elseif {[is_MacOSX]} { | |
1879 | set explorer "open" | |
1880 | } else { | |
1881 | # freedesktop.org-conforming system is our best shot | |
1882 | set explorer "xdg-open" | |
1883 | } | |
1884 | eval exec $explorer [file dirname [gitdir]] & | |
1885 | } | |
1886 | ||
b5834d70 | 1887 | set is_quitting 0 |
1e65c622 | 1888 | set ret_code 1 |
c4fe7728 | 1889 | |
1e65c622 AG |
1890 | proc terminate_me {win} { |
1891 | global ret_code | |
1892 | if {$win ne {.}} return | |
1893 | exit $ret_code | |
1894 | } | |
1895 | ||
1896 | proc do_quit {{rc {1}}} { | |
c950c66e | 1897 | global ui_comm is_quitting repo_config commit_type |
4578c5cb | 1898 | global GITGUI_BCK_exists GITGUI_BCK_i |
95b002ee | 1899 | global ui_comm_spell |
1e65c622 | 1900 | global ret_code |
c4fe7728 | 1901 | |
b5834d70 SP |
1902 | if {$is_quitting} return |
1903 | set is_quitting 1 | |
131f503b | 1904 | |
db7f34d4 SP |
1905 | if {[winfo exists $ui_comm]} { |
1906 | # -- Stash our current commit buffer. | |
1907 | # | |
1908 | set save [gitdir GITGUI_MSG] | |
4578c5cb SP |
1909 | if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} { |
1910 | file rename -force [gitdir GITGUI_BCK] $save | |
1911 | set GITGUI_BCK_exists 0 | |
db7f34d4 | 1912 | } else { |
4578c5cb SP |
1913 | set msg [string trim [$ui_comm get 0.0 end]] |
1914 | regsub -all -line {[ \r\t]+$} $msg {} msg | |
1915 | if {(![string match amend* $commit_type] | |
1916 | || [$ui_comm edit modified]) | |
1917 | && $msg ne {}} { | |
1918 | catch { | |
1919 | set fd [open $save w] | |
1920 | puts -nonewline $fd $msg | |
1921 | close $fd | |
1922 | } | |
1923 | } else { | |
1924 | catch {file delete $save} | |
1925 | } | |
1926 | } | |
1927 | ||
95b002ee SP |
1928 | # -- Cancel our spellchecker if its running. |
1929 | # | |
1930 | if {[info exists ui_comm_spell]} { | |
1931 | $ui_comm_spell stop | |
1932 | } | |
1933 | ||
4578c5cb SP |
1934 | # -- Remove our editor backup, its not needed. |
1935 | # | |
1936 | after cancel $GITGUI_BCK_i | |
1937 | if {$GITGUI_BCK_exists} { | |
1938 | catch {file delete [gitdir GITGUI_BCK]} | |
131f503b | 1939 | } |
131f503b | 1940 | |
db7f34d4 SP |
1941 | # -- Stash our current window geometry into this repository. |
1942 | # | |
1943 | set cfg_geometry [list] | |
1944 | lappend cfg_geometry [wm geometry .] | |
a0592d3f JS |
1945 | lappend cfg_geometry [lindex [.vpane sash coord 0] 0] |
1946 | lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1] | |
db7f34d4 SP |
1947 | if {[catch {set rc_geometry $repo_config(gui.geometry)}]} { |
1948 | set rc_geometry {} | |
1949 | } | |
1950 | if {$cfg_geometry ne $rc_geometry} { | |
81347223 | 1951 | catch {git config gui.geometry $cfg_geometry} |
db7f34d4 | 1952 | } |
51f4d16b SP |
1953 | } |
1954 | ||
1e65c622 | 1955 | set ret_code $rc |
cb07fc2a SP |
1956 | destroy . |
1957 | } | |
1958 | ||
1959 | proc do_rescan {} { | |
699d5601 | 1960 | rescan ui_ready |
cb07fc2a SP |
1961 | } |
1962 | ||
8056cc4f AG |
1963 | proc ui_do_rescan {} { |
1964 | rescan {force_first_diff; ui_ready} | |
1965 | } | |
1966 | ||
6e27d826 | 1967 | proc do_commit {} { |
ec6b424a | 1968 | commit_tree |
6e27d826 SP |
1969 | } |
1970 | ||
8a965b8e AMS |
1971 | proc next_diff {} { |
1972 | global next_diff_p next_diff_w next_diff_i | |
29853b90 AG |
1973 | show_diff $next_diff_p $next_diff_w {} |
1974 | } | |
1975 | ||
1976 | proc find_anchor_pos {lst name} { | |
1977 | set lid [lsearch -sorted -exact $lst $name] | |
1978 | ||
1979 | if {$lid == -1} { | |
1980 | set lid 0 | |
1981 | foreach lname $lst { | |
1982 | if {$lname >= $name} break | |
1983 | incr lid | |
1984 | } | |
1985 | } | |
1986 | ||
1987 | return $lid | |
1988 | } | |
1989 | ||
1990 | proc find_file_from {flist idx delta path mmask} { | |
1991 | global file_states | |
1992 | ||
1993 | set len [llength $flist] | |
1994 | while {$idx >= 0 && $idx < $len} { | |
1995 | set name [lindex $flist $idx] | |
1996 | ||
1997 | if {$name ne $path && [info exists file_states($name)]} { | |
1998 | set state [lindex $file_states($name) 0] | |
1999 | ||
2000 | if {$mmask eq {} || [regexp $mmask $state]} { | |
2001 | return $idx | |
2002 | } | |
2003 | } | |
2004 | ||
2005 | incr idx $delta | |
2006 | } | |
2007 | ||
2008 | return {} | |
2009 | } | |
2010 | ||
2011 | proc find_next_diff {w path {lno {}} {mmask {}}} { | |
2012 | global next_diff_p next_diff_w next_diff_i | |
2013 | global file_lists ui_index ui_workdir | |
2014 | ||
2015 | set flist $file_lists($w) | |
2016 | if {$lno eq {}} { | |
2017 | set lno [find_anchor_pos $flist $path] | |
2018 | } else { | |
2019 | incr lno -1 | |
2020 | } | |
2021 | ||
2022 | if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} { | |
2023 | if {$w eq $ui_index} { | |
2024 | set mmask "^$mmask" | |
2025 | } else { | |
2026 | set mmask "$mmask\$" | |
2027 | } | |
2028 | } | |
2029 | ||
2030 | set idx [find_file_from $flist $lno 1 $path $mmask] | |
2031 | if {$idx eq {}} { | |
2032 | incr lno -1 | |
2033 | set idx [find_file_from $flist $lno -1 $path $mmask] | |
2034 | } | |
2035 | ||
2036 | if {$idx ne {}} { | |
2037 | set next_diff_w $w | |
2038 | set next_diff_p [lindex $flist $idx] | |
2039 | set next_diff_i [expr {$idx+1}] | |
2040 | return 1 | |
2041 | } else { | |
2042 | return 0 | |
2043 | } | |
2044 | } | |
2045 | ||
2046 | proc next_diff_after_action {w path {lno {}} {mmask {}}} { | |
2047 | global current_diff_path | |
2048 | ||
2049 | if {$path ne $current_diff_path} { | |
2050 | return {} | |
2051 | } elseif {[find_next_diff $w $path $lno $mmask]} { | |
2052 | return {next_diff;} | |
2053 | } else { | |
2054 | return {reshow_diff;} | |
2055 | } | |
2056 | } | |
2057 | ||
2058 | proc select_first_diff {} { | |
2059 | global ui_workdir | |
2060 | ||
2061 | if {[find_next_diff $ui_workdir {} 1 {^_?U}] || | |
2062 | [find_next_diff $ui_workdir {} 1 {[^O]$}]} { | |
2063 | next_diff | |
2064 | } | |
8a965b8e AMS |
2065 | } |
2066 | ||
8056cc4f AG |
2067 | proc force_first_diff {} { |
2068 | global current_diff_path | |
2069 | ||
2070 | if {[info exists file_states($current_diff_path)]} { | |
2071 | set state [lindex $file_states($current_diff_path) 0] | |
2072 | ||
2073 | if {[string index $state 1] ne {O}} return | |
2074 | } | |
2075 | ||
2076 | select_first_diff | |
2077 | } | |
2078 | ||
24263b77 | 2079 | proc toggle_or_diff {w x y} { |
20a53c02 | 2080 | global file_states file_lists current_diff_path ui_index ui_workdir |
24263b77 | 2081 | global last_clicked selected_paths |
131f503b | 2082 | |
cb07fc2a SP |
2083 | set pos [split [$w index @$x,$y] .] |
2084 | set lno [lindex $pos 0] | |
2085 | set col [lindex $pos 1] | |
24263b77 SP |
2086 | set path [lindex $file_lists($w) [expr {$lno - 1}]] |
2087 | if {$path eq {}} { | |
2088 | set last_clicked {} | |
2089 | return | |
2090 | } | |
2091 | ||
2092 | set last_clicked [list $w $lno] | |
2093 | array unset selected_paths | |
2094 | $ui_index tag remove in_sel 0.0 end | |
0812665e | 2095 | $ui_workdir tag remove in_sel 0.0 end |
cb07fc2a | 2096 | |
3e34838c | 2097 | # Determine the state of the file |
617ceee6 AG |
2098 | if {[info exists file_states($path)]} { |
2099 | set state [lindex $file_states($path) 0] | |
8056cc4f AG |
2100 | } else { |
2101 | set state {__} | |
2102 | } | |
2103 | ||
8056cc4f | 2104 | # Restage the file, or simply show the diff |
cead78ed | 2105 | if {$col == 0 && $y > 1} { |
3e34838c AG |
2106 | # Conflicts need special handling |
2107 | if {[string first {U} $state] >= 0} { | |
0aea2842 AG |
2108 | # $w must always be $ui_workdir, but... |
2109 | if {$w ne $ui_workdir} { set lno {} } | |
2110 | merge_stage_workdir $path $lno | |
3e34838c AG |
2111 | return |
2112 | } | |
2113 | ||
8056cc4f AG |
2114 | if {[string index $state 1] eq {O}} { |
2115 | set mmask {} | |
2116 | } else { | |
2117 | set mmask {[^O]} | |
2118 | } | |
2119 | ||
2120 | set after [next_diff_after_action $w $path $lno $mmask] | |
8a965b8e | 2121 | |
de5f6d5d | 2122 | if {$w eq $ui_index} { |
74d18d2e | 2123 | update_indexinfo \ |
93e912c5 | 2124 | "Unstaging [short_path $path] from commit" \ |
74d18d2e | 2125 | [list $path] \ |
699d5601 | 2126 | [concat $after [list ui_ready]] |
de5f6d5d | 2127 | } elseif {$w eq $ui_workdir} { |
74d18d2e | 2128 | update_index \ |
4d583c86 | 2129 | "Adding [short_path $path]" \ |
74d18d2e | 2130 | [list $path] \ |
699d5601 | 2131 | [concat $after [list ui_ready]] |
74d18d2e | 2132 | } |
24263b77 | 2133 | } else { |
03e4ec53 | 2134 | show_diff $path $w $lno |
cb07fc2a SP |
2135 | } |
2136 | } | |
2137 | ||
24263b77 | 2138 | proc add_one_to_selection {w x y} { |
833eda73 | 2139 | global file_lists last_clicked selected_paths |
7f1df79b | 2140 | |
833eda73 | 2141 | set lno [lindex [split [$w index @$x,$y] .] 0] |
24263b77 SP |
2142 | set path [lindex $file_lists($w) [expr {$lno - 1}]] |
2143 | if {$path eq {}} { | |
2144 | set last_clicked {} | |
2145 | return | |
2146 | } | |
cb07fc2a | 2147 | |
833eda73 SP |
2148 | if {$last_clicked ne {} |
2149 | && [lindex $last_clicked 0] ne $w} { | |
2150 | array unset selected_paths | |
2151 | [lindex $last_clicked 0] tag remove in_sel 0.0 end | |
2152 | } | |
2153 | ||
24263b77 SP |
2154 | set last_clicked [list $w $lno] |
2155 | if {[catch {set in_sel $selected_paths($path)}]} { | |
2156 | set in_sel 0 | |
2157 | } | |
2158 | if {$in_sel} { | |
2159 | unset selected_paths($path) | |
2160 | $w tag remove in_sel $lno.0 [expr {$lno + 1}].0 | |
2161 | } else { | |
2162 | set selected_paths($path) 1 | |
2163 | $w tag add in_sel $lno.0 [expr {$lno + 1}].0 | |
2164 | } | |
2165 | } | |
2166 | ||
2167 | proc add_range_to_selection {w x y} { | |
833eda73 | 2168 | global file_lists last_clicked selected_paths |
24263b77 SP |
2169 | |
2170 | if {[lindex $last_clicked 0] ne $w} { | |
2171 | toggle_or_diff $w $x $y | |
2172 | return | |
cb07fc2a | 2173 | } |
24263b77 | 2174 | |
833eda73 | 2175 | set lno [lindex [split [$w index @$x,$y] .] 0] |
24263b77 SP |
2176 | set lc [lindex $last_clicked 1] |
2177 | if {$lc < $lno} { | |
2178 | set begin $lc | |
2179 | set end $lno | |
2180 | } else { | |
2181 | set begin $lno | |
2182 | set end $lc | |
2183 | } | |
2184 | ||
2185 | foreach path [lrange $file_lists($w) \ | |
2186 | [expr {$begin - 1}] \ | |
2187 | [expr {$end - 1}]] { | |
2188 | set selected_paths($path) 1 | |
2189 | } | |
2190 | $w tag add in_sel $begin.0 [expr {$end + 1}].0 | |
cb07fc2a SP |
2191 | } |
2192 | ||
c91ee2bd JS |
2193 | proc show_more_context {} { |
2194 | global repo_config | |
2195 | if {$repo_config(gui.diffcontext) < 99} { | |
2196 | incr repo_config(gui.diffcontext) | |
2197 | reshow_diff | |
2198 | } | |
2199 | } | |
2200 | ||
2201 | proc show_less_context {} { | |
2202 | global repo_config | |
55ba8a34 | 2203 | if {$repo_config(gui.diffcontext) > 1} { |
c91ee2bd JS |
2204 | incr repo_config(gui.diffcontext) -1 |
2205 | reshow_diff | |
2206 | } | |
2207 | } | |
2208 | ||
cb07fc2a SP |
2209 | ###################################################################### |
2210 | ## | |
a4bee597 | 2211 | ## ui construction |
db453781 | 2212 | |
6bbd1cb9 | 2213 | load_config 0 |
92148d80 | 2214 | apply_config |
2ebba528 SP |
2215 | set ui_comm {} |
2216 | ||
cb07fc2a | 2217 | # -- Menu Bar |
a49c67d1 | 2218 | # |
b4946930 | 2219 | menu .mbar -tearoff 0 |
1ac17950 CS |
2220 | .mbar add cascade -label [mc Repository] -menu .mbar.repository |
2221 | .mbar add cascade -label [mc Edit] -menu .mbar.edit | |
64a906f8 | 2222 | if {[is_enabled branch]} { |
1ac17950 | 2223 | .mbar add cascade -label [mc Branch] -menu .mbar.branch |
700a65ce | 2224 | } |
2ebba528 | 2225 | if {[is_enabled multicommit] || [is_enabled singlecommit]} { |
a9813cb5 | 2226 | .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit |
2ebba528 | 2227 | } |
64a906f8 | 2228 | if {[is_enabled transport]} { |
1ac17950 | 2229 | .mbar add cascade -label [mc Merge] -menu .mbar.merge |
6bdf5e5f | 2230 | .mbar add cascade -label [mc Remote] -menu .mbar.remote |
4ccdab02 | 2231 | } |
cb07fc2a SP |
2232 | . configure -menu .mbar |
2233 | ||
a4abfa62 | 2234 | # -- Repository Menu |
a49c67d1 | 2235 | # |
a4abfa62 | 2236 | menu .mbar.repository |
35874c16 | 2237 | |
afd54240 PB |
2238 | .mbar.repository add command \ |
2239 | -label [mc "Explore Working Copy"] \ | |
2240 | -command {do_explore} | |
2241 | .mbar.repository add separator | |
2242 | ||
35874c16 | 2243 | .mbar.repository add command \ |
1ac17950 | 2244 | -label [mc "Browse Current Branch's Files"] \ |
c74b6c66 | 2245 | -command {browser::new $current_branch} |
a8139888 | 2246 | set ui_browse_current [.mbar.repository index last] |
8e891fac | 2247 | .mbar.repository add command \ |
1ac17950 | 2248 | -label [mc "Browse Branch Files..."] \ |
8e891fac | 2249 | -command browser_open::dialog |
35874c16 SP |
2250 | .mbar.repository add separator |
2251 | ||
d0752429 | 2252 | .mbar.repository add command \ |
1ac17950 | 2253 | -label [mc "Visualize Current Branch's History"] \ |
7416bbc6 | 2254 | -command {do_gitk $current_branch} |
a8139888 | 2255 | set ui_visualize_current [.mbar.repository index last] |
5753ef1a | 2256 | .mbar.repository add command \ |
1ac17950 | 2257 | -label [mc "Visualize All Branch History"] \ |
7416bbc6 | 2258 | -command {do_gitk --all} |
d0752429 | 2259 | .mbar.repository add separator |
75e355d6 | 2260 | |
a8139888 SP |
2261 | proc current_branch_write {args} { |
2262 | global current_branch | |
2263 | .mbar.repository entryconf $::ui_browse_current \ | |
1ac17950 | 2264 | -label [mc "Browse %s's Files" $current_branch] |
a8139888 | 2265 | .mbar.repository entryconf $::ui_visualize_current \ |
1ac17950 | 2266 | -label [mc "Visualize %s's History" $current_branch] |
a8139888 SP |
2267 | } |
2268 | trace add variable current_branch write current_branch_write | |
2269 | ||
cf25ddc8 | 2270 | if {[is_enabled multicommit]} { |
1ac17950 | 2271 | .mbar.repository add command -label [mc "Database Statistics"] \ |
7416bbc6 | 2272 | -command do_stats |
0fd49d0a | 2273 | |
1ac17950 | 2274 | .mbar.repository add command -label [mc "Compress Database"] \ |
7416bbc6 | 2275 | -command do_gc |
4aca740b | 2276 | |
1ac17950 | 2277 | .mbar.repository add command -label [mc "Verify Database"] \ |
7416bbc6 | 2278 | -command do_fsck_objects |
444f92d0 | 2279 | |
a4abfa62 | 2280 | .mbar.repository add separator |
75e355d6 | 2281 | |
20ddfcaa SP |
2282 | if {[is_Cygwin]} { |
2283 | .mbar.repository add command \ | |
1ac17950 | 2284 | -label [mc "Create Desktop Icon"] \ |
7416bbc6 | 2285 | -command do_cygwin_shortcut |
20ddfcaa | 2286 | } elseif {[is_Windows]} { |
a4abfa62 | 2287 | .mbar.repository add command \ |
1ac17950 | 2288 | -label [mc "Create Desktop Icon"] \ |
7416bbc6 | 2289 | -command do_windows_shortcut |
06c31115 | 2290 | } elseif {[is_MacOSX]} { |
a4abfa62 | 2291 | .mbar.repository add command \ |
1ac17950 | 2292 | -label [mc "Create Desktop Icon"] \ |
7416bbc6 | 2293 | -command do_macosx_app |
4aca740b | 2294 | } |
4ccdab02 | 2295 | } |
85ab313e | 2296 | |
af894943 SF |
2297 | if {[is_MacOSX]} { |
2298 | proc ::tk::mac::Quit {args} { do_quit } | |
2299 | } else { | |
2300 | .mbar.repository add command -label [mc Quit] \ | |
2301 | -command do_quit \ | |
2302 | -accelerator $M1T-Q | |
2303 | } | |
cb07fc2a | 2304 | |
9861671d SP |
2305 | # -- Edit Menu |
2306 | # | |
2307 | menu .mbar.edit | |
1ac17950 | 2308 | .mbar.edit add command -label [mc Undo] \ |
9861671d | 2309 | -command {catch {[focus] edit undo}} \ |
7416bbc6 | 2310 | -accelerator $M1T-Z |
1ac17950 | 2311 | .mbar.edit add command -label [mc Redo] \ |
9861671d | 2312 | -command {catch {[focus] edit redo}} \ |
7416bbc6 | 2313 | -accelerator $M1T-Y |
9861671d | 2314 | .mbar.edit add separator |
1ac17950 | 2315 | .mbar.edit add command -label [mc Cut] \ |
9861671d | 2316 | -command {catch {tk_textCut [focus]}} \ |
7416bbc6 | 2317 | -accelerator $M1T-X |
1ac17950 | 2318 | .mbar.edit add command -label [mc Copy] \ |
9861671d | 2319 | -command {catch {tk_textCopy [focus]}} \ |
7416bbc6 | 2320 | -accelerator $M1T-C |
1ac17950 | 2321 | .mbar.edit add command -label [mc Paste] \ |
9861671d | 2322 | -command {catch {tk_textPaste [focus]; [focus] see insert}} \ |
7416bbc6 | 2323 | -accelerator $M1T-V |
1ac17950 | 2324 | .mbar.edit add command -label [mc Delete] \ |
9861671d | 2325 | -command {catch {[focus] delete sel.first sel.last}} \ |
7416bbc6 | 2326 | -accelerator Del |
9861671d | 2327 | .mbar.edit add separator |
1ac17950 | 2328 | .mbar.edit add command -label [mc "Select All"] \ |
9861671d | 2329 | -command {catch {[focus] tag add sel 0.0 end}} \ |
7416bbc6 | 2330 | -accelerator $M1T-A |
9861671d | 2331 | |
85ab313e SP |
2332 | # -- Branch Menu |
2333 | # | |
64a906f8 | 2334 | if {[is_enabled branch]} { |
700a65ce SP |
2335 | menu .mbar.branch |
2336 | ||
1ac17950 | 2337 | .mbar.branch add command -label [mc "Create..."] \ |
b1fa2bff | 2338 | -command branch_create::dialog \ |
7416bbc6 | 2339 | -accelerator $M1T-N |
700a65ce SP |
2340 | lappend disable_on_lock [list .mbar.branch entryconf \ |
2341 | [.mbar.branch index last] -state] | |
2342 | ||
1ac17950 | 2343 | .mbar.branch add command -label [mc "Checkout..."] \ |
d41b43eb SP |
2344 | -command branch_checkout::dialog \ |
2345 | -accelerator $M1T-O | |
2346 | lappend disable_on_lock [list .mbar.branch entryconf \ | |
2347 | [.mbar.branch index last] -state] | |
2348 | ||
1ac17950 | 2349 | .mbar.branch add command -label [mc "Rename..."] \ |
61f82ce7 SP |
2350 | -command branch_rename::dialog |
2351 | lappend disable_on_lock [list .mbar.branch entryconf \ | |
2352 | [.mbar.branch index last] -state] | |
2353 | ||
1ac17950 | 2354 | .mbar.branch add command -label [mc "Delete..."] \ |
3206c63d | 2355 | -command branch_delete::dialog |
700a65ce SP |
2356 | lappend disable_on_lock [list .mbar.branch entryconf \ |
2357 | [.mbar.branch index last] -state] | |
fd234dfd | 2358 | |
1ac17950 | 2359 | .mbar.branch add command -label [mc "Reset..."] \ |
a6c9b081 | 2360 | -command merge::reset_hard |
fd234dfd SP |
2361 | lappend disable_on_lock [list .mbar.branch entryconf \ |
2362 | [.mbar.branch index last] -state] | |
700a65ce SP |
2363 | } |
2364 | ||
cb07fc2a | 2365 | # -- Commit Menu |
a49c67d1 | 2366 | # |
1e65c622 AG |
2367 | proc commit_btn_caption {} { |
2368 | if {[is_enabled nocommit]} { | |
2369 | return [mc "Done"] | |
2370 | } else { | |
2371 | return [mc Commit@@verb] | |
2372 | } | |
2373 | } | |
2374 | ||
2ebba528 SP |
2375 | if {[is_enabled multicommit] || [is_enabled singlecommit]} { |
2376 | menu .mbar.commit | |
2377 | ||
1e02b32e SP |
2378 | if {![is_enabled nocommit]} { |
2379 | .mbar.commit add radiobutton \ | |
2380 | -label [mc "New Commit"] \ | |
2381 | -command do_select_commit_type \ | |
2382 | -variable selected_commit_type \ | |
2383 | -value new | |
2384 | lappend disable_on_lock \ | |
2385 | [list .mbar.commit entryconf [.mbar.commit index last] -state] | |
2386 | ||
2387 | .mbar.commit add radiobutton \ | |
2388 | -label [mc "Amend Last Commit"] \ | |
2389 | -command do_select_commit_type \ | |
2390 | -variable selected_commit_type \ | |
2391 | -value amend | |
2392 | lappend disable_on_lock \ | |
2393 | [list .mbar.commit entryconf [.mbar.commit index last] -state] | |
2394 | ||
2395 | .mbar.commit add separator | |
2396 | } | |
24ac9b75 | 2397 | |
1ac17950 | 2398 | .mbar.commit add command -label [mc Rescan] \ |
8056cc4f | 2399 | -command ui_do_rescan \ |
7416bbc6 | 2400 | -accelerator F5 |
2ebba528 SP |
2401 | lappend disable_on_lock \ |
2402 | [list .mbar.commit entryconf [.mbar.commit index last] -state] | |
24ac9b75 | 2403 | |
1ac17950 | 2404 | .mbar.commit add command -label [mc "Stage To Commit"] \ |
cd16a6c9 SP |
2405 | -command do_add_selection \ |
2406 | -accelerator $M1T-T | |
2ebba528 SP |
2407 | lappend disable_on_lock \ |
2408 | [list .mbar.commit entryconf [.mbar.commit index last] -state] | |
24ac9b75 | 2409 | |
1ac17950 | 2410 | .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \ |
2ebba528 | 2411 | -command do_add_all \ |
7416bbc6 | 2412 | -accelerator $M1T-I |
2ebba528 SP |
2413 | lappend disable_on_lock \ |
2414 | [list .mbar.commit entryconf [.mbar.commit index last] -state] | |
24ac9b75 | 2415 | |
1ac17950 | 2416 | .mbar.commit add command -label [mc "Unstage From Commit"] \ |
7416bbc6 | 2417 | -command do_unstage_selection |
2ebba528 SP |
2418 | lappend disable_on_lock \ |
2419 | [list .mbar.commit entryconf [.mbar.commit index last] -state] | |
e734817d | 2420 | |
1ac17950 | 2421 | .mbar.commit add command -label [mc "Revert Changes"] \ |
7416bbc6 | 2422 | -command do_revert_selection |
2ebba528 SP |
2423 | lappend disable_on_lock \ |
2424 | [list .mbar.commit entryconf [.mbar.commit index last] -state] | |
e734817d | 2425 | |
2ebba528 | 2426 | .mbar.commit add separator |
1461c5f3 | 2427 | |
c91ee2bd JS |
2428 | .mbar.commit add command -label [mc "Show Less Context"] \ |
2429 | -command show_less_context \ | |
729ffa50 | 2430 | -accelerator $M1T-\- |
c91ee2bd JS |
2431 | |
2432 | .mbar.commit add command -label [mc "Show More Context"] \ | |
2433 | -command show_more_context \ | |
729ffa50 | 2434 | -accelerator $M1T-= |
c91ee2bd JS |
2435 | |
2436 | .mbar.commit add separator | |
2437 | ||
ed70e4d7 | 2438 | if {![is_enabled nocommitmsg]} { |
1e02b32e SP |
2439 | .mbar.commit add command -label [mc "Sign Off"] \ |
2440 | -command do_signoff \ | |
2441 | -accelerator $M1T-S | |
2442 | } | |
24ac9b75 | 2443 | |
1e65c622 | 2444 | .mbar.commit add command -label [commit_btn_caption] \ |
2ebba528 | 2445 | -command do_commit \ |
7416bbc6 | 2446 | -accelerator $M1T-Return |
2ebba528 SP |
2447 | lappend disable_on_lock \ |
2448 | [list .mbar.commit entryconf [.mbar.commit index last] -state] | |
2449 | } | |
cb07fc2a | 2450 | |
9b28a8b9 SP |
2451 | # -- Merge Menu |
2452 | # | |
2453 | if {[is_enabled branch]} { | |
2454 | menu .mbar.merge | |
1ac17950 | 2455 | .mbar.merge add command -label [mc "Local Merge..."] \ |
a870ddc0 SP |
2456 | -command merge::dialog \ |
2457 | -accelerator $M1T-M | |
9b28a8b9 SP |
2458 | lappend disable_on_lock \ |
2459 | [list .mbar.merge entryconf [.mbar.merge index last] -state] | |
1ac17950 | 2460 | .mbar.merge add command -label [mc "Abort Merge..."] \ |
a6c9b081 | 2461 | -command merge::reset_hard |
9b28a8b9 SP |
2462 | lappend disable_on_lock \ |
2463 | [list .mbar.merge entryconf [.mbar.merge index last] -state] | |
9b28a8b9 SP |
2464 | } |
2465 | ||
2466 | # -- Transport Menu | |
2467 | # | |
2468 | if {[is_enabled transport]} { | |
6bdf5e5f | 2469 | menu .mbar.remote |
9b28a8b9 | 2470 | |
ba6485e0 PB |
2471 | .mbar.remote add command \ |
2472 | -label [mc "Add..."] \ | |
2473 | -command remote_add::dialog \ | |
2474 | -accelerator $M1T-A | |
6bdf5e5f SP |
2475 | .mbar.remote add command \ |
2476 | -label [mc "Push..."] \ | |
840bcfa7 SP |
2477 | -command do_push_anywhere \ |
2478 | -accelerator $M1T-P | |
6bdf5e5f | 2479 | .mbar.remote add command \ |
3c1c2a00 | 2480 | -label [mc "Delete Branch..."] \ |
aa252f19 | 2481 | -command remote_branch_delete::dialog |
9b28a8b9 SP |
2482 | } |
2483 | ||
0c8d7839 SP |
2484 | if {[is_MacOSX]} { |
2485 | # -- Apple Menu (Mac OS X only) | |
2486 | # | |
442b3caa | 2487 | .mbar add cascade -label Apple -menu .mbar.apple |
0c8d7839 SP |
2488 | menu .mbar.apple |
2489 | ||
1ac17950 | 2490 | .mbar.apple add command -label [mc "About %s" [appname]] \ |
7416bbc6 | 2491 | -command do_about |
13824e2d SP |
2492 | .mbar.apple add separator |
2493 | .mbar.apple add command \ | |
2494 | -label [mc "Preferences..."] \ | |
2495 | -command do_options \ | |
2496 | -accelerator $M1T-, | |
2497 | bind . <$M1B-,> do_options | |
0c8d7839 SP |
2498 | } else { |
2499 | # -- Edit Menu | |
2500 | # | |
2501 | .mbar.edit add separator | |
1ac17950 | 2502 | .mbar.edit add command -label [mc "Options..."] \ |
7416bbc6 | 2503 | -command do_options |
273984fc | 2504 | } |
557afe82 | 2505 | |
273984fc SP |
2506 | # -- Help Menu |
2507 | # | |
1ac17950 | 2508 | .mbar add cascade -label [mc Help] -menu .mbar.help |
273984fc | 2509 | menu .mbar.help |
0c8d7839 | 2510 | |
273984fc | 2511 | if {![is_MacOSX]} { |
1ac17950 | 2512 | .mbar.help add command -label [mc "About %s" [appname]] \ |
7416bbc6 | 2513 | -command do_about |
0c8d7839 | 2514 | } |
82aa2354 | 2515 | |
2db21e70 | 2516 | |
20ddfcaa | 2517 | set doc_path [file dirname [gitexec]] |
273984fc SP |
2518 | set doc_path [file join $doc_path Documentation index.html] |
2519 | ||
20ddfcaa | 2520 | if {[is_Cygwin]} { |
ee405993 | 2521 | set doc_path [exec cygpath --mixed $doc_path] |
273984fc SP |
2522 | } |
2523 | ||
273984fc SP |
2524 | if {[file isfile $doc_path]} { |
2525 | set doc_url "file:$doc_path" | |
2526 | } else { | |
2527 | set doc_url {http://www.kernel.org/pub/software/scm/git/docs/} | |
2528 | } | |
2529 | ||
2db21e70 PB |
2530 | proc start_browser {url} { |
2531 | git "web--browse" $url | |
273984fc | 2532 | } |
2db21e70 PB |
2533 | |
2534 | .mbar.help add command -label [mc "Online Documentation"] \ | |
2535 | -command [list start_browser $doc_url] | |
2536 | unset doc_path doc_url | |
82aa2354 | 2537 | |
2ebba528 SP |
2538 | # -- Standard bindings |
2539 | # | |
39fa2a98 | 2540 | wm protocol . WM_DELETE_WINDOW do_quit |
2ebba528 SP |
2541 | bind all <$M1B-Key-q> do_quit |
2542 | bind all <$M1B-Key-Q> do_quit | |
2543 | bind all <$M1B-Key-w> {destroy [winfo toplevel %W]} | |
2544 | bind all <$M1B-Key-W> {destroy [winfo toplevel %W]} | |
2545 | ||
3e45ee1e SP |
2546 | set subcommand_args {} |
2547 | proc usage {} { | |
2548 | puts stderr "usage: $::argv0 $::subcommand $::subcommand_args" | |
2549 | exit 1 | |
2550 | } | |
2551 | ||
2ebba528 SP |
2552 | # -- Not a normal commit type invocation? Do that instead! |
2553 | # | |
258871d3 | 2554 | switch -- $subcommand { |
85d2d597 | 2555 | browser - |
2ebba528 | 2556 | blame { |
f7078b40 AG |
2557 | if {$subcommand eq "blame"} { |
2558 | set subcommand_args {[--line=<num>] rev? path} | |
2559 | } else { | |
2560 | set subcommand_args {rev? path} | |
2561 | } | |
c52c9452 | 2562 | if {$argv eq {}} usage |
a0db0d61 | 2563 | set head {} |
3e45ee1e | 2564 | set path {} |
f7078b40 | 2565 | set jump_spec {} |
3e45ee1e SP |
2566 | set is_path 0 |
2567 | foreach a $argv { | |
2568 | if {$is_path || [file exists $_prefix$a]} { | |
2569 | if {$path ne {}} usage | |
6b3d8b97 | 2570 | set path $_prefix$a |
3e45ee1e SP |
2571 | break |
2572 | } elseif {$a eq {--}} { | |
2573 | if {$path ne {}} { | |
a0db0d61 SP |
2574 | if {$head ne {}} usage |
2575 | set head $path | |
3e45ee1e SP |
2576 | set path {} |
2577 | } | |
2578 | set is_path 1 | |
f7078b40 AG |
2579 | } elseif {[regexp {^--line=(\d+)$} $a a lnum]} { |
2580 | if {$jump_spec ne {} || $head ne {}} usage | |
2581 | set jump_spec [list $lnum] | |
a0db0d61 SP |
2582 | } elseif {$head eq {}} { |
2583 | if {$head ne {}} usage | |
2584 | set head $a | |
c52c9452 | 2585 | set is_path 1 |
3e45ee1e SP |
2586 | } else { |
2587 | usage | |
2588 | } | |
2589 | } | |
2590 | unset is_path | |
2591 | ||
c52c9452 SP |
2592 | if {$head ne {} && $path eq {}} { |
2593 | set path $_prefix$head | |
2594 | set head {} | |
2595 | } | |
2596 | ||
a0db0d61 | 2597 | if {$head eq {}} { |
d41b43eb | 2598 | load_current_branch |
a0db0d61 | 2599 | } else { |
02087abc SP |
2600 | if {[regexp {^[0-9a-f]{1,39}$} $head]} { |
2601 | if {[catch { | |
2602 | set head [git rev-parse --verify $head] | |
2603 | } err]} { | |
2604 | puts stderr $err | |
2605 | exit 1 | |
2606 | } | |
2607 | } | |
a0db0d61 | 2608 | set current_branch $head |
2ebba528 | 2609 | } |
a0db0d61 | 2610 | |
85d2d597 SP |
2611 | switch -- $subcommand { |
2612 | browser { | |
f7078b40 | 2613 | if {$jump_spec ne {}} usage |
85d2d597 SP |
2614 | if {$head eq {}} { |
2615 | if {$path ne {} && [file isdirectory $path]} { | |
2616 | set head $current_branch | |
2617 | } else { | |
2618 | set head $path | |
2619 | set path {} | |
2620 | } | |
2621 | } | |
2622 | browser::new $head $path | |
2623 | } | |
2624 | blame { | |
2625 | if {$head eq {} && ![file exists $path]} { | |
c8c4854b | 2626 | puts stderr [mc "fatal: cannot stat path %s: No such file or directory" $path] |
85d2d597 SP |
2627 | exit 1 |
2628 | } | |
f7078b40 | 2629 | blame::new $head $path $jump_spec |
85d2d597 | 2630 | } |
c52c9452 | 2631 | } |
258871d3 SP |
2632 | return |
2633 | } | |
2634 | citool - | |
2635 | gui { | |
2636 | if {[llength $argv] != 0} { | |
2637 | puts -nonewline stderr "usage: $argv0" | |
0b2bc460 SP |
2638 | if {$subcommand ne {gui} |
2639 | && [file tail $argv0] ne "git-$subcommand"} { | |
258871d3 SP |
2640 | puts -nonewline stderr " $subcommand" |
2641 | } | |
2642 | puts stderr {} | |
2643 | exit 1 | |
2644 | } | |
2645 | # fall through to setup UI for commits | |
2ebba528 | 2646 | } |
2ebba528 | 2647 | default { |
c0f7a6c3 | 2648 | puts stderr "usage: $argv0 \[{blame|browser|citool}\]" |
2ebba528 SP |
2649 | exit 1 |
2650 | } | |
2651 | } | |
2652 | ||
8553b772 SP |
2653 | # -- Branch Control |
2654 | # | |
2655 | frame .branch \ | |
2656 | -borderwidth 1 \ | |
2657 | -relief sunken | |
2658 | label .branch.l1 \ | |
1ac17950 | 2659 | -text [mc "Current Branch:"] \ |
8553b772 | 2660 | -anchor w \ |
7416bbc6 | 2661 | -justify left |
8553b772 SP |
2662 | label .branch.cb \ |
2663 | -textvariable current_branch \ | |
2664 | -anchor w \ | |
7416bbc6 | 2665 | -justify left |
8553b772 SP |
2666 | pack .branch.l1 -side left |
2667 | pack .branch.cb -side left -fill x | |
2668 | pack .branch -side top -fill x | |
2669 | ||
cb07fc2a | 2670 | # -- Main Window Layout |
a49c67d1 | 2671 | # |
a0592d3f JS |
2672 | panedwindow .vpane -orient horizontal |
2673 | panedwindow .vpane.files -orient vertical | |
c5a1eb88 | 2674 | .vpane add .vpane.files -sticky nsew -height 100 -width 200 |
cb07fc2a SP |
2675 | pack .vpane -anchor n -side top -fill both -expand 1 |
2676 | ||
2677 | # -- Index File List | |
a49c67d1 | 2678 | # |
c5a1eb88 | 2679 | frame .vpane.files.index -height 100 -width 200 |
c73ce762 | 2680 | label .vpane.files.index.title -text [mc "Staged Changes (Will Commit)"] \ |
c382fdd7 PH |
2681 | -background lightgreen -foreground black |
2682 | text $ui_index -background white -foreground black \ | |
2683 | -borderwidth 0 \ | |
c5a1eb88 | 2684 | -width 20 -height 10 \ |
3c236977 | 2685 | -wrap none \ |
6c6dd01a | 2686 | -cursor $cursor_ptr \ |
3c236977 SP |
2687 | -xscrollcommand {.vpane.files.index.sx set} \ |
2688 | -yscrollcommand {.vpane.files.index.sy set} \ | |
cb07fc2a | 2689 | -state disabled |
3c236977 SP |
2690 | scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview] |
2691 | scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview] | |
cb07fc2a | 2692 | pack .vpane.files.index.title -side top -fill x |
3c236977 SP |
2693 | pack .vpane.files.index.sx -side bottom -fill x |
2694 | pack .vpane.files.index.sy -side right -fill y | |
cb07fc2a | 2695 | pack $ui_index -side left -fill both -expand 1 |
cb07fc2a | 2696 | |
0812665e | 2697 | # -- Working Directory File List |
a49c67d1 | 2698 | # |
c5a1eb88 | 2699 | frame .vpane.files.workdir -height 100 -width 200 |
c73ce762 | 2700 | label .vpane.files.workdir.title -text [mc "Unstaged Changes"] \ |
c382fdd7 PH |
2701 | -background lightsalmon -foreground black |
2702 | text $ui_workdir -background white -foreground black \ | |
2703 | -borderwidth 0 \ | |
c5a1eb88 | 2704 | -width 20 -height 10 \ |
3c236977 | 2705 | -wrap none \ |
6c6dd01a | 2706 | -cursor $cursor_ptr \ |
3c236977 SP |
2707 | -xscrollcommand {.vpane.files.workdir.sx set} \ |
2708 | -yscrollcommand {.vpane.files.workdir.sy set} \ | |
cb07fc2a | 2709 | -state disabled |
3c236977 SP |
2710 | scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview] |
2711 | scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview] | |
0812665e | 2712 | pack .vpane.files.workdir.title -side top -fill x |
3c236977 SP |
2713 | pack .vpane.files.workdir.sx -side bottom -fill x |
2714 | pack .vpane.files.workdir.sy -side right -fill y | |
0812665e | 2715 | pack $ui_workdir -side left -fill both -expand 1 |
a0592d3f | 2716 | |
0812665e | 2717 | .vpane.files add .vpane.files.workdir -sticky nsew |
a0592d3f | 2718 | .vpane.files add .vpane.files.index -sticky nsew |
cb07fc2a | 2719 | |
0812665e | 2720 | foreach i [list $ui_index $ui_workdir] { |
3849bfba SP |
2721 | rmsel_tag $i |
2722 | $i tag conf in_diff -background [$i tag cget in_sel -background] | |
24263b77 SP |
2723 | } |
2724 | unset i | |
131f503b | 2725 | |
0fb8f9ce | 2726 | # -- Diff and Commit Area |
a49c67d1 | 2727 | # |
8009dcdc | 2728 | frame .vpane.lower -height 300 -width 400 |
0fb8f9ce SP |
2729 | frame .vpane.lower.commarea |
2730 | frame .vpane.lower.diff -relief sunken -borderwidth 1 | |
a0592d3f JS |
2731 | pack .vpane.lower.diff -fill both -expand 1 |
2732 | pack .vpane.lower.commarea -side bottom -fill x | |
0fd49d0a | 2733 | .vpane add .vpane.lower -sticky nsew |
cb07fc2a SP |
2734 | |
2735 | # -- Commit Area Buttons | |
a49c67d1 | 2736 | # |
0fb8f9ce SP |
2737 | frame .vpane.lower.commarea.buttons |
2738 | label .vpane.lower.commarea.buttons.l -text {} \ | |
cb07fc2a | 2739 | -anchor w \ |
7416bbc6 | 2740 | -justify left |
0fb8f9ce SP |
2741 | pack .vpane.lower.commarea.buttons.l -side top -fill x |
2742 | pack .vpane.lower.commarea.buttons -side left -fill y | |
131f503b | 2743 | |
1ac17950 | 2744 | button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \ |
8056cc4f | 2745 | -command ui_do_rescan |
0fb8f9ce | 2746 | pack .vpane.lower.commarea.buttons.rescan -side top -fill x |
390adaea SP |
2747 | lappend disable_on_lock \ |
2748 | {.vpane.lower.commarea.buttons.rescan conf -state} | |
131f503b | 2749 | |
1ac17950 | 2750 | button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \ |
7416bbc6 | 2751 | -command do_add_all |
7fe7e733 | 2752 | pack .vpane.lower.commarea.buttons.incall -side top -fill x |
390adaea SP |
2753 | lappend disable_on_lock \ |
2754 | {.vpane.lower.commarea.buttons.incall conf -state} | |
131f503b | 2755 | |
ed70e4d7 | 2756 | if {![is_enabled nocommitmsg]} { |
1e02b32e SP |
2757 | button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \ |
2758 | -command do_signoff | |
2759 | pack .vpane.lower.commarea.buttons.signoff -side top -fill x | |
2760 | } | |
131f503b | 2761 | |
1e65c622 | 2762 | button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \ |
7416bbc6 | 2763 | -command do_commit |
0fb8f9ce | 2764 | pack .vpane.lower.commarea.buttons.commit -side top -fill x |
390adaea SP |
2765 | lappend disable_on_lock \ |
2766 | {.vpane.lower.commarea.buttons.commit conf -state} | |
cb07fc2a | 2767 | |
1e02b32e SP |
2768 | if {![is_enabled nocommit]} { |
2769 | button .vpane.lower.commarea.buttons.push -text [mc Push] \ | |
2770 | -command do_push_anywhere | |
2771 | pack .vpane.lower.commarea.buttons.push -side top -fill x | |
1e65c622 AG |
2772 | } |
2773 | ||
cb07fc2a | 2774 | # -- Commit Message Buffer |
a49c67d1 | 2775 | # |
0fb8f9ce | 2776 | frame .vpane.lower.commarea.buffer |
24ac9b75 | 2777 | frame .vpane.lower.commarea.buffer.header |
0fb8f9ce | 2778 | set ui_comm .vpane.lower.commarea.buffer.t |
24ac9b75 | 2779 | set ui_coml .vpane.lower.commarea.buffer.header.l |
1e02b32e SP |
2780 | |
2781 | if {![is_enabled nocommit]} { | |
2782 | radiobutton .vpane.lower.commarea.buffer.header.new \ | |
2783 | -text [mc "New Commit"] \ | |
2784 | -command do_select_commit_type \ | |
2785 | -variable selected_commit_type \ | |
2786 | -value new | |
2787 | lappend disable_on_lock \ | |
2788 | [list .vpane.lower.commarea.buffer.header.new conf -state] | |
2789 | radiobutton .vpane.lower.commarea.buffer.header.amend \ | |
2790 | -text [mc "Amend Last Commit"] \ | |
2791 | -command do_select_commit_type \ | |
2792 | -variable selected_commit_type \ | |
2793 | -value amend | |
2794 | lappend disable_on_lock \ | |
2795 | [list .vpane.lower.commarea.buffer.header.amend conf -state] | |
2796 | } | |
2797 | ||
a49c67d1 | 2798 | label $ui_coml \ |
cb07fc2a | 2799 | -anchor w \ |
7416bbc6 | 2800 | -justify left |
4539eacd SP |
2801 | proc trace_commit_type {varname args} { |
2802 | global ui_coml commit_type | |
2803 | switch -glob -- $commit_type { | |
1ac17950 CS |
2804 | initial {set txt [mc "Initial Commit Message:"]} |
2805 | amend {set txt [mc "Amended Commit Message:"]} | |
2806 | amend-initial {set txt [mc "Amended Initial Commit Message:"]} | |
2807 | amend-merge {set txt [mc "Amended Merge Commit Message:"]} | |
2808 | merge {set txt [mc "Merge Commit Message:"]} | |
2809 | * {set txt [mc "Commit Message:"]} | |
4539eacd SP |
2810 | } |
2811 | $ui_coml conf -text $txt | |
2812 | } | |
2813 | trace add variable commit_type write trace_commit_type | |
24ac9b75 | 2814 | pack $ui_coml -side left -fill x |
1e02b32e SP |
2815 | |
2816 | if {![is_enabled nocommit]} { | |
2817 | pack .vpane.lower.commarea.buffer.header.amend -side right | |
2818 | pack .vpane.lower.commarea.buffer.header.new -side right | |
2819 | } | |
24ac9b75 | 2820 | |
c382fdd7 PH |
2821 | text $ui_comm -background white -foreground black \ |
2822 | -borderwidth 1 \ | |
9861671d | 2823 | -undo true \ |
b2c6fcf1 | 2824 | -maxundo 20 \ |
9861671d | 2825 | -autoseparators true \ |
cb07fc2a | 2826 | -relief sunken \ |
11027d54 | 2827 | -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \ |
b4946930 | 2828 | -font font_diff \ |
6c6dd01a | 2829 | -yscrollcommand {.vpane.lower.commarea.buffer.sby set} |
390adaea SP |
2830 | scrollbar .vpane.lower.commarea.buffer.sby \ |
2831 | -command [list $ui_comm yview] | |
24ac9b75 | 2832 | pack .vpane.lower.commarea.buffer.header -side top -fill x |
0fb8f9ce | 2833 | pack .vpane.lower.commarea.buffer.sby -side right -fill y |
cb07fc2a | 2834 | pack $ui_comm -side left -fill y |
0fb8f9ce SP |
2835 | pack .vpane.lower.commarea.buffer -side left -fill y |
2836 | ||
0e794311 SP |
2837 | # -- Commit Message Buffer Context Menu |
2838 | # | |
e8ab6446 SP |
2839 | set ctxm .vpane.lower.commarea.buffer.ctxm |
2840 | menu $ctxm -tearoff 0 | |
2841 | $ctxm add command \ | |
1ac17950 | 2842 | -label [mc Cut] \ |
e8ab6446 SP |
2843 | -command {tk_textCut $ui_comm} |
2844 | $ctxm add command \ | |
1ac17950 | 2845 | -label [mc Copy] \ |
e8ab6446 SP |
2846 | -command {tk_textCopy $ui_comm} |
2847 | $ctxm add command \ | |
1ac17950 | 2848 | -label [mc Paste] \ |
e8ab6446 SP |
2849 | -command {tk_textPaste $ui_comm} |
2850 | $ctxm add command \ | |
1ac17950 | 2851 | -label [mc Delete] \ |
e8ab6446 SP |
2852 | -command {$ui_comm delete sel.first sel.last} |
2853 | $ctxm add separator | |
2854 | $ctxm add command \ | |
1ac17950 | 2855 | -label [mc "Select All"] \ |
75e78c8a | 2856 | -command {focus $ui_comm;$ui_comm tag add sel 0.0 end} |
e8ab6446 | 2857 | $ctxm add command \ |
1ac17950 | 2858 | -label [mc "Copy All"] \ |
e8ab6446 | 2859 | -command { |
0e794311 SP |
2860 | $ui_comm tag add sel 0.0 end |
2861 | tk_textCopy $ui_comm | |
2862 | $ui_comm tag remove sel 0.0 end | |
e8ab6446 SP |
2863 | } |
2864 | $ctxm add separator | |
2865 | $ctxm add command \ | |
1ac17950 | 2866 | -label [mc "Sign Off"] \ |
0e794311 | 2867 | -command do_signoff |
95b002ee | 2868 | set ui_comm_ctxm $ctxm |
0e794311 | 2869 | |
0fb8f9ce | 2870 | # -- Diff Header |
a49c67d1 | 2871 | # |
20a53c02 SP |
2872 | proc trace_current_diff_path {varname args} { |
2873 | global current_diff_path diff_actions file_states | |
2874 | if {$current_diff_path eq {}} { | |
e8ab6446 SP |
2875 | set s {} |
2876 | set f {} | |
2877 | set p {} | |
2878 | set o disabled | |
2879 | } else { | |
20a53c02 | 2880 | set p $current_diff_path |
e8ab6446 | 2881 | set s [mapdesc [lindex $file_states($p) 0] $p] |
1ac17950 | 2882 | set f [mc "File:"] |
e8ab6446 SP |
2883 | set p [escape_path $p] |
2884 | set o normal | |
2885 | } | |
2886 | ||
2887 | .vpane.lower.diff.header.status configure -text $s | |
2888 | .vpane.lower.diff.header.file configure -text $f | |
2889 | .vpane.lower.diff.header.path configure -text $p | |
2890 | foreach w $diff_actions { | |
2891 | uplevel #0 $w $o | |
2892 | } | |
2893 | } | |
20a53c02 | 2894 | trace add variable current_diff_path write trace_current_diff_path |
e8ab6446 | 2895 | |
9adccb05 | 2896 | frame .vpane.lower.diff.header -background gold |
e8ab6446 | 2897 | label .vpane.lower.diff.header.status \ |
9adccb05 | 2898 | -background gold \ |
c382fdd7 | 2899 | -foreground black \ |
3e7b0e1d SP |
2900 | -width $max_status_desc \ |
2901 | -anchor w \ | |
7416bbc6 | 2902 | -justify left |
e8ab6446 | 2903 | label .vpane.lower.diff.header.file \ |
9adccb05 | 2904 | -background gold \ |
c382fdd7 | 2905 | -foreground black \ |
e8ab6446 | 2906 | -anchor w \ |
7416bbc6 | 2907 | -justify left |
e8ab6446 | 2908 | label .vpane.lower.diff.header.path \ |
9adccb05 | 2909 | -background gold \ |
c382fdd7 | 2910 | -foreground black \ |
fce89e46 | 2911 | -anchor w \ |
7416bbc6 | 2912 | -justify left |
e8ab6446 SP |
2913 | pack .vpane.lower.diff.header.status -side left |
2914 | pack .vpane.lower.diff.header.file -side left | |
2915 | pack .vpane.lower.diff.header.path -fill x | |
2916 | set ctxm .vpane.lower.diff.header.ctxm | |
2917 | menu $ctxm -tearoff 0 | |
2918 | $ctxm add command \ | |
1ac17950 | 2919 | -label [mc Copy] \ |
fce89e46 SP |
2920 | -command { |
2921 | clipboard clear | |
2922 | clipboard append \ | |
2923 | -format STRING \ | |
2924 | -type STRING \ | |
20a53c02 | 2925 | -- $current_diff_path |
fce89e46 | 2926 | } |
e8ab6446 SP |
2927 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] |
2928 | bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y" | |
0fb8f9ce SP |
2929 | |
2930 | # -- Diff Body | |
a49c67d1 | 2931 | # |
0fb8f9ce SP |
2932 | frame .vpane.lower.diff.body |
2933 | set ui_diff .vpane.lower.diff.body.t | |
c382fdd7 PH |
2934 | text $ui_diff -background white -foreground black \ |
2935 | -borderwidth 0 \ | |
0fb8f9ce | 2936 | -width 80 -height 15 -wrap none \ |
b4946930 | 2937 | -font font_diff \ |
0fb8f9ce SP |
2938 | -xscrollcommand {.vpane.lower.diff.body.sbx set} \ |
2939 | -yscrollcommand {.vpane.lower.diff.body.sby set} \ | |
0fb8f9ce SP |
2940 | -state disabled |
2941 | scrollbar .vpane.lower.diff.body.sbx -orient horizontal \ | |
2942 | -command [list $ui_diff xview] | |
2943 | scrollbar .vpane.lower.diff.body.sby -orient vertical \ | |
2944 | -command [list $ui_diff yview] | |
2945 | pack .vpane.lower.diff.body.sbx -side bottom -fill x | |
2946 | pack .vpane.lower.diff.body.sby -side right -fill y | |
2947 | pack $ui_diff -side left -fill both -expand 1 | |
2948 | pack .vpane.lower.diff.header -side top -fill x | |
2949 | pack .vpane.lower.diff.body -side bottom -fill both -expand 1 | |
2950 | ||
30b14ed3 | 2951 | $ui_diff tag conf d_cr -elide true |
ca521566 SP |
2952 | $ui_diff tag conf d_@ -foreground blue -font font_diffbold |
2953 | $ui_diff tag conf d_+ -foreground {#00a000} | |
fec4a785 SP |
2954 | $ui_diff tag conf d_- -foreground red |
2955 | ||
ca521566 | 2956 | $ui_diff tag conf d_++ -foreground {#00a000} |
fec4a785 SP |
2957 | $ui_diff tag conf d_-- -foreground red |
2958 | $ui_diff tag conf d_+s \ | |
ca521566 SP |
2959 | -foreground {#00a000} \ |
2960 | -background {#e2effa} | |
fec4a785 SP |
2961 | $ui_diff tag conf d_-s \ |
2962 | -foreground red \ | |
ca521566 | 2963 | -background {#e2effa} |
fec4a785 | 2964 | $ui_diff tag conf d_s+ \ |
ca521566 SP |
2965 | -foreground {#00a000} \ |
2966 | -background ivory1 | |
fec4a785 SP |
2967 | $ui_diff tag conf d_s- \ |
2968 | -foreground red \ | |
ca521566 | 2969 | -background ivory1 |
fec4a785 SP |
2970 | |
2971 | $ui_diff tag conf d<<<<<<< \ | |
2972 | -foreground orange \ | |
2973 | -font font_diffbold | |
2974 | $ui_diff tag conf d======= \ | |
2975 | -foreground orange \ | |
2976 | -font font_diffbold | |
2977 | $ui_diff tag conf d>>>>>>> \ | |
2978 | -foreground orange \ | |
2979 | -font font_diffbold | |
cb07fc2a | 2980 | |
ca521566 SP |
2981 | $ui_diff tag raise sel |
2982 | ||
0e794311 SP |
2983 | # -- Diff Body Context Menu |
2984 | # | |
042c2325 AG |
2985 | |
2986 | proc create_common_diff_popup {ctxm} { | |
2987 | $ctxm add command \ | |
2988 | -label [mc "Show Less Context"] \ | |
2989 | -command show_less_context | |
2990 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] | |
2991 | $ctxm add command \ | |
2992 | -label [mc "Show More Context"] \ | |
2993 | -command show_more_context | |
2994 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] | |
2995 | $ctxm add separator | |
2996 | $ctxm add command \ | |
2997 | -label [mc Refresh] \ | |
2998 | -command reshow_diff | |
2999 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] | |
3000 | $ctxm add command \ | |
3001 | -label [mc Copy] \ | |
3002 | -command {tk_textCopy $ui_diff} | |
3003 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] | |
3004 | $ctxm add command \ | |
3005 | -label [mc "Select All"] \ | |
3006 | -command {focus $ui_diff;$ui_diff tag add sel 0.0 end} | |
3007 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] | |
3008 | $ctxm add command \ | |
3009 | -label [mc "Copy All"] \ | |
3010 | -command { | |
3011 | $ui_diff tag add sel 0.0 end | |
3012 | tk_textCopy $ui_diff | |
3013 | $ui_diff tag remove sel 0.0 end | |
3014 | } | |
3015 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] | |
3016 | $ctxm add separator | |
3017 | $ctxm add command \ | |
3018 | -label [mc "Decrease Font Size"] \ | |
3019 | -command {incr_font_size font_diff -1} | |
3020 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] | |
3021 | $ctxm add command \ | |
3022 | -label [mc "Increase Font Size"] \ | |
3023 | -command {incr_font_size font_diff 1} | |
3024 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] | |
3025 | $ctxm add separator | |
3fe01623 AG |
3026 | set emenu $ctxm.enc |
3027 | menu $emenu | |
3028 | build_encoding_menu $emenu [list force_diff_encoding] | |
3029 | $ctxm add cascade \ | |
3030 | -label [mc "Encoding"] \ | |
3031 | -menu $emenu | |
3032 | lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] | |
3033 | $ctxm add separator | |
042c2325 AG |
3034 | $ctxm add command -label [mc "Options..."] \ |
3035 | -command do_options | |
3036 | } | |
3037 | ||
e8ab6446 SP |
3038 | set ctxm .vpane.lower.diff.body.ctxm |
3039 | menu $ctxm -tearoff 0 | |
fba6072e JS |
3040 | $ctxm add command \ |
3041 | -label [mc "Apply/Reverse Hunk"] \ | |
3042 | -command {apply_hunk $cursorX $cursorY} | |
3043 | set ui_diff_applyhunk [$ctxm index last] | |
3044 | lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state] | |
5821988f JS |
3045 | $ctxm add command \ |
3046 | -label [mc "Apply/Reverse Line"] \ | |
3047 | -command {apply_line $cursorX $cursorY; do_rescan} | |
3048 | set ui_diff_applyline [$ctxm index last] | |
3049 | lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state] | |
fba6072e | 3050 | $ctxm add separator |
042c2325 AG |
3051 | create_common_diff_popup $ctxm |
3052 | ||
3053 | set ctxmmg .vpane.lower.diff.body.ctxmmg | |
3054 | menu $ctxmmg -tearoff 0 | |
7e30682c AG |
3055 | $ctxmmg add command \ |
3056 | -label [mc "Run Merge Tool"] \ | |
3057 | -command {merge_resolve_tool} | |
3058 | lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state] | |
3059 | $ctxmmg add separator | |
042c2325 AG |
3060 | $ctxmmg add command \ |
3061 | -label [mc "Use Remote Version"] \ | |
3062 | -command {merge_resolve_one 3} | |
3063 | lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state] | |
3064 | $ctxmmg add command \ | |
3065 | -label [mc "Use Local Version"] \ | |
3066 | -command {merge_resolve_one 2} | |
3067 | lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state] | |
3068 | $ctxmmg add command \ | |
3069 | -label [mc "Revert To Base"] \ | |
3070 | -command {merge_resolve_one 1} | |
3071 | lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state] | |
3072 | $ctxmmg add separator | |
3073 | create_common_diff_popup $ctxmmg | |
3074 | ||
3075 | proc popup_diff_menu {ctxm ctxmmg x y X Y} { | |
ce015c21 | 3076 | global current_diff_path file_states |
83751fc1 SP |
3077 | set ::cursorX $x |
3078 | set ::cursorY $y | |
042c2325 AG |
3079 | if {[info exists file_states($current_diff_path)]} { |
3080 | set state [lindex $file_states($current_diff_path) 0] | |
a25c5189 | 3081 | } else { |
042c2325 AG |
3082 | set state {__} |
3083 | } | |
ff515d81 | 3084 | if {[string first {U} $state] >= 0} { |
042c2325 | 3085 | tk_popup $ctxmmg $X $Y |
047d94d5 | 3086 | } else { |
042c2325 AG |
3087 | if {$::ui_index eq $::current_diff_side} { |
3088 | set l [mc "Unstage Hunk From Commit"] | |
3089 | set t [mc "Unstage Line From Commit"] | |
3090 | } else { | |
3091 | set l [mc "Stage Hunk For Commit"] | |
3092 | set t [mc "Stage Line For Commit"] | |
3093 | } | |
3094 | if {$::is_3way_diff | |
3095 | || $current_diff_path eq {} | |
3096 | || {__} eq $state | |
3097 | || {_O} eq $state | |
3098 | || {_T} eq $state | |
3099 | || {T_} eq $state} { | |
3100 | set s disabled | |
3101 | } else { | |
3102 | set s normal | |
3103 | } | |
3104 | $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l | |
3105 | $ctxm entryconf $::ui_diff_applyline -state $s -label $t | |
3106 | tk_popup $ctxm $X $Y | |
9c9f5fa9 | 3107 | } |
83751fc1 | 3108 | } |
042c2325 | 3109 | bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg %x %y %X %Y] |
0e794311 | 3110 | |
cb07fc2a | 3111 | # -- Status Bar |
e8ab6446 | 3112 | # |
51530d17 | 3113 | set main_status [::status_bar::new .status] |
cb07fc2a | 3114 | pack .status -anchor w -side bottom -fill x |
1ac17950 | 3115 | $main_status show [mc "Initializing..."] |
cb07fc2a | 3116 | |
2d19516d | 3117 | # -- Load geometry |
e8ab6446 | 3118 | # |
2d19516d | 3119 | catch { |
51f4d16b | 3120 | set gm $repo_config(gui.geometry) |
c4fe7728 SP |
3121 | wm geometry . [lindex $gm 0] |
3122 | .vpane sash place 0 \ | |
a0592d3f JS |
3123 | [lindex $gm 1] \ |
3124 | [lindex [.vpane sash coord 0] 1] | |
c4fe7728 | 3125 | .vpane.files sash place 0 \ |
a0592d3f JS |
3126 | [lindex [.vpane.files sash coord 0] 0] \ |
3127 | [lindex $gm 2] | |
c4fe7728 | 3128 | unset gm |
390adaea | 3129 | } |
2d19516d | 3130 | |
cb07fc2a | 3131 | # -- Key Bindings |
e8ab6446 | 3132 | # |
ec6b424a | 3133 | bind $ui_comm <$M1B-Key-Return> {do_commit;break} |
cd16a6c9 SP |
3134 | bind $ui_comm <$M1B-Key-t> {do_add_selection;break} |
3135 | bind $ui_comm <$M1B-Key-T> {do_add_selection;break} | |
93e912c5 SP |
3136 | bind $ui_comm <$M1B-Key-i> {do_add_all;break} |
3137 | bind $ui_comm <$M1B-Key-I> {do_add_all;break} | |
9861671d SP |
3138 | bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break} |
3139 | bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break} | |
3140 | bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break} | |
3141 | bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break} | |
3142 | bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break} | |
3143 | bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break} | |
3144 | bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break} | |
3145 | bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break} | |
729ffa50 MB |
3146 | bind $ui_comm <$M1B-Key-minus> {show_less_context;break} |
3147 | bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break} | |
3148 | bind $ui_comm <$M1B-Key-equal> {show_more_context;break} | |
3149 | bind $ui_comm <$M1B-Key-plus> {show_more_context;break} | |
3150 | bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break} | |
9861671d SP |
3151 | |
3152 | bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break} | |
3153 | bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break} | |
3154 | bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break} | |
3155 | bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break} | |
3156 | bind $ui_diff <$M1B-Key-v> {break} | |
3157 | bind $ui_diff <$M1B-Key-V> {break} | |
3158 | bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break} | |
3159 | bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break} | |
b2c6fcf1 SP |
3160 | bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break} |
3161 | bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break} | |
3162 | bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break} | |
3163 | bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break} | |
60aa065f SP |
3164 | bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break} |
3165 | bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break} | |
3166 | bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break} | |
3167 | bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break} | |
3168 | bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break} | |
3169 | bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break} | |
23effa79 | 3170 | bind $ui_diff <Button-1> {focus %W} |
49b86f01 | 3171 | |
64a906f8 | 3172 | if {[is_enabled branch]} { |
b1fa2bff SP |
3173 | bind . <$M1B-Key-n> branch_create::dialog |
3174 | bind . <$M1B-Key-N> branch_create::dialog | |
d41b43eb SP |
3175 | bind . <$M1B-Key-o> branch_checkout::dialog |
3176 | bind . <$M1B-Key-O> branch_checkout::dialog | |
a870ddc0 SP |
3177 | bind . <$M1B-Key-m> merge::dialog |
3178 | bind . <$M1B-Key-M> merge::dialog | |
bd29ebc3 | 3179 | } |
840bcfa7 SP |
3180 | if {[is_enabled transport]} { |
3181 | bind . <$M1B-Key-p> do_push_anywhere | |
3182 | bind . <$M1B-Key-P> do_push_anywhere | |
3183 | } | |
bd29ebc3 | 3184 | |
8056cc4f AG |
3185 | bind . <Key-F5> ui_do_rescan |
3186 | bind . <$M1B-Key-r> ui_do_rescan | |
3187 | bind . <$M1B-Key-R> ui_do_rescan | |
07123f40 SP |
3188 | bind . <$M1B-Key-s> do_signoff |
3189 | bind . <$M1B-Key-S> do_signoff | |
cd16a6c9 SP |
3190 | bind . <$M1B-Key-t> do_add_selection |
3191 | bind . <$M1B-Key-T> do_add_selection | |
93e912c5 SP |
3192 | bind . <$M1B-Key-i> do_add_all |
3193 | bind . <$M1B-Key-I> do_add_all | |
729ffa50 MB |
3194 | bind . <$M1B-Key-minus> {show_less_context;break} |
3195 | bind . <$M1B-Key-KP_Subtract> {show_less_context;break} | |
3196 | bind . <$M1B-Key-equal> {show_more_context;break} | |
3197 | bind . <$M1B-Key-plus> {show_more_context;break} | |
3198 | bind . <$M1B-Key-KP_Add> {show_more_context;break} | |
07123f40 | 3199 | bind . <$M1B-Key-Return> do_commit |
0812665e | 3200 | foreach i [list $ui_index $ui_workdir] { |
24263b77 SP |
3201 | bind $i <Button-1> "toggle_or_diff $i %x %y; break" |
3202 | bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break" | |
3203 | bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break" | |
cb07fc2a | 3204 | } |
62aac80b SP |
3205 | unset i |
3206 | ||
3207 | set file_lists($ui_index) [list] | |
0812665e | 3208 | set file_lists($ui_workdir) [list] |
a49c67d1 | 3209 | |
19c82148 | 3210 | wm title . "[appname] ([reponame]) [file normalize [file dirname [gitdir]]]" |
cb07fc2a | 3211 | focus -force $ui_comm |
1d8b3cbf | 3212 | |
85ab313e SP |
3213 | # -- Warn the user about environmental problems. Cygwin's Tcl |
3214 | # does *not* pass its env array onto any processes it spawns. | |
3215 | # This means that git processes get none of our environment. | |
1d8b3cbf | 3216 | # |
20ddfcaa | 3217 | if {[is_Cygwin]} { |
1d8b3cbf SP |
3218 | set ignored_env 0 |
3219 | set suggest_user {} | |
c8c4854b | 3220 | set msg [mc "Possible environment issues exist. |
1d8b3cbf SP |
3221 | |
3222 | The following environment variables are probably | |
3223 | going to be ignored by any Git subprocess run | |
c8c4854b | 3224 | by %s: |
1d8b3cbf | 3225 | |
c8c4854b | 3226 | " [appname]] |
1d8b3cbf SP |
3227 | foreach name [array names env] { |
3228 | switch -regexp -- $name { | |
3229 | {^GIT_INDEX_FILE$} - | |
3230 | {^GIT_OBJECT_DIRECTORY$} - | |
3231 | {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} - | |
3232 | {^GIT_DIFF_OPTS$} - | |
3233 | {^GIT_EXTERNAL_DIFF$} - | |
3234 | {^GIT_PAGER$} - | |
3235 | {^GIT_TRACE$} - | |
3236 | {^GIT_CONFIG$} - | |
3237 | {^GIT_CONFIG_LOCAL$} - | |
3238 | {^GIT_(AUTHOR|COMMITTER)_DATE$} { | |
3239 | append msg " - $name\n" | |
3240 | incr ignored_env | |
3241 | } | |
3242 | {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} { | |
3243 | append msg " - $name\n" | |
3244 | incr ignored_env | |
3245 | set suggest_user $name | |
3246 | } | |
3247 | } | |
3248 | } | |
3249 | if {$ignored_env > 0} { | |
c8c4854b | 3250 | append msg [mc " |
1d8b3cbf | 3251 | This is due to a known issue with the |
c8c4854b | 3252 | Tcl binary distributed by Cygwin."] |
1d8b3cbf SP |
3253 | |
3254 | if {$suggest_user ne {}} { | |
c8c4854b | 3255 | append msg [mc " |
1d8b3cbf | 3256 | |
c8c4854b | 3257 | A good replacement for %s |
1d8b3cbf SP |
3258 | is placing values for the user.name and |
3259 | user.email settings into your personal | |
3260 | ~/.gitconfig file. | |
c8c4854b | 3261 | " $suggest_user] |
1d8b3cbf SP |
3262 | } |
3263 | warn_popup $msg | |
3264 | } | |
3265 | unset ignored_env msg suggest_user name | |
3266 | } | |
3267 | ||
85ab313e SP |
3268 | # -- Only initialize complex UI if we are going to stay running. |
3269 | # | |
64a906f8 | 3270 | if {[is_enabled transport]} { |
4ccdab02 | 3271 | load_all_remotes |
85ab313e | 3272 | |
6bdf5e5f | 3273 | set n [.mbar.remote index end] |
8329bd07 | 3274 | populate_remotes_menu |
6bdf5e5f SP |
3275 | set n [expr {[.mbar.remote index end] - $n}] |
3276 | if {$n > 0} { | |
7e09b153 | 3277 | if {[.mbar.remote type 0] eq "tearoff"} { incr n } |
6bdf5e5f SP |
3278 | .mbar.remote insert $n separator |
3279 | } | |
3280 | unset n | |
4ccdab02 | 3281 | } |
85ab313e | 3282 | |
4578c5cb SP |
3283 | if {[winfo exists $ui_comm]} { |
3284 | set GITGUI_BCK_exists [load_message GITGUI_BCK] | |
3285 | ||
3286 | # -- If both our backup and message files exist use the | |
3287 | # newer of the two files to initialize the buffer. | |
3288 | # | |
3289 | if {$GITGUI_BCK_exists} { | |
3290 | set m [gitdir GITGUI_MSG] | |
3291 | if {[file isfile $m]} { | |
3292 | if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} { | |
3293 | catch {file delete [gitdir GITGUI_MSG]} | |
3294 | } else { | |
3295 | $ui_comm delete 0.0 end | |
3296 | $ui_comm edit reset | |
3297 | $ui_comm edit modified false | |
3298 | catch {file delete [gitdir GITGUI_BCK]} | |
3299 | set GITGUI_BCK_exists 0 | |
3300 | } | |
3301 | } | |
3302 | unset m | |
3303 | } | |
3304 | ||
3305 | proc backup_commit_buffer {} { | |
3306 | global ui_comm GITGUI_BCK_exists | |
3307 | ||
3308 | set m [$ui_comm edit modified] | |
3309 | if {$m || $GITGUI_BCK_exists} { | |
3310 | set msg [string trim [$ui_comm get 0.0 end]] | |
3311 | regsub -all -line {[ \r\t]+$} $msg {} msg | |
3312 | ||
3313 | if {$msg eq {}} { | |
3314 | if {$GITGUI_BCK_exists} { | |
3315 | catch {file delete [gitdir GITGUI_BCK]} | |
3316 | set GITGUI_BCK_exists 0 | |
3317 | } | |
3318 | } elseif {$m} { | |
3319 | catch { | |
3320 | set fd [open [gitdir GITGUI_BCK] w] | |
3321 | puts -nonewline $fd $msg | |
3322 | close $fd | |
3323 | set GITGUI_BCK_exists 1 | |
3324 | } | |
3325 | } | |
3326 | ||
3327 | $ui_comm edit modified false | |
3328 | } | |
3329 | ||
3330 | set ::GITGUI_BCK_i [after 2000 backup_commit_buffer] | |
3331 | } | |
3332 | ||
3333 | backup_commit_buffer | |
95b002ee SP |
3334 | |
3335 | # -- If the user has aspell available we can drive it | |
3336 | # in pipe mode to spellcheck the commit message. | |
3337 | # | |
3338 | set spell_cmd [list |] | |
3339 | set spell_dict [get_config gui.spellingdictionary] | |
3340 | lappend spell_cmd aspell | |
3341 | if {$spell_dict ne {}} { | |
3342 | lappend spell_cmd --master=$spell_dict | |
3343 | } | |
3344 | lappend spell_cmd --mode=none | |
3345 | lappend spell_cmd --encoding=utf-8 | |
3346 | lappend spell_cmd pipe | |
3347 | if {$spell_dict eq {none} | |
3348 | || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} { | |
3349 | bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y] | |
3350 | } else { | |
3351 | set ui_comm_spell [spellcheck::init \ | |
3352 | $spell_fd \ | |
3353 | $ui_comm \ | |
3354 | $ui_comm_ctxm \ | |
3355 | ] | |
3356 | } | |
3357 | unset -nocomplain spell_cmd spell_fd spell_err spell_dict | |
4578c5cb SP |
3358 | } |
3359 | ||
53716a7b | 3360 | lock_index begin-read |
301dfaa9 SP |
3361 | if {![winfo ismapped .]} { |
3362 | wm deiconify . | |
3363 | } | |
1e65c622 AG |
3364 | after 1 { |
3365 | if {[is_enabled initialamend]} { | |
3366 | force_amend | |
3367 | } else { | |
3368 | do_rescan | |
3369 | } | |
3370 | ||
3371 | if {[is_enabled nocommitmsg]} { | |
3372 | $ui_comm configure -state disabled -background gray | |
3373 | } | |
3374 | } | |
3972b987 SP |
3375 | if {[is_enabled multicommit]} { |
3376 | after 1000 hint_gc | |
3377 | } | |
1e65c622 AG |
3378 | if {[is_enabled retcode]} { |
3379 | bind . <Destroy> {+terminate_me %W} | |
3380 | } | |
bb4812bc PB |
3381 | if {$picked && [is_config_true gui.autoexplore]} { |
3382 | do_explore | |
3383 | } |