@matheusbsbs / matheus-bagliano / commits / b79223064e
Fork 0

git-gui: Show a progress meter for checking out files

Sometimes switching between branches can take more than a second or two, in which case `git checkout` would normally have shown a small progress meter to the user on the terminal to let them know that we are in fact working, and give them a reasonable idea of when we may finish. We now do obtain that progress meter from read-tree -v and include it in our main window's status bar. This allows users to see how many files we have checked out, how many remain, and what percentage of the operation is completed. It should help to keep users from getting bored during a large checkout operation. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jul 8, 2007 at 22:48 UTC b79223064e163aa0ce7f5b63d12158e87f8729e4
2 files changed +55 -18
lib/checkout_op.tcl
+35 -16
@@ -19,6 +19,7 @@ field create 0; # create the branch if it doesn't exist?
19 field reset_ok 0; # did the user agree to reset?
20 field fetch_ok 0; # did the fetch succeed?
21
22 +field readtree_d {}; # buffered output from read-tree
23 field update_old {}; # was the update-ref call deferred?
24 field reflog_msg {}; # log message for the update-ref call
25
@@ -309,51 +310,69 @@ method _name {} {
310 method _readtree {} {
311 global HEAD
312
312 - ui_status "Updating working directory to '[_name $this]'..."
313 + set readtree_d {}
314 + $::main_status start \
315 + "Updating working directory to '[_name $this]'..." \
316 + {files checked out}
317 +
318 set cmd [list git read-tree]
319 lappend cmd -m
320 lappend cmd -u
321 + lappend cmd -v
322 lappend cmd --exclude-per-directory=.gitignore
323 lappend cmd $HEAD
324 lappend cmd $new_hash
319 - set fd [open "| $cmd" r]
325 +
326 + if {[catch {
327 + set fd [open "| $cmd 2>@1" r]
328 + } err]} {
329 + # Older versions of Tcl 8.4 don't have this 2>@1 IO
330 + # redirect operator. Fallback to |& cat for those.
331 + #
332 + set fd [open "| $cmd |& cat" r]
333 + }
334 +
335 fconfigure $fd -blocking 0 -translation binary
336 fileevent $fd readable [cb _readtree_wait $fd]
337 }
338
339 method _readtree_wait {fd} {
325 - global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
326 - global current_branch is_detached
327 - global ui_comm
340 + global current_branch
341 +
342 + set buf [read $fd]
343 + $::main_status update_meter $buf
344 + append readtree_d $buf
345
329 - # -- We never get interesting output on stdout; only stderr.
330 - #
331 - read $fd
346 fconfigure $fd -blocking 1
347 if {![eof $fd]} {
348 fconfigure $fd -blocking 0
349 return
350 }
351
338 - set name [_name $this]
339 -
340 - # -- The working directory wasn't in sync with the index and
341 - # we'd have to overwrite something to make the switch. A
342 - # merge is required.
343 - #
344 - if {[catch {close $fd} err]} {
352 + if {[catch {close $fd}]} {
353 + set err $readtree_d
354 regsub {^fatal: } $err {} err
355 + $::main_status stop "Aborted checkout of '[_name $this]' (file level merging is required)."
356 warn_popup "File level merge required.
357
358 $err
359
360 Staying on branch '$current_branch'."
351 - ui_status "Aborted checkout of '$name' (file level merging is required)."
361 unlock_index
362 delete_this
363 return
364 }
365
366 + $::main_status stop
367 + _after_readtree $this
368 +}
369 +
370 +method _after_readtree {} {
371 + global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
372 + global current_branch is_detached
373 + global ui_comm
374 +
375 + set name [_name $this]
376 set log "checkout: moving"
377 if {!$is_detached} {
378 append log " from $current_branch"
lib/status_bar.tcl
+20 -2
@@ -9,6 +9,7 @@ field w_c ; # canvas we draw a progress bar into
9 field status {}; # single line of text we show
10 field prefix {}; # text we format into status
11 field units {}; # unit of progress
12 +field meter {}; # current core git progress meter (if active)
13
14 constructor new {path} {
15 set w $path
@@ -45,6 +46,7 @@ method start {msg uds} {
46 set status $msg
47 set prefix $msg
48 set units $uds
49 + set meter {}
50 }
51
52 method update {have total} {
@@ -58,9 +60,25 @@ method update {have total} {
60 $w_c coords bar 0 0 $pdone 20
61 }
62
61 -method stop {msg} {
63 +method update_meter {buf} {
64 + append meter $buf
65 + set r [string last "\r" $meter]
66 + if {$r == -1} {
67 + return
68 + }
69 +
70 + set prior [string range $meter 0 $r]
71 + set meter [string range $meter [expr {$r + 1}] end]
72 + if {[regexp "\\((\\d+)/(\\d+)\\)\\s+done\r\$" $prior _j a b]} {
73 + update $this $a $b
74 + }
75 +}
76 +
77 +method stop {{msg {}}} {
78 destroy $w_c
63 - set status $msg
79 + if {$msg ne {}} {
80 + set status $msg
81 + }
82 }
83
84 method show {msg {test {}}} {