mercurial/HGRepository.st
branchhg-command-server-support
changeset 235 3d8ef499d7d9
parent 234 a9ef61b902ae
child 237 fc6b21de083e
--- a/mercurial/HGRepository.st	Sun Mar 03 20:45:13 2013 +0000
+++ b/mercurial/HGRepository.st	Sun Mar 03 23:58:51 2013 +0000
@@ -12,8 +12,8 @@
 "{ Package: 'stx:libscm/mercurial' }"
 
 Object subclass:#HGRepository
-	instanceVariableNames:'uuid path wc changesets branches heads config lock'
-	classVariableNames:'Cache'
+	instanceVariableNames:'uuid path wc changesets branches heads config lock server'
+	classVariableNames:'Cache UseCommandServer'
 	poolDictionaries:''
 	category:'SCM-Mercurial-Core'
 !
@@ -56,9 +56,10 @@
 
     "/ please change as required (and remove this comment)
 
-    Cache := CacheDictionary new: 8
+    Cache := CacheDictionary new: 8.
+    UseCommandServer := true.
 
-    "Modified: / 14-12-2012 / 19:31:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-03-2013 / 22:57:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !HGRepository class methodsFor:'instance creation'!
@@ -164,11 +165,12 @@
                         reader:[:old |
                             | rbranches current names |
                             rbranches := old.
-                            current := HGCommand branches
-                                    workingDirectory: path pathName;
-                                    active: false;
-                                    closed: true;
-                                    executeOnRepository: self.
+                            current := self execute:
+                                        (HGCommand branches
+                                            workingDirectory: path pathName;
+                                            active: false;
+                                            closed: true;
+                                            yourself).
                             names := rbranches collect:[:b|b name].
                             current := current reject:[:b|names includes: b name].
                             current do:[:b|b setRepository: self].
@@ -183,7 +185,7 @@
     ^branches value
 
     "Created: / 27-11-2012 / 19:57:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-03-2013 / 20:37:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-03-2013 / 22:52:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 config
@@ -201,16 +203,14 @@
                         reader:[
                             | ids |
 
-                            ids := HGCommand heads
-                                        workingDirectory: path pathName;
-                                        executeOnRepository: self.
+                            ids := self execute: HGCommand heads.
                             ids collect:[:id|self changesetWithId: id].
                         ].                                
     ].
     ^heads value.
 
     "Created: / 27-11-2012 / 21:33:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-03-2013 / 20:38:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-03-2013 / 22:53:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 path
@@ -334,7 +334,13 @@
     "Created: / 16-12-2012 / 00:39:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!HGRepository methodsFor:'initialization'!
+!HGRepository methodsFor:'initialize & release'!
+
+finalize
+    server notNil ifTrue:[ server stop ].
+
+    "Created: / 03-03-2013 / 23:15:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
 
 initializeOn: aStringOrFilename
     | p |
@@ -384,6 +390,21 @@
     "Created: / 21-11-2012 / 00:21:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+execute: anHGCommand
+    ^UseCommandServer ifTrue:[
+        server isNil ifTrue:[
+            server := HGCommandServer new repository: self.
+            server start.
+            self registerForFinalization.
+        ].
+        server execute: anHGCommand
+    ] ifFalse:[
+        anHGCommand execute
+    ]
+
+    "Created: / 03-03-2013 / 22:52:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 pull
     "Pulls changesets from default upstream repository.
      See .hg/hgrc, section path"
@@ -401,13 +422,13 @@
 
     See .hg/hgrc, section for configured aliases"
 
-    ^HGCommand pull
-        workingDirectory: path pathName;
-        url: (remote ? 'default') asString;
-        executeOnRepository: self.
+    ^self execute: 
+        (HGCommand pull
+            url: (remote ? 'default') asString;
+            yourself)
 
     "Created: / 04-02-2013 / 15:30:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-03-2013 / 20:38:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-03-2013 / 22:53:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 push
@@ -442,14 +463,15 @@
 
      See .hg/hgrc, section path"
 
-    ^HGCommand push
-        workingDirectory: path pathName;
-        url: (remote ? 'default') asString;
-        force: force;
-        executeOnRepository: self.
+    ^self execute:
+        (HGCommand push
+            workingDirectory: path pathName;
+            url: (remote ? 'default') asString;
+            force: force;
+            yourself)
 
     "Created: / 27-11-2012 / 21:58:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-03-2013 / 20:38:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-03-2013 / 22:54:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !HGRepository methodsFor:'synchronized evaluation'!
@@ -558,10 +580,11 @@
      non-lazy"
 
      | csets cs |
-     csets := HGCommand log
-                    workingDirectory: repository path asString;
-                    revsets: (self loadRevsetsForLoad: id);
-                    executeOnRepository: self.
+     csets := self repository execute:
+                    (HGCommand log
+                        workingDirectory: repository path asString;
+                        revsets: (self loadRevsetsForLoad: id);
+                        yourself).
      "/just to be defensive...
      csets do:[:each| 
         | existing |
@@ -583,7 +606,7 @@
     ^cs
 
     "Created: / 16-12-2012 / 00:57:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-03-2013 / 20:38:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-03-2013 / 22:58:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 loadRevsetsForLoad: id