1717use ConsoleHelpers \SVNBuddy \Process \IProcessFactory ;
1818use Symfony \Component \Console \Output \OutputInterface ;
1919use Symfony \Component \Process \Exception \ProcessFailedException ;
20+ use Symfony \Component \Process \Exception \ProcessTimedOutException ;
2021use Symfony \Component \Process \Process ;
2122
2223class Command
2324{
2425
25- const IDLE_TIMEOUT = 180 ; // 3 minutes .
26+ const IDLE_TIMEOUT = 60 ; // 1 minute .
2627
2728 /**
2829 * Process factory.
@@ -73,6 +74,13 @@ class Command
7374 */
7475 private $ _cacheOverwrite = false ;
7576
77+ /**
78+ * Indicates whether idle timeout recovery is enabled.
79+ *
80+ * @var boolean
81+ */
82+ private $ _idleTimeoutRecovery = false ;
83+
7684 /**
7785 * Creates a command instance.
7886 *
@@ -135,6 +143,20 @@ public function setCacheOverwrite($cache_overwrite)
135143 return $ this ;
136144 }
137145
146+ /**
147+ * Set idle timeout recovery.
148+ *
149+ * @param boolean $idle_timeout_recovery Idle timeout recovery.
150+ *
151+ * @return self
152+ */
153+ public function setIdleTimeoutRecovery ($ idle_timeout_recovery )
154+ {
155+ $ this ->_idleTimeoutRecovery = $ idle_timeout_recovery ;
156+
157+ return $ this ;
158+ }
159+
138160 /**
139161 * Runs the command.
140162 *
@@ -212,6 +234,7 @@ private function _getCacheKey()
212234 *
213235 * @return string
214236 * @throws RepositoryCommandException When command execution failed.
237+ * @throws ProcessTimedOutException When process timed-out with general timeout type.
215238 */
216239 private function _doRun ($ callback = null )
217240 {
@@ -236,13 +259,15 @@ private function _doRun($callback = null)
236259 $ process ->mustRun ($ callback );
237260 }
238261
239- $ output = (string )$ process ->getOutput ();
240-
241- if ( $ this ->_io ->isDebug () ) {
242- $ this ->_io ->writeln ($ output , OutputInterface::OUTPUT_RAW );
262+ return $ this ->getProcessOutput ($ process );
263+ }
264+ catch ( ProcessTimedOutException $ e ) {
265+ // This happens for "svn log --use-merge-history ..." command when we've got all the output already.
266+ if ( $ this ->_idleTimeoutRecovery && $ e ->isIdleTimeout () ) {
267+ return $ this ->getProcessOutput ($ process );
243268 }
244269
245- return $ output ;
270+ throw $ e ;
246271 }
247272 catch ( ProcessFailedException $ e ) {
248273 throw new RepositoryCommandException (
@@ -252,6 +277,24 @@ private function _doRun($callback = null)
252277 }
253278 }
254279
280+ /**
281+ * Returns process output.
282+ *
283+ * @param Process $process Process.
284+ *
285+ * @return string
286+ */
287+ protected function getProcessOutput (Process $ process )
288+ {
289+ $ output = (string )$ process ->getOutput ();
290+
291+ if ( $ this ->_io ->isDebug () ) {
292+ $ this ->_io ->writeln ($ output , OutputInterface::OUTPUT_RAW );
293+ }
294+
295+ return $ output ;
296+ }
297+
255298 /**
256299 * Runs an svn command and displays output in real time.
257300 *
0 commit comments