git-gui: Correct ls-tree buffering problem in browser
Our file browser was showing bad output as it did not properly buffer a partial record when read from `ls-tree -z`. This did not show up on my Mac OS X system as most trees are small, the pipe buffers generally big and `ls-tree -z` was generally fast enough that all data was ready before Tcl started to read. However on my Cygwin system one of my production repositories had a large enough tree and packfile that it took a couple of pipe buffers for `ls-tree -z` to complete its dump. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jul 9, 2007 at 11:55 UTC
56e29f597c8f85b0dfee9ba7408f8d09fd5adb5a
1 file changed
+13
-9
lib/browser.tcl
+13
-9
@@ -11,6 +11,8 @@ field browser_status {Starting...}
11
field browser_stack {}
12
field browser_busy 1
13
14
+field ls_buf {}; # Buffered record output from ls-tree
15
+
16
constructor new {commit} {
17
global cursor_ptr M1B
18
make_toplevel top w
@@ -160,7 +162,7 @@ method _click {was_double_click pos} {
162
}
163
164
method _ls {tree_id {name {}}} {
163
- set browser_buffer {}
165
+ set ls_buf {}
166
set browser_files {}
167
set browser_busy 1
168
@@ -185,17 +187,19 @@ method _ls {tree_id {name {}}} {
187
}
188
189
method _read {fd} {
188
- append browser_buffer [read $fd]
189
- set pck [split $browser_buffer "\0"]
190
- set browser_buffer [lindex $pck end]
190
+ append ls_buf [read $fd]
191
+ set pck [split $ls_buf "\0"]
192
+ set ls_buf [lindex $pck end]
193
194
set n [llength $browser_files]
195
$w conf -state normal
196
foreach p [lrange $pck 0 end-1] {
195
- set info [split $p "\t"]
196
- set path [lindex $info 1]
197
- set info [split [lindex $info 0] { }]
198
- set type [lindex $info 1]
197
+ set tab [string first "\t" $p]
198
+ if {$tab == -1} continue
199
+
200
+ set info [split [string range $p 0 [expr {$tab - 1}]] { }]
201
+ set path [string range $p [expr {$tab + 1}] end]
202
+ set type [lindex $info 1]
203
set object [lindex $info 2]
204
205
switch -- $type {
@@ -225,7 +229,7 @@ method _read {fd} {
229
close $fd
230
set browser_status Ready.
231
set browser_busy 0
228
- unset browser_buffer
232
+ set ls_buf {}
233
if {$n > 0} {
234
$w tag add in_sel 1.0 2.0
235
focus -force $w