--- a/mercurial/HGPackageModelRegistry.st Mon Dec 03 16:17:39 2012 +0000
+++ b/mercurial/HGPackageModelRegistry.st Mon Dec 03 16:20:11 2012 +0000
@@ -11,23 +11,75 @@
!HGPackageModelRegistry methodsFor:'accessing'!
packageNamed:package
- "Returns a HGPackageModel for given package."
+ "Returns a HGPackageModel for given package or nil
+ if given package is not backed by Mercurial repository."
- | dir repo |
+ | dir components names directories root rootI rootD pkg|
- packages at: package ifPresent: [ :pkg | ^ pkg ].
- wcs at: package ifPresent:[ :wc | ^ wc ].
+ packages at: package ifPresent: [ :p | ^ p ].
+
dir := Smalltalk getPackageDirectoryForPackage: package.
- dir := HGRepository discover: dir.
- dir isNil ifTrue:[
- HGError raiseErrorString: 'No repository found for package ',package.
- ^nil.
+ dir isNil ifTrue:[ ^ nil ].
+
+ components := OrderedCollection new.
+ names := OrderedCollection new.
+
+ (package includes: $:) ifFalse:[
+ components := package.
+ names := package.
+ ] ifTrue:[
+ | i1 i2 |
+
+ i1 := 1.
+ i2 := package indexOf: $:.
+
+ components add: (package copyFrom: i1 to: i2 - 1).
+ names add (package copyFrom: 1 to: i2 - 1).
+
+ i1 := i2 + 1.
+ [ (i2 := package indexOf: $/ startingAt: i1) ~~ 0 ] whileTrue:[
+ components add: (package copyFrom: i1 to: i2 - 1).
+ names add (package copyFrom: 1 to: i2 - 1).
+ i1 := i2 + 1.
+ ].
+
+ components add: (package copyFrom: i1 ).
+ names add: package
+
].
- repo := repositories at: dir ifAbsentPut: [ HGRepository on: dir ].
- ^packages at: package ifAbsentPut: [ HGPackageModel new name: package repository: repo ].
+ directories := Array new: components size.
+ directories at: components size put: dir.
+ directories size - 1 downTo: 1 do:[:i|
+ directories at: i put: (directories at: i + 1) directory.
+ ].
+
+ "/ search cached packages...
+ 1 to: names size do:[:i|
+ packages at: (names at:i) ifPresent:[:p|root := p. rootI := i].
+ ].
+ root isNil ifTrue:[
+ directories withIndexDo:[:each :eachI|
+ ( each / '.hg' ) exists ifTrue:[
+ rootD := each.
+ rootI := eachI.
+ ].
+ ].
+ rootD isNil ifTrue:[ ^ nil ].
+ root := HGPackageModel new
+ setName: (names at: rootI)
+ repository: (HGRepository on: rootD).
+ packages at: root name put: root.
+ ].
+ pkg := root.
+ rootI + 1 to: components size do:[:each|
+ pkg := pkg construct: (components at:each).
+ packages at: pkg name put: pkg.
+ ].
+
+ ^pkg
"Created: / 14-11-2012 / 00:15:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 16-11-2012 / 19:52:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-12-2012 / 14:27:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!HGPackageModelRegistry methodsFor:'initialization'!