Code

git-gui: Corrected diff-index/diff-files protocol parsing errors.
authorShawn O. Pearce <spearce@spearce.org>
Tue, 7 Nov 2006 23:34:09 +0000 (18:34 -0500)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 8 Nov 2006 04:48:20 +0000 (23:48 -0500)
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>
git-gui

diff --git a/git-gui b/git-gui
index 4aa035a6c4536d266f21ec41d131ecbd9651fe6f..48e1c5601f813826f1abcf832d3ea6419254c559 100755 (executable)
--- a/git-gui
+++ b/git-gui
@@ -111,6 +111,7 @@ proc read_refresh {fd final} {
        global gitdir PARENT commit_type
        global ui_index ui_other ui_status_value ui_comm
        global status_active file_states
+       global buf_rdi buf_rdf buf_rlo
 
        read $fd
        if {![eof $fd]} return
@@ -123,6 +124,10 @@ proc read_refresh {fd final} {
                lappend ls_others "--exclude-from=$info_exclude"
        }
 
+       set buf_rdi {}
+       set buf_rdf {}
+       set buf_rlo {}
+
        set status_active 3
        set ui_status_value {Scanning for modified files ...}
        set fd_di [open "| git diff-index --cached -z $PARENT" r]
@@ -158,13 +163,28 @@ proc read_diff_index {fd final} {
        global buf_rdi
 
        append buf_rdi [read $fd]
-       set pck [split $buf_rdi "\0"]
-       set buf_rdi [lindex $pck end]
-       foreach {m p} [lrange $pck 0 end-1] {
-               if {$m != {} && $p != {}} {
-                       display_file $p [string index $m end]_
-               }
+       set c 0
+       set n [string length $buf_rdi]
+       while {$c < $n} {
+               set z1 [string first "\0" $buf_rdi $c]
+               if {$z1 == -1} break
+               incr z1
+               set z2 [string first "\0" $buf_rdi $z1]
+               if {$z2 == -1} break
+
+               set c $z2
+               incr z2 -1
+               display_file \
+                       [string range $buf_rdi $z1 $z2] \
+                       [string index $buf_rdi [expr $z1 - 2]]_
+               incr c
+       }
+       if {$c < $n} {
+               set buf_rdi [string range $buf_rdi $c end]
+       } else {
+               set buf_rdi {}
        }
+
        status_eof $fd buf_rdi $final
 }
 
@@ -172,13 +192,28 @@ proc read_diff_files {fd final} {
        global buf_rdf
 
        append buf_rdf [read $fd]
-       set pck [split $buf_rdf "\0"]
-       set buf_rdf [lindex $pck end]
-       foreach {m p} [lrange $pck 0 end-1] {
-               if {$m != {} && $p != {}} {
-                       display_file $p _[string index $m end]
-               }
+       set c 0
+       set n [string length $buf_rdf]
+       while {$c < $n} {
+               set z1 [string first "\0" $buf_rdf $c]
+               if {$z1 == -1} break
+               incr z1
+               set z2 [string first "\0" $buf_rdf $z1]
+               if {$z2 == -1} break
+
+               set c $z2
+               incr z2 -1
+               display_file \
+                       [string range $buf_rdf $z1 $z2] \
+                       _[string index $buf_rdf [expr $z1 - 2]]
+               incr c
+       }
+       if {$c < $n} {
+               set buf_rdf [string range $buf_rdf $c end]
+       } else {
+               set buf_rdf {}
        }
+
        status_eof $fd buf_rdf $final
 }