--- a/mercurial/HGCommand.st Wed Jul 09 10:06:32 2014 +0100
+++ b/mercurial/HGCommand.st Thu Jul 17 15:38:42 2014 +0100
@@ -21,7 +21,7 @@
Object subclass:#HGCommand
instanceVariableNames:'workingDirectory result error errors blocker errorReader
outputReader'
- classVariableNames:'HGExecutable HGVersion'
+ classVariableNames:'HGCommandString HGExecutable HGExecutableArguments HGVersion'
poolDictionaries:'HGDebugFlags'
category:'SCM-Mercurial-Internal'
!
@@ -181,7 +181,7 @@
!
HGCommand subclass:#version
- instanceVariableNames:'executable'
+ instanceVariableNames:'executable arguments'
classVariableNames:''
poolDictionaries:''
privateIn:HGCommand
@@ -234,30 +234,26 @@
!HGCommand class methodsFor:'accessing'!
hgCommand
- "Returns absolute path to hg executable to use"
-
- HGExecutable isNil ifTrue:[
- | executable |
- executable := UserPreferences current hgCommand.
- executable isNil ifTrue:[
- OperatingSystem isMSWINDOWSlike ifTrue:[
- "/ | h |
- "/
- "/ h := Win32OperatingSystem registryEntry
- "/ key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'.
- "/ h notNil ifTrue:[HGExecutable := h valueNamed:''].
- "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable]
- executable := OperatingSystem pathOfCommand:'hg'.
- ] ifFalse:[
- OperatingSystem isUNIXlike ifTrue:[
- executable := OperatingSystem pathOfCommand:'hg'.
- ]
- ].
+ "Returns hg command to use"
+
+ | command |
+ command := HGCommandString notNil ifTrue:[ HGCommandString ] ifFalse:[UserPreferences current hgCommand].
+ command isNil ifTrue:[
+ OperatingSystem isMSWINDOWSlike ifTrue:[
+ "/ | h |
+ "/
+ "/ h := Win32OperatingSystem registryEntry
+ "/ key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'.
+ "/ h notNil ifTrue:[HGExecutable := h valueNamed:''].
+ "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable]
+ command := OperatingSystem pathOfCommand:'hg'.
+ ] ifFalse:[
+ OperatingSystem isUNIXlike ifTrue:[
+ command := OperatingSystem pathOfCommand:'hg'.
+ ]
].
- executable := self hgCommandValidate: executable.
- HGExecutable := executable.
].
- ^ HGExecutable
+ ^ command
"
HGExecutable := nil.
@@ -265,59 +261,66 @@
"
"Created: / 19-11-2012 / 21:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 21-02-2014 / 08:54:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-07-2014 / 11:21:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
hgCommand: command
- HGExecutable := command
+ HGCommandString := command.
+ HGExecutable := HGExecutableArguments := nil.
"
HGCommand hgCommand: '/usr/src/mercurial-2.4/hg'
HGCommand hgCommand: '/usr/bin/hg'
+ HGCommand hgCommand: 'hg'
+ HGCommand hgCommand: nil
"
"Created: / 19-11-2012 / 21:49:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified (comment): / 03-03-2013 / 12:24:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-07-2014 / 11:18:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-hgCommandValidate: executable
- "/ Given a `executable`, checks whether it is a valid hg binary.
- "/ Returns absolute path to hg binary or raise an
- "/ HGInvalidExecutableError or HGInvalidVersionError
- "/ if `executable` is not valid hg binary.
- "/
- | path version |
-
- path := executable asFilename.
- path isAbsolute ifFalse:[
- path := path asAbsoluteFilename.
- path exists ifFalse:[
+hgCommandValidate: command
+ "Given a `command`, checks whether it is a valid hg command.
+ Returns absolute path to hg binary and global arguments (if any)
+ or raise an HGInvalidExecutableError or HGInvalidVersionError
+ if `command` is not valid hg command."
+
+ | tokens executable executableAsFilename arguments version |
+
+ tokens := (HGCommandParser on: command readStream) parseShellCommand.
+ executable := tokens first.
+ executableAsFilename := executable asFilename.
+ arguments := tokens copyFrom: 2.
+ executableAsFilename isAbsolute ifFalse:[
+ executableAsFilename := executableAsFilename asAbsoluteFilename.
+ executableAsFilename exists ifTrue:[
+ executable := executableAsFilename pathName.
+ ] ifFalse:[
"/ Also try to find specified command along PATH, maybe somebody
"/ just typed 'hg' in...
- (executable includes: Filename separator) ifFalse:[
- path := (OperatingSystem pathOfCommand: executable).
- path isNil ifTrue:[
- HGInvalidExecutableError raiseErrorString:('''hg'' executable (%1) not found!!' bindWith: executable).
- ^ nil
- ].
- ^ path
+ executable := (OperatingSystem pathOfCommand: executable).
+ executable isNil ifTrue:[
+ HGInvalidExecutableError raiseErrorString:('''hg'' executable (%1) not found!!' bindWith: command).
+ ^ nil
+ ] ifFalse:[
+ executableAsFilename := executable asFilename.
].
- ].
+ ]
].
- path exists ifFalse:[
- HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) does not exists!!' bindWith: path pathName).
+ executableAsFilename exists ifFalse:[
+ HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) does not exists!!' bindWith: executable).
^ nil
].
- path isDirectory ifTrue:[
- HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is actually a directory!!' bindWith: path pathName).
+ executableAsFilename isDirectory ifTrue:[
+ HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is actually a directory!!' bindWith: executable).
^ nil
].
- path isExecutable ifFalse:[
- HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is cannot be executed!!' bindWith: path pathName).
+ executableAsFilename isExecutable ifFalse:[
+ HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is cannot be executed!!' bindWith: executable).
^ nil
].
[
- version := self hgVersionOf: path pathName.
+ version := self hgVersionOf: executable arguments: arguments.
] on: Error do:[:ex |
HGInvalidExecutableError newException
parameter: ex;
@@ -332,17 +335,17 @@
raise.
^ nil
].
- ^ path pathName
+ ^ { executable . arguments }
"Created: / 21-02-2014 / 08:50:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 21-02-2014 / 10:31:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-07-2014 / 15:10:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
hgVersion
"Return mercurial version installed on this compiter"
HGVersion isNil ifTrue:[
- HGVersion := self hgVersionOf: self hgCommand
+ HGVersion := self hgVersionOf: self hgExecutable arguments: self hgExecutableArguments
].
^ HGVersion
@@ -352,6 +355,7 @@
"Created: / 19-11-2012 / 20:14:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 21-01-2013 / 05:07:58 / jv"
+ "Modified: / 17-07-2014 / 15:09:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
hgVersionIsSupported
@@ -381,18 +385,19 @@
"Created: / 19-11-2012 / 20:31:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-hgVersionOf: hgcommand
- "Return mercurial version installed on this compiter"
+hgVersionOf: executable arguments: arguments
+ "Return mercurial version if passed executable "
^version new
- executable: hgcommand;
+ executable: executable;
+ arguments: arguments;
execute
"
HGCommand hgVersion
"
- "Created: / 21-01-2013 / 05:05:01 / jv"
+ "Created: / 17-07-2014 / 15:08:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
hgVersionsSupported
@@ -425,6 +430,63 @@
"Modified: / 17-10-2012 / 13:05:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!HGCommand class methodsFor:'accessing-private'!
+
+hgExecutable
+ "Returns absolute path to hg executable to use"
+
+ HGExecutable isNil ifTrue:[
+ | command executableAndArguments |
+ command := self hgCommand.
+ command isNil ifTrue:[
+ OperatingSystem isMSWINDOWSlike ifTrue:[
+ "/ | h |
+ "/
+ "/ h := Win32OperatingSystem registryEntry
+ "/ key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'.
+ "/ h notNil ifTrue:[HGExecutable := h valueNamed:''].
+ "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable]
+ command := OperatingSystem pathOfCommand:'hg'.
+ ] ifFalse:[
+ OperatingSystem isUNIXlike ifTrue:[
+ command := OperatingSystem pathOfCommand:'hg'.
+ ]
+ ].
+ ].
+ executableAndArguments := self hgCommandValidate: command.
+ HGExecutable := executableAndArguments first.
+ HGExecutableArguments := executableAndArguments second.
+ ].
+ ^ HGExecutable
+
+ "
+ HGExecutable := nil.
+ self basicNew executable
+ "
+
+ "Created: / 17-07-2014 / 10:16:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-07-2014 / 11:21:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+hgExecutableArguments
+ "Returns an array of (global) arguments to be passed hg executable"
+
+ HGExecutableArguments isNil ifTrue:[
+ HGExecutable := nil.
+ self hgExecutable.
+ ].
+ ^ HGExecutableArguments
+
+
+
+ "
+ HGExecutable := nil.
+ self basicNew executable
+ "
+
+ "Created: / 17-07-2014 / 11:16:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!HGCommand class methodsFor:'commands'!
add
@@ -691,7 +753,7 @@
exe := self executable.
args := self arguments.
-
+
OperatingSystem isMSWINDOWSlike ifTrue:[
(exe endsWith:'.bat') ifTrue:[
| cmd |
@@ -699,7 +761,7 @@
args := #( '/C' ) , args.
exe := cmd.
- ].
+ ].
args := String streamContents:[:s|
args
do:[:each | s nextPut:$"; nextPutAll: each; nextPut: $"]
@@ -821,6 +883,7 @@
^ OrderedCollection streamContents:[:s |
s nextPut: self executable.
+ s nextPutAll: self class hgExecutableArguments ? #().
s nextPut: '--noninteractive'.
self argumentsGlobalOn:s.
s nextPut:self command.
@@ -829,7 +892,7 @@
"Created: / 11-05-2011 / 07:58:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified (format): / 27-12-2011 / 15:47:23 / dundee"
- "Modified: / 16-12-2012 / 00:26:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-07-2014 / 15:25:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
argumentsCommandOn:stream
@@ -867,9 +930,9 @@
!
executable
- ^ self class hgCommand
-
- "Modified: / 19-11-2012 / 21:48:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ ^ self class hgExecutable
+
+ "Modified: / 17-07-2014 / 10:16:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
parseError:stream
@@ -1177,7 +1240,7 @@
| pipe output pid environment sema args sout exec |
- destination notNil ifTrue:[
+ destination notNil ifTrue:[
^ super execute.
].
@@ -1246,7 +1309,7 @@
revision isNil ifTrue:[
self error:'No revision specified'
].
- destination notNil ifTrue:[
+ destination notNil ifTrue:[
stream nextPut: '-o'.
stream nextPut: destination asFilename pathName.
].
@@ -2043,6 +2106,10 @@
!HGCommand::version methodsFor:'accessing'!
+arguments:something
+ arguments := something.
+!
+
executable
^ executable notNil
ifTrue:[executable]
@@ -2059,10 +2126,10 @@
arguments
- ^ Array with: self executable with: '--version'
+ ^ (Array with: self executable) , (arguments ? #()) , #('--version')
"Created: / 19-11-2012 / 20:01:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 21-02-2014 / 00:20:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-07-2014 / 15:11:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
parseOutput:stream