Skip to content

Commit fe47c9c

Browse files
committed
* https://github.com/prati0100/git-gui: git-gui: allow opening currently selected file in default app git-gui: allow closing console window with Escape git gui: fix branch name encoding error git-gui: revert untracked files by deleting them git-gui: update status bar to track operations git-gui: consolidate naming conventions
2 parents 042ed3e + 0d2116c commit fe47c9c

File tree

10 files changed

+920
-232
lines changed

10 files changed

+920
-232
lines changed

git-gui/git-gui.sh

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.}]
3030
##
3131
## Tcl/Tk sanity check
3232

33-
if {[catch {package require Tcl 8.4} err]
34-
|| [catch {package require Tk 8.4} err]
33+
if {[catch {package require Tcl 8.6} err]
34+
|| [catch {package require Tk 8.6} err]
3535
} {
3636
catch {wm withdraw .}
3737
tk_messageBox \
@@ -684,6 +684,7 @@ proc load_current_branch {} {
684684
global current_branch is_detached
685685
686686
set fd [open [gitdir HEAD] r]
687+
fconfigure $fd -translation binary -encoding utf-8
687688
if {[gets $fd ref] < 1} {
688689
set ref {}
689690
}
@@ -1797,10 +1798,10 @@ proc ui_status {msg} {
17971798
}
17981799
}
17991800
1800-
proc ui_ready {{test {}}} {
1801+
proc ui_ready {} {
18011802
global main_status
18021803
if {[info exists main_status]} {
1803-
$main_status show [mc "Ready."] $test
1804+
$main_status show [mc "Ready."]
18041805
}
18051806
}
18061807
@@ -2150,8 +2151,6 @@ proc incr_font_size {font {amt 1}} {
21502151
##
21512152
## ui commands
21522153
2153-
set starting_gitk_msg [mc "Starting gitk... please wait..."]
2154-
21552154
proc do_gitk {revs {is_submodule false}} {
21562155
global current_diff_path file_states current_diff_side ui_index
21572156
global _gitdir _gitworktree
@@ -2206,10 +2205,11 @@ proc do_gitk {revs {is_submodule false}} {
22062205
set env(GIT_WORK_TREE) $_gitworktree
22072206
cd $pwd
22082207
2209-
ui_status $::starting_gitk_msg
2210-
after 10000 {
2211-
ui_ready $starting_gitk_msg
2212-
}
2208+
set status_operation [$::main_status \
2209+
start \
2210+
[mc "Starting %s... please wait..." "gitk"]]
2211+
2212+
after 3500 [list $status_operation stop]
22132213
}
22142214
}
22152215
@@ -2240,16 +2240,16 @@ proc do_git_gui {} {
22402240
set env(GIT_WORK_TREE) $_gitworktree
22412241
cd $pwd
22422242
2243-
ui_status $::starting_gitk_msg
2244-
after 10000 {
2245-
ui_ready $starting_gitk_msg
2246-
}
2243+
set status_operation [$::main_status \
2244+
start \
2245+
[mc "Starting %s... please wait..." "git-gui"]]
2246+
2247+
after 3500 [list $status_operation stop]
22472248
}
22482249
}
22492250
2250-
proc do_explore {} {
2251-
global _gitworktree
2252-
set explorer {}
2251+
# Get the system-specific explorer app/command.
2252+
proc get_explorer {} {
22532253
if {[is_Cygwin] || [is_Windows]} {
22542254
set explorer "explorer.exe"
22552255
} elseif {[is_MacOSX]} {
@@ -2258,9 +2258,23 @@ proc do_explore {} {
22582258
# freedesktop.org-conforming system is our best shot
22592259
set explorer "xdg-open"
22602260
}
2261+
return $explorer
2262+
}
2263+
2264+
proc do_explore {} {
2265+
global _gitworktree
2266+
set explorer [get_explorer]
22612267
eval exec $explorer [list [file nativename $_gitworktree]] &
22622268
}
22632269
2270+
# Open file relative to the working tree by the default associated app.
2271+
proc do_file_open {file} {
2272+
global _gitworktree
2273+
set explorer [get_explorer]
2274+
set full_file_path [file join $_gitworktree $file]
2275+
exec $explorer [file nativename $full_file_path] &
2276+
}
2277+
22642278
set is_quitting 0
22652279
set ret_code 1
22662280
@@ -3512,9 +3526,11 @@ tlabel .vpane.lower.diff.header.file \
35123526
-justify left
35133527
tlabel .vpane.lower.diff.header.path \
35143528
-background gold \
3515-
-foreground black \
3529+
-foreground blue \
35163530
-anchor w \
3517-
-justify left
3531+
-justify left \
3532+
-font [eval font create [font configure font_ui] -underline 1] \
3533+
-cursor hand2
35183534
pack .vpane.lower.diff.header.status -side left
35193535
pack .vpane.lower.diff.header.file -side left
35203536
pack .vpane.lower.diff.header.path -fill x
@@ -3529,8 +3545,12 @@ $ctxm add command \
35293545
-type STRING \
35303546
-- $current_diff_path
35313547
}
3548+
$ctxm add command \
3549+
-label [mc Open] \
3550+
-command {do_file_open $current_diff_path}
35323551
lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
35333552
bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3553+
bind .vpane.lower.diff.header.path <Button-1> {do_file_open $current_diff_path}
35343554
35353555
# -- Diff Body
35363556
#
@@ -4159,6 +4179,9 @@ if {$picked && [is_config_true gui.autoexplore]} {
41594179
do_explore
41604180
}
41614181
4182+
# Clear "Initializing..." status
4183+
after 500 {$main_status show ""}
4184+
41624185
# Local variables:
41634186
# mode: tcl
41644187
# indent-tabs-mode: t

git-gui/lib/blame.tcl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ field w_cviewer ; # pane showing commit message
2424
field finder ; # find mini-dialog frame
2525
field gotoline ; # line goto mini-dialog frame
2626
field status ; # status mega-widget instance
27+
field status_operation ; # operation displayed by status mega-widget
2728
field old_height ; # last known height of $w.file_pane
2829

2930

@@ -274,6 +275,7 @@ constructor new {i_commit i_path i_jump} {
274275
pack $w_cviewer -expand 1 -fill both
275276

276277
set status [::status_bar::new $w.status]
278+
set status_operation {}
277279

278280
menu $w.ctxm -tearoff 0
279281
$w.ctxm add command \
@@ -602,16 +604,23 @@ method _exec_blame {cur_w cur_d options cur_s} {
602604
} else {
603605
lappend options $commit
604606
}
607+
608+
# We may recurse in from another call to _exec_blame and already have
609+
# a status operation.
610+
if {$status_operation == {}} {
611+
set status_operation [$status start \
612+
$cur_s \
613+
[mc "lines annotated"]]
614+
} else {
615+
$status_operation restart $cur_s
616+
}
617+
605618
lappend options -- $path
606619
set fd [eval git_read --nice blame $options]
607620
fconfigure $fd -blocking 0 -translation lf -encoding utf-8
608621
fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
609622
set current_fd $fd
610623
set blame_lines 0
611-
612-
$status start \
613-
$cur_s \
614-
[mc "lines annotated"]
615624
}
616625

617626
method _read_blame {fd cur_w cur_d} {
@@ -806,10 +815,11 @@ method _read_blame {fd cur_w cur_d} {
806815
[mc "Loading original location annotations..."]
807816
} else {
808817
set current_fd {}
809-
$status stop [mc "Annotation complete."]
818+
$status_operation stop [mc "Annotation complete."]
819+
set status_operation {}
810820
}
811821
} else {
812-
$status update $blame_lines $total_lines
822+
$status_operation update $blame_lines $total_lines
813823
}
814824
} ifdeleted { catch {close $fd} }
815825

@@ -1124,7 +1134,7 @@ method _blameparent {} {
11241134
set diffcmd [list diff-tree --unified=0 $cparent $cmit -- $new_path]
11251135
}
11261136
if {[catch {set fd [eval git_read $diffcmd]} err]} {
1127-
$status stop [mc "Unable to display parent"]
1137+
$status_operation stop [mc "Unable to display parent"]
11281138
error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
11291139
return
11301140
}

git-gui/lib/branch.tcl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ proc load_all_heads {} {
88
set rh_len [expr {[string length $rh] + 1}]
99
set all_heads [list]
1010
set fd [git_read for-each-ref --format=%(refname) $rh]
11+
fconfigure $fd -translation binary -encoding utf-8
1112
while {[gets $fd line] > 0} {
1213
if {!$some_heads_tracking || ![is_tracking_branch $line]} {
1314
lappend all_heads [string range $line $rh_len end]
@@ -24,6 +25,7 @@ proc load_all_tags {} {
2425
--sort=-taggerdate \
2526
--format=%(refname) \
2627
refs/tags]
28+
fconfigure $fd -translation binary -encoding utf-8
2729
while {[gets $fd line] > 0} {
2830
if {![regsub ^refs/tags/ $line {} name]} continue
2931
lappend all_tags $name

git-gui/lib/checkout_op.tcl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ method _readtree {} {
341341
global HEAD
342342

343343
set readtree_d {}
344-
$::main_status start \
344+
set status_bar_operation [$::main_status start \
345345
[mc "Updating working directory to '%s'..." [_name $this]] \
346-
[mc "files checked out"]
346+
[mc "files checked out"]]
347347

348348
set fd [git_read --stderr read-tree \
349349
-m \
@@ -354,26 +354,27 @@ method _readtree {} {
354354
$new_hash \
355355
]
356356
fconfigure $fd -blocking 0 -translation binary
357-
fileevent $fd readable [cb _readtree_wait $fd]
357+
fileevent $fd readable [cb _readtree_wait $fd $status_bar_operation]
358358
}
359359

360-
method _readtree_wait {fd} {
360+
method _readtree_wait {fd status_bar_operation} {
361361
global current_branch
362362

363363
set buf [read $fd]
364-
$::main_status update_meter $buf
364+
$status_bar_operation update_meter $buf
365365
append readtree_d $buf
366366

367367
fconfigure $fd -blocking 1
368368
if {![eof $fd]} {
369369
fconfigure $fd -blocking 0
370+
$status_bar_operation stop
370371
return
371372
}
372373

373374
if {[catch {close $fd}]} {
374375
set err $readtree_d
375376
regsub {^fatal: } $err {} err
376-
$::main_status stop [mc "Aborted checkout of '%s' (file level merging is required)." [_name $this]]
377+
$status_bar_operation stop [mc "Aborted checkout of '%s' (file level merging is required)." [_name $this]]
377378
warn_popup [strcat [mc "File level merge required."] "
378379
379380
$err
@@ -384,7 +385,7 @@ $err
384385
return
385386
}
386387

387-
$::main_status stop
388+
$status_bar_operation stop
388389
_after_readtree $this
389390
}
390391

0 commit comments

Comments
 (0)