diff -r eb0f01855893 -r 718711b15cea mercurial/HGCommand.st --- a/mercurial/HGCommand.st Sun Mar 03 12:29:14 2013 +0000 +++ b/mercurial/HGCommand.st Sun Mar 03 19:43:56 2013 +0000 @@ -12,7 +12,8 @@ "{ Package: 'stx:libscm/mercurial' }" Object subclass:#HGCommand - instanceVariableNames:'workingDirectory result error workers blocker errors' + instanceVariableNames:'workingDirectory result error errors blocker errorReader + outputReader' classVariableNames:'HGExecutable HGVersion Debugging Tracing' poolDictionaries:'' category:'SCM-Mercurial-Internal' @@ -458,6 +459,14 @@ !HGCommand methodsFor:'accessing'! +errors + ^ errors +! + +result + ^ result +! + workingDirectory ^workingDirectory notNil ifTrue:[ workingDirectory @@ -516,8 +525,8 @@ execute | stdoutPipe stdout stderrPipe stderr pid environment status args spin | - workers := OrderedCollection new. - errors := SharedQueue new. + self initialize. + blocker := (Semaphore new:-2) name: 'Waiting for hg command to finish'. stdoutPipe := NonPositionableExternalStream makePipe. stdout := stdoutPipe first. @@ -541,7 +550,7 @@ ] ]. - blocker := (Semaphore new:-2) name: 'Waiting for hg command to finish'. + Processor monitor:[ Tracing ifTrue:[ Logger log: 'cmd: executing: ' , (args isString ifTrue:[args] ifFalse:[args asStringWith:' ']) severity: #trace facility: 'HG'. @@ -572,8 +581,8 @@ stdout := stdout contents asString readStream. stderr := stderr contents asString readStream. ]. - self spawn: [ self parseError: stderr ]. - self spawn: [ result := self parseOutput: stdout ]. + self spawnErrorReaderOn: stderr. + self spawnOutputReaderOn: stdout. spin := SemaphoreSet with: blocker with: errors readSemaphore. @@ -589,15 +598,31 @@ ]. ^self status: status result: result - " - SVNv2::Command info: 'https://swing.fit.cvut.cz/svn/stx/libsvn' - " - "Created: / 11-05-2011 / 07:45:00 / Jan Vrany " "Modified: / 17-12-2011 / 19:22:00 / dundee" "Modified (format): / 27-12-2011 / 15:53:54 / dundee" "Modified: / 14-11-2012 / 13:41:57 / jv" - "Modified (format): / 04-02-2013 / 23:40:26 / Jan Vrany " + "Modified: / 03-03-2013 / 19:11:40 / Jan Vrany " +! ! + +!HGCommand methodsFor:'initialization'! + +initialize + "Invoked when a new instance is created." + + "/ please change as required (and remove this comment) + "/ workingDirectory := nil. + "/ result := nil. + "/ error := nil. + "/ workers := nil. + "/ errors := nil. + + errors := SharedQueue new. + + + "/ super initialize. -- commented since inherited method does nothing + + "Modified: / 03-03-2013 / 19:11:30 / Jan Vrany " ! ! !HGCommand methodsFor:'private'! @@ -686,24 +711,40 @@ "Modified: / 04-02-2013 / 14:14:10 / Jan Vrany " ! -spawn:aBlock +spawn:block name: name "Spawn a new background thread executing given block" | worker | - worker := [ aBlock on: Error do:[:ex|self propagate:ex] ] newProcess. - workers add: worker. + worker := [ block on: Error do:[:ex|self propagate:ex] ] newProcess. worker addExitAction:[ Tracing ifTrue:[ - Logger log: 'command parser finished' severity: #trace facility: 'HG'. + Logger log: 'cmd: worker ''', name , ''' finished' severity: #trace facility: 'HG'. ]. - blocker signal. - workers remove: worker + blocker notNil ifTrue:[blocker signal]. ]. worker resume. + worker name: name. + ^worker - "Created: / 04-02-2013 / 11:55:27 / Jan Vrany " - "Modified: / 04-02-2013 / 21:59:53 / Jan Vrany " + "Created: / 03-03-2013 / 16:56:19 / Jan Vrany " + "Modified: / 03-03-2013 / 19:12:03 / Jan Vrany " +! + +spawnErrorReaderOn: stderr + errorReader isNil ifTrue:[ + errorReader := self spawn: [ self parseError: stderr ] name: 'Error reader' + ]. + + "Created: / 03-03-2013 / 16:59:48 / Jan Vrany " +! + +spawnOutputReaderOn: stdout + outputReader isNil ifTrue:[ + outputReader := self spawn: [ result := self parseOutput: stdout ] name: 'Output reader'. + ] + + "Created: / 03-03-2013 / 17:00:17 / Jan Vrany " ! status: status result: res