97 |
97 |
98 command := anHGCommand. |
98 command := anHGCommand. |
99 anHGCommand initialize. |
99 anHGCommand initialize. |
100 blocker := command blocker. |
100 blocker := command blocker. |
101 |
101 |
|
102 anHGCommand repository: repository. |
102 self runcommand: command. |
103 self runcommand: command. |
103 |
104 |
104 anHGCommand spawn: [ |
105 anHGCommand spawn: [ |
105 status := OperatingSystem osProcessStatusClass pid:nil status: #exit code: channel_r nextLongNet core:false. |
106 status := OperatingSystem osProcessStatusClass pid:nil status: #exit code: channel_r nextLongNet core:false. |
106 Tracing ifTrue:[ |
107 |
107 Logger log: 'cmdserver: result code reader finished' severity: #trace facility: 'HG'. |
|
108 ]. |
|
109 channel_e close. |
108 channel_e close. |
110 channel_o close. |
109 channel_o close. |
|
110 command outputReader isNil ifTrue:[ |
|
111 blocker signal |
|
112 ]. |
|
113 command errorReader isNil ifTrue:[ |
|
114 blocker signal |
|
115 ]. |
111 Tracing ifTrue:[ |
116 Tracing ifTrue:[ |
112 Logger log: 'cmdserver: result code reader finished' severity: #trace facility: 'HG'. |
117 Logger log: 'cmdsrv: command finished' severity: #trace facility: 'HG'. |
113 ]. |
118 ]. |
114 blocker signal. |
|
115 ] name: 'command server result reader'. |
119 ] name: 'command server result reader'. |
116 spin := SemaphoreSet with: blocker with: anHGCommand errors readSemaphore. |
120 spin := SemaphoreSet with: blocker with: anHGCommand errors readSemaphore. |
117 |
121 |
118 [ |
122 [ |
119 [ spin wait ~~ blocker ] whileTrue:[ anHGCommand signal ] |
123 [ spin wait ~~ blocker ] whileTrue:[ anHGCommand signal ] |
159 |
163 |
160 arguments |
164 arguments |
161 ^{ |
165 ^{ |
162 HGCommand hgCommand . |
166 HGCommand hgCommand . |
163 "/ '--debug' . '--verbose'. |
167 "/ '--debug' . '--verbose'. |
164 '--repository' . repository pathName . |
168 '--cwd' . repository pathName . |
165 '--config' . 'ui.interactive=True' . |
169 '--config' . 'ui.interactive=True' . |
166 'serve' . |
170 'serve' . |
167 '--cmdserver' . 'pipe' . |
171 '--cmdserver' . 'pipe' . |
168 } |
172 } |
169 |
173 |
170 "Created: / 24-02-2013 / 12:02:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
174 "Created: / 24-02-2013 / 12:02:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
171 "Modified: / 03-03-2013 / 12:21:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
175 "Modified: / 03-03-2013 / 23:12:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
172 ! |
176 ! |
173 |
177 |
174 channelWithId: channelId |
178 channelWithId: channelId |
175 channelId == $o codePoint ifTrue:[ |
179 channelId == $o codePoint ifTrue:[ |
176 ^ channel_o |
180 ^ channel_o |
203 |
207 |
204 | label | |
208 | label | |
205 |
209 |
206 state := #connecting. |
210 state := #connecting. |
207 Tracing ifTrue:[ |
211 Tracing ifTrue:[ |
208 Logger log: 'cmdserver: connecting...' severity: #trace facility: 'HG'. |
212 Logger log: 'cmdsrv: connecting...' severity: #trace facility: 'HG'. |
209 ]. |
213 ]. |
210 label := channel_o next: 13. |
214 label := channel_o next: 13. |
211 label = 'capabilities:' ifFalse:[ |
215 label = 'capabilities:' ifFalse:[ |
212 HGCommandError raiseErrorString: 'Invalid hello message: ', label. |
216 HGCommandError raiseErrorString: 'Invalid hello message: ', label. |
213 ]. |
217 ]. |
217 HGCommandError raiseErrorString: 'Expected ''encoding:'' message, got: ''', label , ''''. |
221 HGCommandError raiseErrorString: 'Expected ''encoding:'' message, got: ''', label , ''''. |
218 ]. |
222 ]. |
219 encoder := CharacterEncoder encoderFor: (channel_o nextAvailable: 1000). |
223 encoder := CharacterEncoder encoderFor: (channel_o nextAvailable: 1000). |
220 state := #connected. |
224 state := #connected. |
221 Tracing ifTrue:[ |
225 Tracing ifTrue:[ |
222 Logger log: 'cmdserver: connected...' severity: #trace facility: 'HG'. |
226 Logger log: 'cmdsrv: connected...' severity: #trace facility: 'HG'. |
223 ]. |
227 ]. |
224 |
228 |
225 "Created: / 24-02-2013 / 12:19:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
229 "Created: / 24-02-2013 / 12:19:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
226 "Modified: / 03-03-2013 / 12:10:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
230 "Modified: / 03-03-2013 / 23:25:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
227 ! |
231 ! |
228 |
232 |
229 runcommand: anHGCommand |
233 runcommand: anHGCommand |
230 "Issue runcommand command to the server" |
234 "Issue runcommand command to the server" |
231 |
235 |
232 | args argslen | |
236 | args argslen | |
233 |
237 |
234 args := OrderedCollection streamContents:[:s| |
238 args := OrderedCollection streamContents:[:s| |
|
239 anHGCommand workingDirectory notNil ifTrue:[ |
|
240 s nextPut: '--cwd'; nextPut: anHGCommand workingDirectory. |
|
241 ]. |
235 anHGCommand argumentsGlobalOn:s. |
242 anHGCommand argumentsGlobalOn:s. |
236 s nextPut:anHGCommand command. |
243 s nextPut:anHGCommand command. |
237 anHGCommand argumentsCommandOn:s. |
244 anHGCommand argumentsCommandOn:s. |
238 ]. |
245 ]. |
239 argslen := args inject: -1 into: [:l :a|l + a size + 1]. |
246 argslen := args inject: -1 into: [:l :a|l + a size + 1]. |
240 |
247 |
241 output |
248 output |
242 nextPutLine:'runcommand'; |
249 nextPutLine:'runcommand'; |
243 nextPutLongNet: argslen. |
250 nextPutLongNet: argslen. |
|
251 |
|
252 Tracing ifTrue:[ |
|
253 Logger log: 'cmdsrv: runcommand: ' , (args asStringWith:Character space) severity: #trace facility: 'HG'. |
|
254 ]. |
244 args |
255 args |
245 do:[:e|output nextPutAll: (encoder encodeString: e)] |
256 do:[:e|output nextPutAll: (encoder encodeString: e)] |
246 separatedBy:[output nextPut: (Character codePoint: 0)]. |
257 separatedBy:[output nextPut: (Character codePoint: 0)]. |
247 |
258 |
248 "Created: / 03-03-2013 / 16:38:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
259 "Created: / 03-03-2013 / 16:38:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
260 "Modified: / 03-03-2013 / 23:46:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
249 ! |
261 ! |
250 |
262 |
251 startReaderWriter |
263 startReaderWriter |
252 |
264 |
253 "Initialize channels" |
265 "Initialize channels" |
346 fileDescriptors:{outputPipe first fileDescriptor . inputPipe second fileDescriptor . 3} |
358 fileDescriptors:{outputPipe first fileDescriptor . inputPipe second fileDescriptor . 3} |
347 fork:true |
359 fork:true |
348 newPgrp:false |
360 newPgrp:false |
349 inDirectory: Filename currentDirectory pathName. |
361 inDirectory: Filename currentDirectory pathName. |
350 Tracing ifTrue:[ |
362 Tracing ifTrue:[ |
351 Logger log: 'cmdserver: server started' severity: #trace facility: 'HG'. |
363 Logger log: 'cmdsrv: server started' severity: #trace facility: 'HG'. |
352 ]. |
364 ]. |
353 pid. |
365 pid. |
354 ] action:[:stat | |
366 ] action:[:stat | |
355 Tracing ifTrue:[ |
367 Tracing ifTrue:[ |
356 Logger log: 'cmdserver: server terminated' severity: #trace facility: 'HG'. |
368 Logger log: 'cmdsrv: server terminated' severity: #trace facility: 'HG'. |
357 ]. |
369 ]. |
358 ]. |
370 ]. |
359 |
371 |
360 |
372 |
361 inputPipe second close. |
373 inputPipe second close. |
370 encoder := CharacterEncoder encoderFor:#ascii. |
382 encoder := CharacterEncoder encoderFor:#ascii. |
371 self startReaderWriter. |
383 self startReaderWriter. |
372 self connect. |
384 self connect. |
373 |
385 |
374 "Created: / 24-02-2013 / 11:40:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
386 "Created: / 24-02-2013 / 11:40:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
375 "Modified: / 03-03-2013 / 14:15:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
387 "Modified: / 03-03-2013 / 23:25:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
376 ! |
388 ! |
377 |
389 |
378 stop |
390 stop |
379 state == #disconnected ifFalse:[ |
391 state == #disconnected ifFalse:[ |
380 Tracing ifTrue:[ |
392 Tracing ifTrue:[ |
503 "Modified: 19.8.1997 / 17:53:11 / cg" |
515 "Modified: 19.8.1997 / 17:53:11 / cg" |
504 ! |
516 ! |
505 |
517 |
506 trace: message |
518 trace: message |
507 HGCommandServer trace ifTrue:[ |
519 HGCommandServer trace ifTrue:[ |
508 Logger log: ('cmserver-ichannel[', id, '] {', Processor activeProcess id printString, '}: ', message) severity: #trace facility: 'HG'. |
520 Logger log: ('cmdsrv-ichannel[', id, '] {', Processor activeProcess id printString, '}: ', message) severity: #trace facility: 'HG'. |
509 ] |
521 ] |
510 |
522 |
511 "Created: / 03-03-2013 / 18:06:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
523 "Created: / 03-03-2013 / 18:06:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
512 "Modified: / 03-03-2013 / 19:34:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
524 "Modified: / 03-03-2013 / 23:19:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
513 ! ! |
525 ! ! |
514 |
526 |
515 !HGCommandServer::InputChannel methodsFor:'reading'! |
527 !HGCommandServer::InputChannel methodsFor:'reading'! |
516 |
528 |
517 next |
529 next |