git-gui: Corrected diff-index/diff-files protocol parsing errors.
When we were receiving a lot of output from diff-index we split records at the wrong locations and started using the file status information (mode and SHA1s) as path names, and then proceeded to try to use part of the path names as status data. This caused all sorts of havoc. So I rewrote the parsing implementation to scan for the pair of null bytes along the buffer and stop scanning (waiting for more data) if both can't be found during this event. This seems to work well under high load (like when processing 6,983 added files). Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 7, 2006 at 18:34 UTC
868c8752451c0b75502a0134068f0cfe055eb7ad
1 file changed
+47
-12
git-gui
+47
-12
@@ -111,6 +111,7 @@ proc read_refresh {fd final} {
111
global gitdir PARENT commit_type
112
global ui_index ui_other ui_status_value ui_comm
113
global status_active file_states
114
+ global buf_rdi buf_rdf buf_rlo
115
116
read $fd
117
if {![eof $fd]} return
@@ -123,6 +124,10 @@ proc read_refresh {fd final} {
124
lappend ls_others "--exclude-from=$info_exclude"
125
}
126
127
+ set buf_rdi {}
128
+ set buf_rdf {}
129
+ set buf_rlo {}
130
+
131
set status_active 3
132
set ui_status_value {Scanning for modified files ...}
133
set fd_di [open "| git diff-index --cached -z $PARENT" r]
@@ -158,13 +163,28 @@ proc read_diff_index {fd final} {
163
global buf_rdi
164
165
append buf_rdi [read $fd]
161
- set pck [split $buf_rdi "\0"]
162
- set buf_rdi [lindex $pck end]
163
- foreach {m p} [lrange $pck 0 end-1] {
164
- if {$m != {} && $p != {}} {
165
- display_file $p [string index $m end]_
166
- }
166
+ set c 0
167
+ set n [string length $buf_rdi]
168
+ while {$c < $n} {
169
+ set z1 [string first "\0" $buf_rdi $c]
170
+ if {$z1 == -1} break
171
+ incr z1
172
+ set z2 [string first "\0" $buf_rdi $z1]
173
+ if {$z2 == -1} break
174
+
175
+ set c $z2
176
+ incr z2 -1
177
+ display_file \
178
+ [string range $buf_rdi $z1 $z2] \
179
+ [string index $buf_rdi [expr $z1 - 2]]_
180
+ incr c
181
+ }
182
+ if {$c < $n} {
183
+ set buf_rdi [string range $buf_rdi $c end]
184
+ } else {
185
+ set buf_rdi {}
186
}
187
+
188
status_eof $fd buf_rdi $final
189
}
190
@@ -172,13 +192,28 @@ proc read_diff_files {fd final} {
192
global buf_rdf
193
194
append buf_rdf [read $fd]
175
- set pck [split $buf_rdf "\0"]
176
- set buf_rdf [lindex $pck end]
177
- foreach {m p} [lrange $pck 0 end-1] {
178
- if {$m != {} && $p != {}} {
179
- display_file $p _[string index $m end]
180
- }
195
+ set c 0
196
+ set n [string length $buf_rdf]
197
+ while {$c < $n} {
198
+ set z1 [string first "\0" $buf_rdf $c]
199
+ if {$z1 == -1} break
200
+ incr z1
201
+ set z2 [string first "\0" $buf_rdf $z1]
202
+ if {$z2 == -1} break
203
+
204
+ set c $z2
205
+ incr z2 -1
206
+ display_file \
207
+ [string range $buf_rdf $z1 $z2] \
208
+ _[string index $buf_rdf [expr $z1 - 2]]
209
+ incr c
210
+ }
211
+ if {$c < $n} {
212
+ set buf_rdf [string range $buf_rdf $c end]
213
+ } else {
214
+ set buf_rdf {}
215
}
216
+
217
status_eof $fd buf_rdf $final
218
}
219