#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Tue, 28 May 2019 15:55:54 +0200
changeset 4435 96b57ec6ddb9
parent 4434 642559b61811
child 4436 63490a8e62a7
#REFACTORING by cg class: CVSSourceCodeManager class added: #readRevisionLogFromStream:headerOnly:numRevisions: changed: #revisionLogOf:fromRevision:toRevision:numberOfRevisions:fileName:directory:module: refactored to allow stream reading (for expecco)
CVSSourceCodeManager.st
--- a/CVSSourceCodeManager.st	Tue May 28 15:55:00 2019 +0200
+++ b/CVSSourceCodeManager.st	Tue May 28 15:55:54 2019 +0200
@@ -4288,6 +4288,104 @@
     "Modified: / 15-02-2019 / 09:42:02 / Claus Gittinger"
 !
 
+readRevisionLogFromStream:aCVSLogPipeStream headerOnly:headerOnly numRevisions:numRevisionsOrNil
+    |info inHeaderInfo line numberOfRevisionsString idx selectedRevisions revisionRecords atEnd|
+    
+    "/
+    "/ read the command's pipe output and extract the container info
+    "/
+    info := IdentityDictionary new.
+    inHeaderInfo := true.
+    [inHeaderInfo and:[aCVSLogPipeStream atEnd not]] whileTrue:[
+        line:= aCVSLogPipeStream nextLine.
+        line notNil ifTrue:[
+            |gotIt|
+
+            gotIt := false.
+            #('RCS file:'        #container
+              'Working file:'    #filename
+              'head:'            #newestRevision
+              'total revisions:' #numberOfRevisions
+             ) pairWiseDo:[:word :key |
+                |s|
+                
+                gotIt ifFalse:[
+                    s := line restAfter:word withoutSeparators:true.
+                    s notNil ifTrue:[info at:key put:s. gotIt := true].
+                ]
+            ].
+            gotIt ifFalse:[
+                (line startsWith:'symbolic names:') ifTrue:[
+                    |tags tokens|
+
+                    tags := Dictionary new.
+                    line:= aCVSLogPipeStream nextLine.
+                    [line notNil
+                     and:[(line startsWith:Character space) or:[line startsWith:Character tab]]] whileTrue:[
+                        tokens := line asCollectionOfSubstringsSeparatedBy:$:.
+                        tags at:(tokens first withoutSeparators) put:(tokens second withoutSeparators).
+                        line:= aCVSLogPipeStream nextLine.
+                    ].
+                    info at:#symbolicNames put:tags.
+                ].
+                (line notNil and:[line startsWith:'description:']) ifTrue:[inHeaderInfo := false].
+            ]
+        ]
+    ].
+    aCVSLogPipeStream nextLine. "/ skip separating line after description.
+
+    info isEmpty ifTrue:[
+        ^ nil
+    ].
+
+    "/ strip selected revisions from the total-revisions entry
+    numberOfRevisionsString := info at:#numberOfRevisions.
+    (idx := numberOfRevisionsString indexOf:$;) ~~ 0 ifTrue:[
+        info at:#numberOfRevisions put:(Integer readFrom:(numberOfRevisionsString copyTo:idx - 1)).
+        idx := numberOfRevisionsString indexOf:$: startingAt:idx.
+        selectedRevisions := Integer readFrom:(numberOfRevisionsString copyFrom:idx+1) onError:0.
+    ] ifFalse:[
+        info at:#numberOfRevisions put:(Integer readFrom:numberOfRevisionsString onError:1).
+        selectedRevisions := 0.
+    ].
+    info at:#numberOfSelectedRevisions put:selectedRevisions.
+    
+    headerOnly ifFalse:[
+        "/
+        "/ continue to read the commands pipe output
+        "/ and extract revision info records
+        "/
+        aCVSLogPipeStream atEnd ifTrue:[
+            selectedRevisions > 0 ifTrue:[
+                "/ suppress warning. if we try to get the info of a non-existing revision"
+                "/ ('CVSSourceCodeManager [warning]: empty log for ', fullName) errorPrintCR.
+            ].
+            ^ info
+        ].
+
+        revisionRecords := OrderedCollection new:selectedRevisions.
+        info at:#revisions put:revisionRecords.
+
+        atEnd := false.
+        [atEnd or:[aCVSLogPipeStream atEnd]] whileFalse:[
+            |record|
+            
+            record := self readRevisionLogEntryFromStream:aCVSLogPipeStream.
+            record isNil ifTrue:[
+                atEnd := true.
+            ] ifFalse:[
+                revisionRecords add:record.
+            ].
+            (numRevisionsOrNil notNil and:[revisionRecords size >= numRevisionsOrNil]) ifTrue:[
+                atEnd := true
+            ]
+        ].
+    ].
+    ^ info
+
+    "Created: / 28-05-2019 / 13:54:26 / Claus Gittinger"
+!
+
 removeContainer:fileName inModule:moduleDir directory:packageDir
     "remove a container"
 
@@ -4841,92 +4939,94 @@
             ^ nil
         ].
 
-        "/
-        "/ read the commands pipe output and extract the container info
-        "/
-        info := IdentityDictionary new.
-        inHeaderInfo := true.
-        [inHeaderInfo and:[inStream atEnd not]] whileTrue:[
-            line:= inStream nextLine.
-            line notNil ifTrue:[
-                |gotIt|
-
-                gotIt := false.
-                #('RCS file:'        #container
-                  'Working file:'    #filename
-                  'head:'            #newestRevision
-                  'total revisions:' #numberOfRevisions
-                 ) pairWiseDo:[:word :key |
-                    gotIt ifFalse:[
-                        s := line restAfter:word withoutSeparators:true.
-                        s notNil ifTrue:[info at:key put:s. gotIt := true].
-                    ]
-                ].
-                gotIt ifFalse:[
-                    (line startsWith:'symbolic names:') ifTrue:[
-                        |tags tokens|
-
-                        tags := Dictionary new.
-                        line:= inStream nextLine.
-                        [line notNil
-                         and:[(line startsWith:Character space) or:[line startsWith:Character tab]]] whileTrue:[
-                            tokens := line asCollectionOfSubstringsSeparatedBy:$:.
-                            tags at:(tokens first withoutSeparators) put:(tokens second withoutSeparators).
-                            line:= inStream nextLine.
-                        ].
-                        info at:#symbolicNames put:tags.
-                    ].
-                    (line notNil and:[line startsWith:'description:']) ifTrue:[inHeaderInfo := false].
-                ]
-            ]
-        ].
-        inStream nextLine. "/ skip separating line after description.
-
-        info isEmpty ifTrue:[
-            ('CVSSourceCodeManager [warning]: no log for ', fullName) errorPrintCR.
-            ^ nil
-        ].
-
-        "/ strip selected revisions from the total-revisions entry
-        s := info at:#numberOfRevisions.
-        (idx := s indexOf:$;) ~~ 0 ifTrue:[
-            info at:#numberOfRevisions put:(Integer readFrom:(s copyTo:idx - 1)).
-            idx := s indexOf:$: startingAt:idx.
-            selectedRevisions := Integer readFrom:(s copyFrom:idx+1) onError:0.
-        ] ifFalse:[
-            info at:#numberOfRevisions put:(Integer readFrom:s onError:[1]).
-            selectedRevisions := 0.
-        ].
-        info at:#numberOfSelectedRevisions put:selectedRevisions.
-        headerOnly ifFalse:[
-            "/
-            "/ continue to read the commands pipe output
-            "/ and extract revision info records
-            "/
-            inStream atEnd ifTrue:[
-                selectedRevisions > 0 ifTrue:[
-                    "/ suppress warning. if we try to get the info of a non-existing revision"
-                    ('CVSSourceCodeManager [warning]: empty log for ', fullName) errorPrintCR.
-                ].
-                ^ info
-            ].
-
-            revisionRecords := OrderedCollection new:selectedRevisions.
-            info at:#revisions put:revisionRecords.
-
-            atEnd := false.
-            [atEnd or:[inStream atEnd]] whileFalse:[
-                record := self readRevisionLogEntryFromStream:inStream.
-                record isNil ifTrue:[
-                    atEnd := true.
-                ] ifFalse:[
-                    revisionRecords add:record.
-                ].
-                (numRevisionsOrNil notNil and:[revisionRecords size >= numRevisionsOrNil]) ifTrue:[
-                    atEnd := true
-                ]
-            ].
-        ].
+        info := self readRevisionLogFromStream:inStream headerOnly:headerOnly numRevisions:numRevisionsOrNil.
+
+"/        "/
+"/        "/ read the command's pipe output and extract the container info
+"/        "/
+"/        info := IdentityDictionary new.
+"/        inHeaderInfo := true.
+"/        [inHeaderInfo and:[inStream atEnd not]] whileTrue:[
+"/            line:= inStream nextLine.
+"/            line notNil ifTrue:[
+"/                |gotIt|
+"/
+"/                gotIt := false.
+"/                #('RCS file:'        #container
+"/                  'Working file:'    #filename
+"/                  'head:'            #newestRevision
+"/                  'total revisions:' #numberOfRevisions
+"/                 ) pairWiseDo:[:word :key |
+"/                    gotIt ifFalse:[
+"/                        s := line restAfter:word withoutSeparators:true.
+"/                        s notNil ifTrue:[info at:key put:s. gotIt := true].
+"/                    ]
+"/                ].
+"/                gotIt ifFalse:[
+"/                    (line startsWith:'symbolic names:') ifTrue:[
+"/                        |tags tokens|
+"/
+"/                        tags := Dictionary new.
+"/                        line:= inStream nextLine.
+"/                        [line notNil
+"/                         and:[(line startsWith:Character space) or:[line startsWith:Character tab]]] whileTrue:[
+"/                            tokens := line asCollectionOfSubstringsSeparatedBy:$:.
+"/                            tags at:(tokens first withoutSeparators) put:(tokens second withoutSeparators).
+"/                            line:= inStream nextLine.
+"/                        ].
+"/                        info at:#symbolicNames put:tags.
+"/                    ].
+"/                    (line notNil and:[line startsWith:'description:']) ifTrue:[inHeaderInfo := false].
+"/                ]
+"/            ]
+"/        ].
+"/        inStream nextLine. "/ skip separating line after description.
+"/
+"/        info isEmptyOrNil ifTrue:[
+"/            ('CVSSourceCodeManager [warning]: no log for ', fullName) errorPrintCR.
+"/            ^ nil
+"/        ].
+"/
+"/        "/ strip selected revisions from the total-revisions entry
+"/        s := info at:#numberOfRevisions.
+"/        (idx := s indexOf:$;) ~~ 0 ifTrue:[
+"/            info at:#numberOfRevisions put:(Integer readFrom:(s copyTo:idx - 1)).
+"/            idx := s indexOf:$: startingAt:idx.
+"/            selectedRevisions := Integer readFrom:(s copyFrom:idx+1) onError:0.
+"/        ] ifFalse:[
+"/            info at:#numberOfRevisions put:(Integer readFrom:s onError:[1]).
+"/            selectedRevisions := 0.
+"/        ].
+"/        info at:#numberOfSelectedRevisions put:selectedRevisions.
+"/        headerOnly ifFalse:[
+"/            "/
+"/            "/ continue to read the commands pipe output
+"/            "/ and extract revision info records
+"/            "/
+"/            inStream atEnd ifTrue:[
+"/                selectedRevisions > 0 ifTrue:[
+"/                    "/ suppress warning. if we try to get the info of a non-existing revision"
+"/                    ('CVSSourceCodeManager [warning]: empty log for ', fullName) errorPrintCR.
+"/                ].
+"/                ^ info
+"/            ].
+"/
+"/            revisionRecords := OrderedCollection new:selectedRevisions.
+"/            info at:#revisions put:revisionRecords.
+"/
+"/            atEnd := false.
+"/            [atEnd or:[inStream atEnd]] whileFalse:[
+"/                record := self readRevisionLogEntryFromStream:inStream.
+"/                record isNil ifTrue:[
+"/                    atEnd := true.
+"/                ] ifFalse:[
+"/                    revisionRecords add:record.
+"/                ].
+"/                (numRevisionsOrNil notNil and:[revisionRecords size >= numRevisionsOrNil]) ifTrue:[
+"/                    atEnd := true
+"/                ]
+"/            ].
+"/        ].
     ] ensure:[
         inStream notNil ifTrue:[inStream close].
 
@@ -4939,6 +5039,11 @@
         ].
         self activityNotification:nil.
     ].
+
+    info isEmptyOrNil ifTrue:[
+        ('CVSSourceCodeManager [warning]: no log for ', fullName) errorPrintCR.
+        ^ nil
+    ].
     ^ info
 
     "
@@ -4953,6 +5058,7 @@
     "Created: / 16-11-1995 / 13:25:30 / cg"
     "Modified: / 29-01-1997 / 16:51:30 / stefan"
     "Modified: / 06-12-2017 / 11:46:41 / cg"
+    "Modified: / 28-05-2019 / 13:56:39 / Claus Gittinger"
 !
 
 revisionLogOfPackageInDirectory:packageDir module:moduleDir