Improve command line code to pull everything at once.
authorEdward Z. Yang <edwardzyang@thewritingpot.com>
Sun, 27 Jul 2008 07:19:25 +0000 (27 01:19 -0600)
committerEdward Z. Yang <edwardzyang@thewritingpot.com>
Sun, 27 Jul 2008 07:19:25 +0000 (27 01:19 -0600)
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
library/Git.php

index 25f85ad..ac91fa5 100644 (file)
@@ -100,29 +100,19 @@ class Git
             );
             $pipes = array();
             $proc = proc_open($command, $pipes_template, $pipes);
+            // Input
             fwrite($pipes[0], $istream);
             fclose($pipes[0]);
-            $stderr = $stdout = '';
-            while (true) {
-                $read = array($pipes[1]);
-                $except = $write = null;
-                $n = stream_select($read, $write, $except, 30);
-                if ($n === 0) {
-                    throw new Git_Exception('Process timed out');
-                } elseif ($n > 0) {
-                    $errLine = fread($pipes[2], 8192);
-                    $outLine = fread($pipes[1], 8192);
-                    $stderr .= $errLine;
-                    $stdout .= $outLine;
-                    if ($errLine === '' && $outLine === '') {
-                        fclose($pipes[1]);
-                        fclose($pipes[2]);
-                        break;
-                    }
-                }
-            }
+            // Output
+            $stdout = stream_get_contents($pipes[1]);
+            fclose($pipes[1]);
+            // Error
+            $stderr = stream_get_contents($pipes[2]);
+            fclose($pipes[2]);
+            // Status
             $status = trim(fread($pipes[3], 5));
             fclose($pipes[3]);
+            // Cleanup
             $close = proc_close($proc);
             if (empty($code)) $status = $close;
         }