AbstractSourceCodeManager.st
changeset 95 aeda58a2343c
parent 93 83042eccb8d1
child 96 326cccce2fe7
--- a/AbstractSourceCodeManager.st	Sat Nov 25 12:06:29 1995 +0100
+++ b/AbstractSourceCodeManager.st	Sat Nov 25 16:27:29 1995 +0100
@@ -104,15 +104,12 @@
 
     "Created: 4.11.1995 / 19:09:12 / cg"
     "Modified: 4.11.1995 / 19:15:43 / cg"
-! !
-
-!AbstractSourceCodeManager class methodsFor:'source code access'!
+!
 
-checkinClass:aClass logMessage:logMessage
-    "checkin of a class into the source repository.
-     Return true if ok, false if not."
+sourceInfoOfClass:aClass
+    "helper: return a classes sourceCodeInfo"
 
-    |cls sourceInfo tempDir packageDir moduleDir tempFile classFileName ok|
+    |cls sourceInfo|
 
     cls := aClass.
     cls isMeta ifTrue:[
@@ -122,12 +119,28 @@
     sourceInfo := cls sourceCodeInfo.
     sourceInfo isNil ifTrue:[
 	'SOURCEMGR: cannot extract classes sourceInfo' infoPrintNL.
-	^ false
+	^ nil
     ].
+    ^ sourceInfo
+
+    "Created: 25.11.1995 / 12:40:19 / cg"
+    "Modified: 25.11.1995 / 12:40:27 / cg"
+! !
+
+!AbstractSourceCodeManager class methodsFor:'source code access'!
+
+checkinClass:aClass logMessage:logMessage
+    "checkin of a class into the source repository.
+     Return true if ok, false if not."
+
+    |sourceInfo tempDir packageDir moduleDir tempFile classFileName ok|
+
+    sourceInfo := self sourceInfoOfClass:aClass.
+    sourceInfo isNil ifTrue:[^ false].
 
     packageDir := sourceInfo at:#directory.
     moduleDir := sourceInfo at:#module.  "/ use the modules name as CVS module
-    classFileName := Smalltalk fileNameForClass:cls.
+    classFileName := Smalltalk fileNameForClass:aClass.
 
     tempDir := (Filename newTemporaryIn:nil) makeDirectory.
     [
@@ -140,7 +153,13 @@
 	    ^ false
 	].
 
-	aClass fileOutOn:aStream withTimeStamp:false.
+	Class fileOutErrorSignal handle:[:ex |
+	    'SOURCEMGR: fileout failed' infoPrintNL.
+	    aStream close.
+	    ^ false
+	] do:[
+	    aClass fileOutOn:aStream withTimeStamp:false.
+	].
 	aStream close.
 
 	(tempFile := tempDir construct:(classFileName,'.st')) exists ifFalse:[
@@ -149,7 +168,7 @@
 	].
 
 	ok := self 
-	    checkinClass:cls
+	    checkinClass:aClass
 	    fileName:classFileName 
 	    directory:packageDir 
 	    module:moduleDir
@@ -157,7 +176,7 @@
 	    logMessage:logMessage.
 
 	ok ifTrue:[
-	    Class addChangeRecordForClassCheckIn:cls.
+	    Class addChangeRecordForClassCheckIn:aClass.
 	].
 	^ ok
     ] valueNowOrOnUnwindDo:[
@@ -207,35 +226,27 @@
      The classes source code is extracted using the revision and the sourceCodeInfo,
      which itself is extracted from the classes packageString."
 
-    |classFileName revision packageDir moduleDir sourceInfo cls|
-
-    cls := aClass.
-    cls isMeta ifTrue:[
-	cls := cls soleInstance
-    ].
+    |classFileName revision packageDir moduleDir sourceInfo|
 
     aRevisionStringOrNil isNil ifTrue:[
-        revision := cls revision.
-        revision isNil ifTrue:[ 
-	    'SOURCEMGR: class ' , cls name , ' has no revision string' infoPrintNL.
+	revision := aClass revision.
+	revision isNil ifTrue:[ 
+	    'SOURCEMGR: class ' , aClass name , ' has no revision string' infoPrintNL.
 	    ^ nil.
 	]
     ] ifFalse:[
 	revision := aRevisionStringOrNil
     ].
 
-    sourceInfo := cls sourceCodeInfo.
-    sourceInfo isNil ifTrue:[
-	('SOURCEMGR: class ' , cls name , ' has no sourceInfo.') infoPrintNL.
-	^ nil
-    ].
+    sourceInfo := self sourceInfoOfClass:aClass.
+    sourceInfo isNil ifTrue:[^ nil].
 
     packageDir := sourceInfo at:#directory.
     moduleDir := sourceInfo at:#module.  "/ use the modules name as CVS module
-    classFileName := Smalltalk fileNameForClass:cls.
+    classFileName := Smalltalk fileNameForClass:aClass.
 
     ^ self 
-	streamForClass:cls
+	streamForClass:aClass
 	fileName:classFileName 
 	revision:revision 
 	directory:packageDir 
@@ -248,29 +259,31 @@
 !AbstractSourceCodeManager class methodsFor:'source code administration'!
 
 revisionLogOf:aClass
-    "return a classes revisionlog as a collection of revision entries, nil on failure.
+    "return info about the repository container and
+     the revisionlog as a collection of revision entries.
+     Return nil on failure.
      The returned information is a structure (IdentityDictionary)
      filled with:
-            #container          -> the RCS container file name
-            #filename           -> the actual source file name
-            #newestRevision     -> the revisionString of the newest revision
-            #numberOfRevisions  -> the number of revisions in the container
-            #revisions          -> collection of per-revision info
+	    #container          -> the RCS container file name
+	    #filename           -> the actual source file name
+	    #newestRevision     -> the revisionString of the newest revision
+	    #numberOfRevisions  -> the number of revisions in the container
+	    #revisions          -> collection of per-revision info
 
-            per revision info consists of one record per revision:
+	    per revision info consists of one record per revision:
 
-              #revision              -> the revision string
-              #author                -> who checked that revision into the repository
-              #date                  -> when was it checked in
-              #state                 -> the RCS state
-              #numberOfChangedLines  -> the number of changed line w.r.t the previous
+	      #revision              -> the revision string
+	      #author                -> who checked that revision into the repository
+	      #date                  -> when was it checked in
+	      #state                 -> the RCS state
+	      #numberOfChangedLines  -> the number of changed line w.r.t the previous
 
-            revisions are ordered newest first 
-            (i.e. the last entry is for the initial revision; the first for the most recent one)
-        "
+	    revisions are ordered newest first 
+	    (i.e. the last entry is for the initial revision; the first for the most recent one)
+	"
 
     ^ self
-        revisionLogOf:aClass fromRevision:nil toRevision:nil
+	revisionLogOf:aClass fromRevision:nil toRevision:nil
 
     "
      SourceCodeManager revisionLogOf:Array 
@@ -281,58 +294,60 @@
 !
 
 revisionLogOf:aClass fromRevision:rev1 toRevision:rev2
-    "return (part of) a classes revisionlog as a collection of revision entries, nil on failure.
+    "return info about the repository container and
+     (part of) the revisionlog as a collection of revision entries.
+     Return nil on failure.
+
      The returned information is a structure (IdentityDictionary)
      filled with:
-            #container          -> the RCS container file name
-            #filename           -> the actual source file name
-            #newestRevision     -> the revisionString of the newest revision
-            #numberOfRevisions  -> the number of revisions in the container
-            #revisions          -> collection of per-revision info
+	    #container          -> the RCS container file name 
+	    #filename           -> the actual source file name
+	    #newestRevision     -> the revisionString of the newest revision
+	    #numberOfRevisions  -> the number of revisions in the container
+	    #revisions          -> collection of per-revision info (see below)
 
-            per revision info consists of one record per revision:
+	    rev1 / rev2 specify from which revisions a logEntry is wanted:
+	      If rev1 is nil, the first revision is the initial revision
+	      otherwise, the log starts with that revision.
+	      If rev2 is nil, the last revision is the newest revision
+	      otherwise, the log ends with that revision.
+	      If both are nil, no logEntries are extracted (i.e. only the header).
 
-              #revision              -> the revision string
-              #author                -> who checked that revision into the repository
-              #date                  -> when was it checked in
-              #state                 -> the RCS state
-              #numberOfChangedLines  -> the number of changed line w.r.t the previous
+	    per revision info consists of one record per revision:
 
-            revisions are ordered newest first 
-            (i.e. the last entry is for the initial revision; the first for the most recent one)
-        "
-
-    |cls sourceInfo tempDir packageDir moduleDir tempFile classFileName ok|
+	      #revision              -> the revision string
+	      #author                -> who checked that revision into the repository
+	      #date                  -> when was it checked in
+	      #state                 -> the RCS state
+	      #numberOfChangedLines  -> the number of changed line w.r.t the previous
 
-    cls := aClass.
-    cls isMeta ifTrue:[
-        cls := cls soleInstance
-    ].
+	    revisions are ordered newest first 
+	    (i.e. the last entry is for the initial revision; the first for the most recent one)
+	"
 
-    sourceInfo := cls sourceCodeInfo.
-    sourceInfo isNil ifTrue:[
-        'SOURCEMGR: cannot extract classes sourceInfo' infoPrintNL.
-        ^ false
-    ].
+    |cls sourceInfo packageDir moduleDir classFileName|
+
+    sourceInfo := self sourceInfoOfClass:aClass.
+    sourceInfo isNil ifTrue:[^ nil].
 
     packageDir := sourceInfo at:#directory.
     moduleDir := sourceInfo at:#module.  "/ use the modules name as CVS module
-    classFileName := Smalltalk fileNameForClass:cls.
+    classFileName := Smalltalk fileNameForClass:aClass.
 
     ^ self 
-        revisionLogOf:cls
-        fromRevision:rev1 
-        toRevision:rev2
-        fileName:classFileName 
-        directory:packageDir 
-        module:moduleDir
+	revisionLogOf:aClass
+	fromRevision:rev1 
+	toRevision:rev2
+	fileName:classFileName 
+	directory:packageDir 
+	module:moduleDir
 
     "
      SourceCodeManager revisionLogOf:Array fromRevision:'1.40' toRevision:'1.43' 
     "
 
     "Created: 6.11.1995 / 18:56:00 / cg"
-    "Modified: 25.11.1995 / 11:56:13 / cg"
+    "Modified: 25.11.1995 / 12:43:12 / cg"
 !
 
 revisionLogOf:cls fromRevision:rev1 toRevision:rev2 fileName:classFileName directory:packageDir module:moduleDir 
@@ -356,18 +371,18 @@
     aStream nextPutAll:'  Newest revision: '; nextPutAll:(log at:#newestRevision) printString; cr.
 
     (log at:#revisions) do:[:entry |
-        aStream cr.
-        aStream nextPutAll:'  revision '; nextPutAll:(entry at:#revision); tab.
-        aStream nextPutAll:' date: '; nextPutAll:(entry at:#date); tab.
-        aStream nextPutAll:' author: '; nextPutAll:(entry at:#author); tab.
-        aStream cr.
+	aStream cr.
+	aStream nextPutAll:'  revision '; nextPutAll:(entry at:#revision); tab.
+	aStream nextPutAll:' date: '; nextPutAll:(entry at:#date); tab.
+	aStream nextPutAll:' author: '; nextPutAll:(entry at:#author); tab.
+	aStream cr.
 
-        log := entry at:#logMessage.
-        (log isEmpty or:[log isBlank or:[log withoutSeparators = '.']]) ifTrue:[
-            log := '*** empty log message ***'
-        ].
-        aStream tab; nextPutAll:log.
-        aStream cr.
+	log := entry at:#logMessage.
+	(log isEmpty or:[log isBlank or:[log withoutSeparators = '.']]) ifTrue:[
+	    log := '*** empty log message ***'
+	].
+	aStream tab; nextPutAll:log.
+	aStream cr.
     ].
     ^ true
 
@@ -385,25 +400,17 @@
 writeRevisionLogOf:aClass fromRevision:rev1 toRevision:rev2 to:aStream
     "extract a classes log and append it to aStream."
 
-    |cls sourceInfo tempDir packageDir moduleDir tempFile classFileName ok|
+    |sourceInfo packageDir moduleDir classFileName|
 
-    cls := aClass.
-    cls isMeta ifTrue:[
-	cls := cls soleInstance
-    ].
-
-    sourceInfo := cls sourceCodeInfo.
-    sourceInfo isNil ifTrue:[
-	'SOURCEMGR: cannot extract classes sourceInfo' infoPrintNL.
-	^ false
-    ].
+    sourceInfo := self sourceInfoOfClass:aClass.
+    sourceInfo isNil ifTrue:[^ nil].
 
     packageDir := sourceInfo at:#directory.
     moduleDir := sourceInfo at:#module.  "/ use the modules name as CVS module
-    classFileName := Smalltalk fileNameForClass:cls.
+    classFileName := Smalltalk fileNameForClass:aClass.
 
     ^ self 
-	writeRevisionLogOf:cls
+	writeRevisionLogOf:aClass 
 	fromRevision:rev1 
 	toRevision:rev2
 	fileName:classFileName 
@@ -416,7 +423,7 @@
     "
 
     "Created: 6.11.1995 / 18:56:00 / cg"
-    "Modified: 20.11.1995 / 12:19:47 / cg"
+    "Modified: 25.11.1995 / 12:42:59 / cg"
 !
 
 writeRevisionLogOf:aClass to:aStream
@@ -433,4 +440,4 @@
 !AbstractSourceCodeManager class methodsFor:'documentation'!
 
 version
-^ '$Header: /cvs/stx/stx/libbasic3/AbstractSourceCodeManager.st,v 1.22 1995-11-25 11:04:18 cg Exp $'! !
+^ '$Header: /cvs/stx/stx/libbasic3/AbstractSourceCodeManager.st,v 1.23 1995-11-25 15:27:25 cg Exp $'! !