More robust changeset reading - creates InvalidChange when an error
authorvrany
Tue, 24 Jan 2012 18:39:37 +0100
changeset 2745 c2f7200248e7
parent 2744 f4e60b8ad090
child 2746 ea46530f8ae7
More robust changeset reading - creates InvalidChange when an error occures while reading changeset. changed: #changesFromStream:for:reader:do:
ChangeSet.st
--- a/ChangeSet.st	Tue Jan 24 18:36:37 2012 +0100
+++ b/ChangeSet.st	Tue Jan 24 18:39:37 2012 +0100
@@ -21,7 +21,7 @@
 Object subclass:#ChangeFileReader
 	instanceVariableNames:'inputStream parseTree changeAction changeSet selector receiver
 		arguments receiverSelector receiverReceiver lineNumber position
-		className methodSelector'
+		className methodSelector chunk'
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:ChangeSet
@@ -634,6 +634,7 @@
                                         changesFromParseTree:tree 
                                         lineNumber:lineNumber
                                         position:pos
+                                        chunk: chunk
                                     ) ifFalse:[
                                         change := DoItChange new.
                                         change source:chunk.
@@ -658,8 +659,9 @@
      ChangeSet fromStream:(Object source asString readStream)
     "
 
-    "Created: / 16.2.1998 / 12:19:34 / cg"
-    "Modified: / 14.12.1999 / 15:23:16 / cg"
+    "Created: / 16-02-1998 / 12:19:34 / cg"
+    "Modified: / 14-12-1999 / 15:23:16 / cg"
+    "Modified: / 24-01-2012 / 17:28:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 skipEncodingChunkOn:stream
@@ -1539,45 +1541,6 @@
     "Modified: / 12-10-2006 / 16:51:32 / cg"
 !
 
-condenseChangesForPackage2:aPackageSymbol
-
-    "Like condenseChangesForPackage: but used by svn commit.
-     Bad naming here"
-
-
-    |changesToRemove|
-
-    changesToRemove := self select:[:aChange |
-        |removeThis mClass mthd|
-
-        removeThis := false.
-        (aChange isMethodChange or:[aChange isMethodRemoveChange]) ifTrue:[
-            mClass := aChange changeClass.
-            mClass notNil ifTrue:[
-                mthd := mClass compiledMethodAt:(aChange selector).
-                mthd isNil ifTrue:[
-                    removeThis := (mClass package = aPackageSymbol)
-                ] ifFalse:[
-                    removeThis := (mthd package = aPackageSymbol)
-                ]
-            ].
-        ] ifFalse:[
-            (aChange isClassChange) ifTrue:[
-                (aChange changeClass notNil) ifTrue:[
-                    removeThis := (aChange changeClass package = aPackageSymbol)
-                ].
-            ].
-        ].
-        removeThis
-    ].
-
-    self condenseChanges:changesToRemove
-
-    "Modified: / 12-10-2006 / 16:51:27 / cg"
-    "Created: / 09-08-2009 / 14:29:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
-    "Modified (comment): / 06-07-2011 / 13:35:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 condenseChangesForPackage:aPackageSymbol
     "remove all changes for aPackageSymbol
      This is invoked when a project is checked into the repository."
@@ -2025,6 +1988,8 @@
     ^(nameSpace ~~ Smalltalk and:[(clsName startsWith: nameSpace name) not])
         ifTrue:[nameSpace name , '::' , clsName]
         ifFalse:[clsName].
+
+    "Modified: / 24-01-2012 / 17:07:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 receiversClassName
@@ -2046,8 +2011,21 @@
      arg; the lineNumber is only valid, if the underlying inputStream 
      provides line-numbers; otherwise, nil is passed."
 
+    ^self changesFromParseTree:aTree lineNumber:initialLineNumberOrNil position:initialPositionOrNil chunk: nil
+
+    "Modified: / 24-01-2012 / 17:29:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+changesFromParseTree:aTree lineNumber:initialLineNumberOrNil position:initialPositionOrNil chunk: initialChunkOrNil
+    "given a parse-tree (from parsing some changes source/chunk),
+     create changes and evaluate changeAction on each.
+     The chnageAction-block is invoked with the change and a lineNumberOrNil as
+     arg; the lineNumber is only valid, if the underlying inputStream 
+     provides line-numbers; otherwise, nil is passed."
+
     lineNumber := initialLineNumberOrNil.
     position := initialPositionOrNil.
+    chunk := initialChunkOrNil.
     parseTree := aTree.
 
     selector := aTree selector.
@@ -2060,6 +2038,8 @@
     ].
 
     ^ self processChange
+
+    "Created: / 24-01-2012 / 17:28:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !ChangeSet::ChangeFileReader methodsFor:'reading-private'!
@@ -2241,6 +2221,28 @@
 !
 
 handleMethodChange
+    [
+        ^ self handleMethodChangeUnsafe
+    ] on: Error do:[:ex|
+        | change |
+
+        change := InvalidChange new source: chunk.
+        self addChange: change.
+
+        "Read methods that may follow"    
+
+        [ (chunk := inputStream nextChunk) notEmptyOrNil ] whileTrue:[
+            change := InvalidChange new source: chunk.
+            self addChange: change.
+        ]
+    ].
+
+    ^ true
+
+    "Modified (comment): / 24-01-2012 / 17:32:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+handleMethodChangeUnsafe
     |priv categoryName methodSource changes change parser |
 
     (selector == #'ignoredMethodsFor:') ifTrue:[
@@ -2267,7 +2269,7 @@
     lineNumber := inputStream lineNumber.
     position := inputStream position1Based.
 
-    methodSource := inputStream nextChunk.
+    methodSource := chunk := inputStream nextChunk.
     changes := OrderedCollection new.
 
     [methodSource notEmptyOrNil] whileTrue:[
@@ -2298,9 +2300,11 @@
         inputStream skipSeparators.
         lineNumber := inputStream lineNumber.
         position := inputStream position1Based.
-        methodSource := inputStream nextChunk.
+        methodSource := chunk := inputStream nextChunk.
     ].
     ^ true
+
+    "Created: / 24-01-2012 / 16:52:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 handleMethodPrivacyChange
@@ -2461,6 +2465,27 @@
      arg; the lineNumber is only valid, if the underlying stream 
      provides line-numbers; otherwise, nil is passed."
 
+    [
+        ^ self processChangeUnsafe
+    ] on: Error do:[:ex|
+        | change |
+
+        change := InvalidChange new source: chunk.
+        self addChange: change.
+    ].
+
+    ^true
+
+    "Modified: / 24-01-2012 / 17:34:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+processChangeUnsafe
+    "given a parse-tree (from parsing some changes source/chunk),
+     create changes and evaluate changeAction on each.
+     The block is invoked with the change and a lineNumberOrNil as
+     arg; the lineNumber is only valid, if the underlying stream 
+     provides line-numbers; otherwise, nil is passed."
+
     |dispatchSelector|
 
     dispatchSelector := ('process_',(selector copyReplaceAll:$: with:$_)) asSymbol.
@@ -2476,6 +2501,8 @@
     ].
 
     ^ false
+
+    "Created: / 24-01-2012 / 17:33:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 process_categoriesFor_
@@ -2998,6 +3025,6 @@
 !ChangeSet class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic3/ChangeSet.st,v 1.186 2011-12-01 18:18:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic3/ChangeSet.st,v 1.187 2012-01-24 17:39:37 vrany Exp $'
 
 ! !