mercurial/HGCommand.st
changeset 395 fc0607653d8a
parent 372 5acd6d915c77
parent 391 f05648d15add
child 399 abafe12d47d6
equal deleted inserted replaced
372:5acd6d915c77 395:fc0607653d8a
    73 	classVariableNames:''
    73 	classVariableNames:''
    74 	poolDictionaries:''
    74 	poolDictionaries:''
    75 	privateIn:HGCommand
    75 	privateIn:HGCommand
    76 !
    76 !
    77 
    77 
       
    78 HGCommand subclass:#init
       
    79 	instanceVariableNames:'path'
       
    80 	classVariableNames:''
       
    81 	poolDictionaries:''
       
    82 	privateIn:HGCommand
       
    83 !
       
    84 
    78 HGCommand subclass:#locate
    85 HGCommand subclass:#locate
    79 	instanceVariableNames:'revision'
    86 	instanceVariableNames:'revision'
    80 	classVariableNames:''
    87 	classVariableNames:''
    81 	poolDictionaries:''
    88 	poolDictionaries:''
    82 	privateIn:HGCommand
    89 	privateIn:HGCommand
   211 ! !
   218 ! !
   212 
   219 
   213 !HGCommand class methodsFor:'accessing'!
   220 !HGCommand class methodsFor:'accessing'!
   214 
   221 
   215 hgCommand
   222 hgCommand
   216     | h |
   223     "Returns absolute path to hg executable to use"
   217 
   224 
   218     HGExecutable notNil ifTrue:[
       
   219         ^ HGExecutable
       
   220     ].
       
   221     HGExecutable := UserPreferences current hgCommand.
       
   222     HGExecutable isNil ifTrue:[
   225     HGExecutable isNil ifTrue:[
   223         OperatingSystem isMSWINDOWSlike ifTrue:[
   226         | executable |
   224             "/        h := Win32OperatingSystem registryEntry
   227         executable :=  UserPreferences current hgCommand.
   225             "/                key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'.
   228         executable isNil ifTrue:[ 
   226             "/        h notNil ifTrue:[HGExecutable := h valueNamed:''].
   229             OperatingSystem isMSWINDOWSlike ifTrue:[
   227             "/        HGExecutable notEmptyOrNil ifTrue:[^HGExecutable]
   230                 "/        | h |
   228             HGExecutable := OperatingSystem pathOfCommand:'hg'.
   231                 "/ 
   229         ] ifFalse:[
   232                 "/        h := Win32OperatingSystem registryEntry
   230             OperatingSystem isUNIXlike ifTrue:[
   233                 "/                key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'.
   231                 HGExecutable := OperatingSystem pathOfCommand:'hg'.
   234                 "/        h notNil ifTrue:[HGExecutable := h valueNamed:''].
   232             ]
   235                 "/        HGExecutable notEmptyOrNil ifTrue:[^HGExecutable]
       
   236                 executable := OperatingSystem pathOfCommand:'hg'.
       
   237             ] ifFalse:[
       
   238                 OperatingSystem isUNIXlike ifTrue:[
       
   239                     executable := OperatingSystem pathOfCommand:'hg'.
       
   240                 ]
       
   241             ].
   233         ].
   242         ].
   234     ].
   243         executable := self hgCommandValidate: executable.            
   235     HGExecutable isNil ifTrue:[
   244         HGExecutable := executable. 
   236         self error:'''hg'' executable not found!!'.
       
   237     ].
   245     ].
   238     ^ HGExecutable
   246     ^ HGExecutable
   239 
   247 
   240     "
   248     "
   241      HGExecutable := nil.
   249      HGExecutable := nil.
   242      self basicNew executable"
   250      self basicNew executable
       
   251     "
   243 
   252 
   244     "Created: / 19-11-2012 / 21:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   253     "Created: / 19-11-2012 / 21:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   245     "Modified: / 19-11-2012 / 23:21:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   254     "Modified: / 21-02-2014 / 08:54:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   246 !
   255 !
   247 
   256 
   248 hgCommand: command
   257 hgCommand: command
   249     HGExecutable := command
   258     HGExecutable := command
   250 
   259 
   253     HGCommand hgCommand: '/usr/bin/hg'
   262     HGCommand hgCommand: '/usr/bin/hg'
   254     "
   263     "
   255 
   264 
   256     "Created: / 19-11-2012 / 21:49:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   265     "Created: / 19-11-2012 / 21:49:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   257     "Modified (comment): / 03-03-2013 / 12:24:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   266     "Modified (comment): / 03-03-2013 / 12:24:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   267 !
       
   268 
       
   269 hgCommandValidate: executable
       
   270     "/ Given a `executable`, checks whether it is a valid hg binary.
       
   271     "/ Returns absolute path to hg binary or raise an
       
   272     "/ HGInvalidExecutableError or HGInvalidVersionError 
       
   273     "/ if `executable` is not valid hg binary.
       
   274     "/ 
       
   275     | path version |
       
   276 
       
   277     path := executable asFilename.
       
   278     path isAbsolute ifFalse:[ 
       
   279         path := path asAbsoluteFilename.
       
   280         path exists ifFalse:[ 
       
   281             "/ Also try to find specified command along PATH, maybe somebody
       
   282             "/ just typed 'hg' in...
       
   283             (executable includes: Filename separator) ifFalse:[
       
   284                 path  := (OperatingSystem pathOfCommand: executable).
       
   285                 path isNil ifTrue:[
       
   286                     HGInvalidExecutableError raiseErrorString:('''hg'' executable (%1) not found!!' bindWith: executable).
       
   287                     ^ nil
       
   288                 ].
       
   289                 ^ path
       
   290             ].
       
   291         ].
       
   292     ].
       
   293     path exists ifFalse:[
       
   294         HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) does not exists!!' bindWith: path pathName).
       
   295         ^ nil
       
   296     ].
       
   297     path isDirectory ifTrue:[ 
       
   298         HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is actually a directory!!' bindWith: path pathName).
       
   299         ^ nil
       
   300     ].
       
   301     path isExecutable ifFalse:[ 
       
   302         HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is cannot be executed!!' bindWith: path pathName).
       
   303         ^ nil
       
   304     ].
       
   305     [ 
       
   306         version := self hgVersionOf: path pathName.  
       
   307     ] on: Error do:[:ex |
       
   308         HGInvalidExecutableError newException
       
   309             parameter: ex;
       
   310             messageText: 'Failed to check version: ', ex description;
       
   311             raise.
       
   312         ^ nil
       
   313     ].
       
   314     (self hgVersionIsSupported: version) ifFalse:[ 
       
   315         HGInvalidVersionError newException
       
   316             parameter: version;
       
   317             messageText: ('Unsuported Mercurial version (%1)' bindWith: (version asStringWith:$.));
       
   318             raise.
       
   319         ^ nil
       
   320     ].
       
   321     ^ path pathName
       
   322 
       
   323     "Created: / 21-02-2014 / 08:50:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   324     "Modified: / 21-02-2014 / 10:31:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   258 !
   325 !
   259 
   326 
   260 hgVersion
   327 hgVersion
   261     "Return mercurial version installed on this compiter"
   328     "Return mercurial version installed on this compiter"
   262 
   329 
   380     ^heads new
   447     ^heads new
   381 
   448 
   382     "Created: / 27-11-2012 / 21:32:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   449     "Created: / 27-11-2012 / 21:32:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   383 !
   450 !
   384 
   451 
       
   452 init
       
   453     ^init new
       
   454 
       
   455     "Created: / 13-02-2014 / 12:37:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   456 !
       
   457 
   385 locate
   458 locate
   386     ^locate new
   459     ^locate new
   387 
   460 
   388     "Created: / 16-11-2012 / 22:36:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   461     "Created: / 16-11-2012 / 22:36:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   389 !
   462 !
   461         url: url;
   534         url: url;
   462         path: stringOfFilename asFilename asAbsoluteFilename pathName;
   535         path: stringOfFilename asFilename asAbsoluteFilename pathName;
   463         execute
   536         execute
   464 
   537 
   465     "Created: / 01-10-2012 / 00:06:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   538     "Created: / 01-10-2012 / 00:06:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   539 !
       
   540 
       
   541 init: aStringOrFilename
       
   542     ^ self init path: aStringOrFilename; yourself
       
   543 
       
   544     "Created: / 13-02-2014 / 12:37:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   466 ! !
   545 ! !
   467 
   546 
   468 !HGCommand methodsFor:'accessing'!
   547 !HGCommand methodsFor:'accessing'!
   469 
   548 
   470 result
   549 result
   526     self assert: anException isException.
   605     self assert: anException isException.
   527 
   606 
   528     Trace ifTrue:[
   607     Trace ifTrue:[
   529         Logger log: 'cmd: propagating: ' , anException class name , ' - ', anException description severity: #trace facility: 'HG'.
   608         Logger log: 'cmd: propagating: ' , anException class name , ' - ', anException description severity: #trace facility: 'HG'.
   530     ].
   609     ].
       
   610     Debug ifTrue:[ 
       
   611         anException isNotification ifFalse:[ 
       
   612             thisContext fullPrintAllOn: Transcript.  
       
   613         ].
       
   614     ].
   531     errors nextPut: anException.
   615     errors nextPut: anException.
   532 
   616 
   533     "Created: / 04-02-2013 / 21:29:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   617     "Created: / 04-02-2013 / 21:29:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   534     "Modified: / 09-02-2014 / 19:28:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   618     "Modified: / 05-03-2014 / 00:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   535 !
   619 !
   536 
   620 
   537 signal
   621 signal
   538     "Signal all propagated exceptions to the caller"
   622     "Signal all propagated exceptions to the caller"
   539 
   623 
  1182 
  1266 
  1183     "Created: / 15-11-2012 / 17:04:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1267     "Created: / 15-11-2012 / 17:04:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1184     "Modified: / 08-03-2013 / 19:35:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1268     "Modified: / 08-03-2013 / 19:35:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1185 ! !
  1269 ! !
  1186 
  1270 
       
  1271 !HGCommand::init methodsFor:'accessing'!
       
  1272 
       
  1273 path
       
  1274     ^ path
       
  1275 !
       
  1276 
       
  1277 path:aStringOrFilename
       
  1278     path := aStringOrFilename.
       
  1279 ! !
       
  1280 
       
  1281 !HGCommand::init methodsFor:'private'!
       
  1282 
       
  1283 argumentsCommandOn:stream
       
  1284     stream nextPut: path asFilename asAbsoluteFilename pathName
       
  1285     "Created: / 13-02-2014 / 12:36:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1286 !
       
  1287 
       
  1288 parseOutput:stream
       
  1289     "Parses output of 'hg' command, i.e. commit, log, update, checkout,
       
  1290      etc."
       
  1291 
       
  1292     ^ nil
       
  1293 
       
  1294     "Created: / 13-02-2014 / 12:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1295 ! !
  1187 !HGCommand::locate methodsFor:'accessing'!
  1296 !HGCommand::locate methodsFor:'accessing'!
  1188 
  1297 
  1189 revision
  1298 revision
  1190     ^ revision
  1299     ^ revision
  1191 !
  1300 !
  1783 
  1892 
  1784 !HGCommand::version methodsFor:'private'!
  1893 !HGCommand::version methodsFor:'private'!
  1785 
  1894 
  1786 arguments
  1895 arguments
  1787 
  1896 
  1788     ^ Array with: HGExecutable with: '--version'
  1897     ^ Array with: self executable with: '--version'
  1789 
  1898 
  1790     "Created: / 19-11-2012 / 20:01:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1899     "Created: / 19-11-2012 / 20:01:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1900     "Modified: / 21-02-2014 / 00:20:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1791 !
  1901 !
  1792 
  1902 
  1793 parseOutput:stream
  1903 parseOutput:stream
  1794     "Parses output of 'hg' command, i.e. commit, log, update, checkout,
  1904     "Parses output of 'hg' command, i.e. commit, log, update, checkout,
  1795      etc."
  1905      etc."