3 Copyright (C) 2012-2013 Jan Vrany |
3 Copyright (C) 2012-2013 Jan Vrany |
4 |
4 |
5 This library is free software; you can redistribute it and/or |
5 This library is free software; you can redistribute it and/or |
6 modify it under the terms of the GNU Lesser General Public |
6 modify it under the terms of the GNU Lesser General Public |
7 License as published by the Free Software Foundation; either |
7 License as published by the Free Software Foundation; either |
8 version 2.1 of the License. |
8 version 2.1 of the License. |
9 |
9 |
10 This library is distributed in the hope that it will be useful, |
10 This library is distributed in the hope that it will be useful, |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 Lesser General Public License for more details. |
13 Lesser General Public License for more details. |
195 Copyright (C) 2012-2013 Jan Vrany |
195 Copyright (C) 2012-2013 Jan Vrany |
196 |
196 |
197 This library is free software; you can redistribute it and/or |
197 This library is free software; you can redistribute it and/or |
198 modify it under the terms of the GNU Lesser General Public |
198 modify it under the terms of the GNU Lesser General Public |
199 License as published by the Free Software Foundation; either |
199 License as published by the Free Software Foundation; either |
200 version 2.1 of the License. |
200 version 2.1 of the License. |
201 |
201 |
202 This library is distributed in the hope that it will be useful, |
202 This library is distributed in the hope that it will be useful, |
203 but WITHOUT ANY WARRANTY; without even the implied warranty of |
203 but WITHOUT ANY WARRANTY; without even the implied warranty of |
204 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
204 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
205 Lesser General Public License for more details. |
205 Lesser General Public License for more details. |
237 "Returns absolute path to hg executable to use" |
237 "Returns absolute path to hg executable to use" |
238 |
238 |
239 HGExecutable isNil ifTrue:[ |
239 HGExecutable isNil ifTrue:[ |
240 | executable | |
240 | executable | |
241 executable := UserPreferences current hgCommand. |
241 executable := UserPreferences current hgCommand. |
242 executable isNil ifTrue:[ |
242 executable isNil ifTrue:[ |
243 OperatingSystem isMSWINDOWSlike ifTrue:[ |
243 OperatingSystem isMSWINDOWSlike ifTrue:[ |
244 "/ | h | |
244 "/ | h | |
245 "/ |
245 "/ |
246 "/ h := Win32OperatingSystem registryEntry |
246 "/ h := Win32OperatingSystem registryEntry |
247 "/ 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'. |
248 "/ h notNil ifTrue:[HGExecutable := h valueNamed:'']. |
248 "/ h notNil ifTrue:[HGExecutable := h valueNamed:'']. |
249 "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable] |
249 "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable] |
250 executable := OperatingSystem pathOfCommand:'hg'. |
250 executable := OperatingSystem pathOfCommand:'hg'. |
281 ! |
281 ! |
282 |
282 |
283 hgCommandValidate: executable |
283 hgCommandValidate: executable |
284 "/ Given a `executable`, checks whether it is a valid hg binary. |
284 "/ Given a `executable`, checks whether it is a valid hg binary. |
285 "/ Returns absolute path to hg binary or raise an |
285 "/ Returns absolute path to hg binary or raise an |
286 "/ HGInvalidExecutableError or HGInvalidVersionError |
286 "/ HGInvalidExecutableError or HGInvalidVersionError |
287 "/ if `executable` is not valid hg binary. |
287 "/ if `executable` is not valid hg binary. |
288 "/ |
288 "/ |
289 | path version | |
289 | path version | |
290 |
290 |
291 path := executable asFilename. |
291 path := executable asFilename. |
292 path isAbsolute ifFalse:[ |
292 path isAbsolute ifFalse:[ |
293 path := path asAbsoluteFilename. |
293 path := path asAbsoluteFilename. |
294 path exists ifFalse:[ |
294 path exists ifFalse:[ |
295 "/ Also try to find specified command along PATH, maybe somebody |
295 "/ Also try to find specified command along PATH, maybe somebody |
296 "/ just typed 'hg' in... |
296 "/ just typed 'hg' in... |
297 (executable includes: Filename separator) ifFalse:[ |
297 (executable includes: Filename separator) ifFalse:[ |
298 path := (OperatingSystem pathOfCommand: executable). |
298 path := (OperatingSystem pathOfCommand: executable). |
299 path isNil ifTrue:[ |
299 path isNil ifTrue:[ |
306 ]. |
306 ]. |
307 path exists ifFalse:[ |
307 path exists ifFalse:[ |
308 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) does not exists!!' bindWith: path pathName). |
308 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) does not exists!!' bindWith: path pathName). |
309 ^ nil |
309 ^ nil |
310 ]. |
310 ]. |
311 path isDirectory ifTrue:[ |
311 path isDirectory ifTrue:[ |
312 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is actually a directory!!' bindWith: path pathName). |
312 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is actually a directory!!' bindWith: path pathName). |
313 ^ nil |
313 ^ nil |
314 ]. |
314 ]. |
315 path isExecutable ifFalse:[ |
315 path isExecutable ifFalse:[ |
316 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is cannot be executed!!' bindWith: path pathName). |
316 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is cannot be executed!!' bindWith: path pathName). |
317 ^ nil |
317 ^ nil |
318 ]. |
318 ]. |
319 [ |
319 [ |
320 version := self hgVersionOf: path pathName. |
320 version := self hgVersionOf: path pathName. |
321 ] on: Error do:[:ex | |
321 ] on: Error do:[:ex | |
322 HGInvalidExecutableError newException |
322 HGInvalidExecutableError newException |
323 parameter: ex; |
323 parameter: ex; |
324 messageText: 'Failed to check version: ', ex description; |
324 messageText: 'Failed to check version: ', ex description; |
325 raise. |
325 raise. |
326 ^ nil |
326 ^ nil |
327 ]. |
327 ]. |
328 (self hgVersionIsSupported: version) ifFalse:[ |
328 (self hgVersionIsSupported: version) ifFalse:[ |
329 HGInvalidVersionError newException |
329 HGInvalidVersionError newException |
330 parameter: version; |
330 parameter: version; |
331 messageText: ('Unsuported Mercurial version (%1)' bindWith: (version asStringWith:$.)); |
331 messageText: ('Unsuported Mercurial version (%1)' bindWith: (version asStringWith:$.)); |
332 raise. |
332 raise. |
333 ^ nil |
333 ^ nil |
634 self assert: anException isException. |
634 self assert: anException isException. |
635 |
635 |
636 Trace ifTrue:[ |
636 Trace ifTrue:[ |
637 Logger log: 'cmd: propagating: ' , anException class name , ' - ', anException description severity: #trace facility: 'HG'. |
637 Logger log: 'cmd: propagating: ' , anException class name , ' - ', anException description severity: #trace facility: 'HG'. |
638 ]. |
638 ]. |
639 Debug ifTrue:[ |
639 Debug ifTrue:[ |
640 anException isNotification ifFalse:[ |
640 anException isNotification ifFalse:[ |
641 thisContext fullPrintAllOn: Transcript. |
641 anException suspendedContext notNil ifTrue:[ |
|
642 anException suspendedContext fullPrintAllOn: Transcript. |
|
643 ]. |
642 ]. |
644 ]. |
643 ]. |
645 ]. |
644 errors nextPut: anException. |
646 errors nextPut: anException. |
645 |
647 |
646 "Created: / 04-02-2013 / 21:29:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
648 "Created: / 04-02-2013 / 21:29:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
682 |
684 |
683 environment := OperatingSystem isUNIXlike |
685 environment := OperatingSystem isUNIXlike |
684 ifTrue:[OperatingSystem getEnvironment copy] |
686 ifTrue:[OperatingSystem getEnvironment copy] |
685 ifFalse:[environment := Dictionary new]. |
687 ifFalse:[environment := Dictionary new]. |
686 environment at: 'HGEDITOR' put: 'true'. |
688 environment at: 'HGEDITOR' put: 'true'. |
687 |
|
688 environment at:'LANG' put:'C'. |
689 environment at:'LANG' put:'C'. |
|
690 environment at:'LC_MESSAGES' put:'C'. |
689 |
691 |
690 args := self arguments. |
692 args := self arguments. |
691 OperatingSystem isMSWINDOWSlike ifTrue:[ |
693 OperatingSystem isMSWINDOWSlike ifTrue:[ |
692 args := String streamContents:[:s| |
694 args := String streamContents:[:s| |
693 args |
695 args |
727 OperatingSystem isUNIXlike ifTrue:[ |
729 OperatingSystem isUNIXlike ifTrue:[ |
728 "/JV: Q: Why this is necessary? |
730 "/JV: Q: Why this is necessary? |
729 stdout readWaitWithTimeoutMs: 10. |
731 stdout readWaitWithTimeoutMs: 10. |
730 stderr readWaitWithTimeoutMs: 10. |
732 stderr readWaitWithTimeoutMs: 10. |
731 Debug ifTrue:[ |
733 Debug ifTrue:[ |
|
734 "/ Transcript showCR:'hg stdout:'; showCR:stdout contents asString. |
|
735 "/ Transcript showCR:'hg stderr:'; showCR:stderr contents asString. |
732 stdout := stdout contents asString readStream. |
736 stdout := stdout contents asString readStream. |
733 stderr := stderr contents asString readStream. |
737 stderr := stderr contents asString readStream. |
734 ] |
738 ] |
735 ]. |
739 ]. |
736 |
740 |
878 spawn:block name: name |
882 spawn:block name: name |
879 "Spawn a new background thread executing given block" |
883 "Spawn a new background thread executing given block" |
880 |
884 |
881 | worker | |
885 | worker | |
882 |
886 |
883 worker := [ |
887 worker := [ |
884 Trace ifTrue:[ |
888 Trace ifTrue:[ |
885 Logger log: 'cmd: worker ''', name , ''' spawned' severity: #trace facility: 'HG'. |
889 Logger log: 'cmd: worker ''', name , ''' spawned' severity: #trace facility: 'HG'. |
886 ]. |
890 ]. |
887 block on: Error do:[:ex|self propagate:ex] |
891 block on: Error do:[:ex|self propagate:ex] |
888 ] newProcess. |
892 ] newProcess. |
889 worker addExitAction:[ |
893 worker addExitAction:[ |
890 Trace ifTrue:[ |
894 Trace ifTrue:[ |
891 Logger log: 'cmd: worker ''', name , ''' finished' severity: #trace facility: 'HG'. |
895 Logger log: 'cmd: worker ''', name , ''' finished' severity: #trace facility: 'HG'. |
892 ]. |
896 ]. |
909 "Created: / 03-03-2013 / 16:59:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
913 "Created: / 03-03-2013 / 16:59:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
910 "Modified: / 06-03-2013 / 11:42:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
914 "Modified: / 06-03-2013 / 11:42:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
911 ! |
915 ! |
912 |
916 |
913 spawnOutputReaderOn: stdout |
917 spawnOutputReaderOn: stdout |
914 outputReader isNil ifTrue:[ |
918 outputReader isNil ifTrue:[ |
915 outputReader := self spawn: [ result := self parseOutput: stdout ] name: 'Output reader'. |
919 outputReader := self spawn: [ result := self parseOutput: stdout ] name: 'Output reader'. |
916 ] |
920 ] |
917 |
921 |
918 "Created: / 03-03-2013 / 17:00:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
922 "Created: / 03-03-2013 / 17:00:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
919 ! |
923 ! |
982 |
986 |
983 !HGCommand::bookmark methodsFor:'private'! |
987 !HGCommand::bookmark methodsFor:'private'! |
984 |
988 |
985 argumentsCommandOn:stream |
989 argumentsCommandOn:stream |
986 revision notNil ifTrue:[ |
990 revision notNil ifTrue:[ |
987 stream |
991 stream |
988 nextPut: '-r'; |
992 nextPut: '-r'; |
989 nextPut: revision asString. |
993 nextPut: revision asString. |
990 ]. |
994 ]. |
991 stream |
995 stream |
992 nextPut: name. |
996 nextPut: name. |
993 |
997 |
994 "Created: / 20-03-2014 / 17:26:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
998 "Created: / 20-03-2014 / 17:26:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
995 "Modified: / 20-03-2014 / 18:43:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
999 "Modified: / 20-03-2014 / 18:43:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
996 ! |
1000 ! |
997 |
1001 |
998 parseError:stream |
1002 parseError:stream |
999 ^ (self parserOn: stream) parseErrorBookmark |
1003 ^ (self parserOn: stream) parseErrorBookmark |
1000 |
1004 |
1001 "Created: / 20-03-2014 / 17:27:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1005 "Created: / 20-03-2014 / 17:27:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1002 ! |
1006 ! |
1003 |
1007 |
1508 argumentsCommandOn:stream |
1512 argumentsCommandOn:stream |
1509 "Called to get command specific options" |
1513 "Called to get command specific options" |
1510 |
1514 |
1511 | template | |
1515 | template | |
1512 |
1516 |
1513 template := HGCommandParser templateLog. |
1517 template := HGCommandParser templateLog. |
1514 path isNil ifTrue:[ |
1518 path isNil ifTrue:[ |
1515 revsets isEmptyOrNil ifTrue:[ |
1519 revsets isEmptyOrNil ifTrue:[ |
1516 self error:'No revisions given'. |
1520 self error:'No revisions given'. |
1517 ]. |
1521 ]. |
1518 revsets do:[:revset| |
1522 revsets do:[:revset| |
1525 stream nextPut:string |
1529 stream nextPut:string |
1526 ]. |
1530 ]. |
1527 ] ifFalse:[ |
1531 ] ifFalse:[ |
1528 stream nextPut: '--follow'. |
1532 stream nextPut: '--follow'. |
1529 ]. |
1533 ]. |
1530 idsOnly == true ifTrue:[ |
1534 idsOnly == true ifTrue:[ |
1531 template := HGCommandParser templateLogIdsOnly. |
1535 template := HGCommandParser templateLogIdsOnly. |
1532 ]. |
1536 ]. |
1533 |
1537 |
1534 childrenOnly == true ifTrue:[ |
1538 childrenOnly == true ifTrue:[ |
1535 template := HGCommandParser templateLogChildren. |
1539 template := HGCommandParser templateLogChildren. |
1536 ]. |
1540 ]. |
1537 |
1541 |
1538 stream |
1542 stream |
1539 nextPut:'--debug'; |
1543 nextPut:'--debug'; |
1540 nextPut:'--template'; |
1544 nextPut:'--template'; |
1541 nextPut:template. |
1545 nextPut:template. |
1542 limit notNil ifTrue:[ |
1546 limit notNil ifTrue:[ |
1543 stream |
1547 stream |
1544 nextPut: '-l'; |
1548 nextPut: '-l'; |
1545 nextPut: limit printString |
1549 nextPut: limit printString |
1546 ]. |
1550 ]. |
1547 |
1551 |
1548 path notNil ifTrue:[ |
1552 path notNil ifTrue:[ |
2041 "Created: / 19-11-2012 / 20:02:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2045 "Created: / 19-11-2012 / 20:02:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2042 ! ! |
2046 ! ! |
2043 |
2047 |
2044 !HGCommand class methodsFor:'documentation'! |
2048 !HGCommand class methodsFor:'documentation'! |
2045 |
2049 |
|
2050 version |
|
2051 ^ '$Header: /cvs/stx/stx/libscm/mercurial/HGCommand.st,v 1.4 2014/04/13 15:02:07 cg Exp $' |
|
2052 ! |
|
2053 |
|
2054 version_CVS |
|
2055 ^ '$Header: /cvs/stx/stx/libscm/mercurial/HGCommand.st,v 1.4 2014/04/13 15:02:07 cg Exp $' |
|
2056 ! |
|
2057 |
2046 version_HG |
2058 version_HG |
2047 |
2059 |
2048 ^ '$Changeset: <not expanded> $' |
2060 ^ '$Changeset: <not expanded> $' |
2049 ! |
2061 ! |
2050 |
2062 |
2051 version_SVN |
2063 version_SVN |
2052 ^ 'Id:: ' |
2064 ^ '$Id: HGCommand.st,v 1.4 2014/04/13 15:02:07 cg Exp $' |
2053 ! ! |
2065 ! ! |
2054 |
2066 |
2055 |
2067 |
2056 HGCommand::resolve initialize! |
2068 HGCommand::resolve initialize! |