common/SCMAbstractPackageModel.st
changeset 387 ebec1ef28839
parent 384 d946e0f0f12a
child 388 d093d603292a
--- a/common/SCMAbstractPackageModel.st	Thu Feb 27 22:38:01 2014 +0000
+++ b/common/SCMAbstractPackageModel.st	Fri Feb 28 10:47:43 2014 +0000
@@ -65,6 +65,13 @@
 
     In this case, the HGRepository object is shared by all three package models.
 
+    == Virtual packages ==
+
+    Package is 'virtual' if there's actually no code in the package. Virtual packages
+    are therefore just containers for nested packages. For example, package 'stx' would
+    be a 'virtual' package, since there's no code packages in 'stx' - all is in one of
+    its nested sub-packages - stx:libbasic, stx:libscm.
+
     [author:]
         Jan Vrany <jan.vrany@fit.cvut.cz>
 
@@ -213,9 +220,25 @@
     "Return a logical revision of the package, i.e., a revision
      on which the next commit will be based on"              
 
-    ^ self subclassResponsibility
+    self isVirtual ifTrue:[ 
+        | childRevs |
 
-    "Modified (comment): / 25-02-2014 / 22:41:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+        childRevs := Set new.
+        self childrenDo:[:each | childRevs add: each revision ].
+        childRevs size == 0 ifTrue:[ 
+            self error: 'No non-virtual children'.
+            ^ nil.
+        ].
+        childRevs size ~~ 1 ifTrue:[ 
+            self error: 'Inconsistent revisions of chilren of virtual package'.
+            ^ nil
+        ].
+        ^ childRevs anElement
+    ] ifFalse:[ 
+        ^ self getRevision
+    ].
+
+    "Modified: / 28-02-2014 / 09:38:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 temporaryWorkingCopy
@@ -450,7 +473,7 @@
     | childNames nameSizePlus1 |
 
     nameSizePlus1 := name size + 1.
-    childNames := Smalltalk allProjectIDs select:[:each |
+    childNames := Smalltalk allLoadedProjectIDs select:[:each |
         (each startsWith: name)
         and:[ each ~= name
         and:[ ((each at: nameSizePlus1) == $/ or:[ (each at: nameSizePlus1) == $: ])
@@ -462,6 +485,7 @@
     "
 
     "Created: / 19-02-2014 / 23:43:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 28-02-2014 / 10:32:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 childrenDo: aBlock
@@ -540,6 +564,15 @@
 
     "Created: / 01-12-2012 / 01:29:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 01-12-2012 / 18:11:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getRevision
+    "Return a logical revision of the package, i.e., a revision
+     on which the next commit will be based on"              
+
+    ^ self subclassResponsibility
+
+    "Created: / 28-02-2014 / 09:33:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SCMAbstractPackageModel methodsFor:'file out'!
@@ -873,6 +906,24 @@
             and:[ ':/' includes: (anotherName at: name size + 1) ]].
 
     "Created: / 25-02-2014 / 22:50:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isVirtual
+    "Return true, if the package is virtual, i.e., there's no code in
+     the package. False otherwise.
+
+     Virtual packages serves merely as containers for nested packages"
+
+    "/ Following implementation is bit time-costly. Maybe we should cache
+    "/ the information. We'll see.
+    ^ self classes isEmpty and:[ self extensions isEmpty ]
+
+    "
+    (HGPackageModel named: 'stx:libscm') isVirtual
+    (HGPackageModel named: 'stx:libscm/mercurial') isVirtual
+    "
+
+    "Created: / 27-02-2014 / 22:46:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SCMAbstractPackageModel methodsFor:'utilities'!
@@ -883,9 +934,7 @@
         with: anotherPackageModel
 
     "Created: / 26-02-2014 / 22:43:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!SCMAbstractPackageModel methodsFor:'utils'!
+!
 
 ensureTemporaryWorkingCopy
     "raise an error: must be redefined in concrete subclass(es)"