232 ! ! |
232 ! ! |
233 |
233 |
234 !HGCommand class methodsFor:'accessing'! |
234 !HGCommand class methodsFor:'accessing'! |
235 |
235 |
236 hgCommand |
236 hgCommand |
237 "Returns absolute path to hg executable to use" |
237 "Returns hg command to use" |
238 |
238 |
239 HGExecutable isNil ifTrue:[ |
239 | command | |
240 | executable | |
240 command := HGCommandString notNil ifTrue:[ HGCommandString ] ifFalse:[UserPreferences current hgCommand]. |
241 executable := UserPreferences current hgCommand. |
241 command isNil ifTrue:[ |
242 executable isNil ifTrue:[ |
242 OperatingSystem isMSWINDOWSlike ifTrue:[ |
243 OperatingSystem isMSWINDOWSlike ifTrue:[ |
243 "/ | h | |
244 "/ | h | |
244 "/ |
245 "/ |
245 "/ h := Win32OperatingSystem registryEntry |
246 "/ h := Win32OperatingSystem registryEntry |
246 "/ key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'. |
247 "/ key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'. |
247 "/ h notNil ifTrue:[HGExecutable := h valueNamed:'']. |
248 "/ h notNil ifTrue:[HGExecutable := h valueNamed:'']. |
248 "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable] |
249 "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable] |
249 command := OperatingSystem pathOfCommand:'hg'. |
250 executable := OperatingSystem pathOfCommand:'hg'. |
250 ] ifFalse:[ |
251 ] ifFalse:[ |
251 OperatingSystem isUNIXlike ifTrue:[ |
252 OperatingSystem isUNIXlike ifTrue:[ |
252 command := OperatingSystem pathOfCommand:'hg'. |
253 executable := OperatingSystem pathOfCommand:'hg'. |
253 ] |
254 ] |
|
255 ]. |
|
256 ]. |
254 ]. |
257 executable := self hgCommandValidate: executable. |
255 ]. |
258 HGExecutable := executable. |
256 ^ command |
259 ]. |
|
260 ^ HGExecutable |
|
261 |
257 |
262 " |
258 " |
263 HGExecutable := nil. |
259 HGExecutable := nil. |
264 self basicNew executable |
260 self basicNew executable |
265 " |
261 " |
266 |
262 |
267 "Created: / 19-11-2012 / 21:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
263 "Created: / 19-11-2012 / 21:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
268 "Modified: / 21-02-2014 / 08:54:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
264 "Modified: / 17-07-2014 / 11:21:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
269 ! |
265 ! |
270 |
266 |
271 hgCommand: command |
267 hgCommand: command |
272 HGExecutable := command |
268 HGCommandString := command. |
|
269 HGExecutable := HGExecutableArguments := nil. |
273 |
270 |
274 " |
271 " |
275 HGCommand hgCommand: '/usr/src/mercurial-2.4/hg' |
272 HGCommand hgCommand: '/usr/src/mercurial-2.4/hg' |
276 HGCommand hgCommand: '/usr/bin/hg' |
273 HGCommand hgCommand: '/usr/bin/hg' |
|
274 HGCommand hgCommand: 'hg' |
|
275 HGCommand hgCommand: nil |
277 " |
276 " |
278 |
277 |
279 "Created: / 19-11-2012 / 21:49:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
278 "Created: / 19-11-2012 / 21:49:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
280 "Modified (comment): / 03-03-2013 / 12:24:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
279 "Modified: / 17-07-2014 / 11:18:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
281 ! |
280 ! |
282 |
281 |
283 hgCommandValidate: executable |
282 hgCommandValidate: command |
284 "/ Given a `executable`, checks whether it is a valid hg binary. |
283 "Given a `command`, checks whether it is a valid hg command. |
285 "/ Returns absolute path to hg binary or raise an |
284 Returns absolute path to hg binary and global arguments (if any) |
286 "/ HGInvalidExecutableError or HGInvalidVersionError |
285 or raise an HGInvalidExecutableError or HGInvalidVersionError |
287 "/ if `executable` is not valid hg binary. |
286 if `command` is not valid hg command." |
288 "/ |
287 |
289 | path version | |
288 | tokens executable executableAsFilename arguments version | |
290 |
289 |
291 path := executable asFilename. |
290 tokens := (HGCommandParser on: command readStream) parseShellCommand. |
292 path isAbsolute ifFalse:[ |
291 executable := tokens first. |
293 path := path asAbsoluteFilename. |
292 executableAsFilename := executable asFilename. |
294 path exists ifFalse:[ |
293 arguments := tokens copyFrom: 2. |
|
294 executableAsFilename isAbsolute ifFalse:[ |
|
295 executableAsFilename := executableAsFilename asAbsoluteFilename. |
|
296 executableAsFilename exists ifTrue:[ |
|
297 executable := executableAsFilename pathName. |
|
298 ] ifFalse:[ |
295 "/ Also try to find specified command along PATH, maybe somebody |
299 "/ Also try to find specified command along PATH, maybe somebody |
296 "/ just typed 'hg' in... |
300 "/ just typed 'hg' in... |
297 (executable includes: Filename separator) ifFalse:[ |
301 executable := (OperatingSystem pathOfCommand: executable). |
298 path := (OperatingSystem pathOfCommand: executable). |
302 executable isNil ifTrue:[ |
299 path isNil ifTrue:[ |
303 HGInvalidExecutableError raiseErrorString:('''hg'' executable (%1) not found!!' bindWith: command). |
300 HGInvalidExecutableError raiseErrorString:('''hg'' executable (%1) not found!!' bindWith: executable). |
304 ^ nil |
301 ^ nil |
305 ] ifFalse:[ |
302 ]. |
306 executableAsFilename := executable asFilename. |
303 ^ path |
|
304 ]. |
307 ]. |
305 ]. |
308 ] |
306 ]. |
309 ]. |
307 path exists ifFalse:[ |
310 executableAsFilename exists ifFalse:[ |
308 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) does not exists!!' bindWith: path pathName). |
311 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) does not exists!!' bindWith: executable). |
309 ^ nil |
312 ^ nil |
310 ]. |
313 ]. |
311 path isDirectory ifTrue:[ |
314 executableAsFilename isDirectory ifTrue:[ |
312 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is actually a directory!!' bindWith: path pathName). |
315 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is actually a directory!!' bindWith: executable). |
313 ^ nil |
316 ^ nil |
314 ]. |
317 ]. |
315 path isExecutable ifFalse:[ |
318 executableAsFilename isExecutable ifFalse:[ |
316 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is cannot be executed!!' bindWith: path pathName). |
319 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is cannot be executed!!' bindWith: executable). |
317 ^ nil |
320 ^ nil |
318 ]. |
321 ]. |
319 [ |
322 [ |
320 version := self hgVersionOf: path pathName. |
323 version := self hgVersionOf: executable arguments: arguments. |
321 ] on: Error do:[:ex | |
324 ] on: Error do:[:ex | |
322 HGInvalidExecutableError newException |
325 HGInvalidExecutableError newException |
323 parameter: ex; |
326 parameter: ex; |
324 messageText: 'Failed to check version: ', ex description; |
327 messageText: 'Failed to check version: ', ex description; |
325 raise. |
328 raise. |
421 |
426 |
422 "Created: / 19-03-2008 / 12:29:59 / janfrog" |
427 "Created: / 19-03-2008 / 12:29:59 / janfrog" |
423 "Modified: / 19-03-2009 / 14:00:59 / Jan Vrany <vranyj1@fel.cvut.cz>" |
428 "Modified: / 19-03-2009 / 14:00:59 / Jan Vrany <vranyj1@fel.cvut.cz>" |
424 "Modified (format): / 27-12-2011 / 16:00:13 / dundee" |
429 "Modified (format): / 27-12-2011 / 16:00:13 / dundee" |
425 "Modified: / 17-10-2012 / 13:05:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
430 "Modified: / 17-10-2012 / 13:05:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
431 ! ! |
|
432 |
|
433 !HGCommand class methodsFor:'accessing-private'! |
|
434 |
|
435 hgExecutable |
|
436 "Returns absolute path to hg executable to use" |
|
437 |
|
438 HGExecutable isNil ifTrue:[ |
|
439 | command executableAndArguments | |
|
440 command := self hgCommand. |
|
441 command isNil ifTrue:[ |
|
442 OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
443 "/ | h | |
|
444 "/ |
|
445 "/ h := Win32OperatingSystem registryEntry |
|
446 "/ key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'. |
|
447 "/ h notNil ifTrue:[HGExecutable := h valueNamed:'']. |
|
448 "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable] |
|
449 command := OperatingSystem pathOfCommand:'hg'. |
|
450 ] ifFalse:[ |
|
451 OperatingSystem isUNIXlike ifTrue:[ |
|
452 command := OperatingSystem pathOfCommand:'hg'. |
|
453 ] |
|
454 ]. |
|
455 ]. |
|
456 executableAndArguments := self hgCommandValidate: command. |
|
457 HGExecutable := executableAndArguments first. |
|
458 HGExecutableArguments := executableAndArguments second. |
|
459 ]. |
|
460 ^ HGExecutable |
|
461 |
|
462 " |
|
463 HGExecutable := nil. |
|
464 self basicNew executable |
|
465 " |
|
466 |
|
467 "Created: / 17-07-2014 / 10:16:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
468 "Modified: / 17-07-2014 / 11:21:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
469 ! |
|
470 |
|
471 hgExecutableArguments |
|
472 "Returns an array of (global) arguments to be passed hg executable" |
|
473 |
|
474 HGExecutableArguments isNil ifTrue:[ |
|
475 HGExecutable := nil. |
|
476 self hgExecutable. |
|
477 ]. |
|
478 ^ HGExecutableArguments |
|
479 |
|
480 |
|
481 |
|
482 " |
|
483 HGExecutable := nil. |
|
484 self basicNew executable |
|
485 " |
|
486 |
|
487 "Created: / 17-07-2014 / 11:16:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
426 ! ! |
488 ! ! |
427 |
489 |
428 !HGCommand class methodsFor:'commands'! |
490 !HGCommand class methodsFor:'commands'! |
429 |
491 |
430 add |
492 add |
689 environment at:'LANG' put:'C'. |
751 environment at:'LANG' put:'C'. |
690 environment at:'LC_MESSAGES' put:'C'. |
752 environment at:'LC_MESSAGES' put:'C'. |
691 |
753 |
692 exe := self executable. |
754 exe := self executable. |
693 args := self arguments. |
755 args := self arguments. |
694 |
756 |
695 OperatingSystem isMSWINDOWSlike ifTrue:[ |
757 OperatingSystem isMSWINDOWSlike ifTrue:[ |
696 (exe endsWith:'.bat') ifTrue:[ |
758 (exe endsWith:'.bat') ifTrue:[ |
697 | cmd | |
759 | cmd | |
698 cmd := OperatingSystem pathOfCommand:'cmd'. |
760 cmd := OperatingSystem pathOfCommand:'cmd'. |
699 args := #( '/C' ) , args. |
761 args := #( '/C' ) , args. |
700 exe := cmd. |
762 exe := cmd. |
701 |
763 |
702 ]. |
764 ]. |
703 args := String streamContents:[:s| |
765 args := String streamContents:[:s| |
704 args |
766 args |
705 do:[:each | s nextPut:$"; nextPutAll: each; nextPut: $"] |
767 do:[:each | s nextPut:$"; nextPutAll: each; nextPut: $"] |
706 separatedBy: [ s space ] |
768 separatedBy: [ s space ] |
707 ] |
769 ] |
819 |
881 |
820 arguments |
882 arguments |
821 |
883 |
822 ^ OrderedCollection streamContents:[:s | |
884 ^ OrderedCollection streamContents:[:s | |
823 s nextPut: self executable. |
885 s nextPut: self executable. |
|
886 s nextPutAll: self class hgExecutableArguments ? #(). |
824 s nextPut: '--noninteractive'. |
887 s nextPut: '--noninteractive'. |
825 self argumentsGlobalOn:s. |
888 self argumentsGlobalOn:s. |
826 s nextPut:self command. |
889 s nextPut:self command. |
827 self argumentsCommandOn:s. |
890 self argumentsCommandOn:s. |
828 ]. |
891 ]. |
829 |
892 |
830 "Created: / 11-05-2011 / 07:58:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
893 "Created: / 11-05-2011 / 07:58:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
831 "Modified (format): / 27-12-2011 / 15:47:23 / dundee" |
894 "Modified (format): / 27-12-2011 / 15:47:23 / dundee" |
832 "Modified: / 16-12-2012 / 00:26:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
895 "Modified: / 17-07-2014 / 15:25:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
833 ! |
896 ! |
834 |
897 |
835 argumentsCommandOn:stream |
898 argumentsCommandOn:stream |
836 "Called to get command specific options" |
899 "Called to get command specific options" |
837 |
900 |