added: #previousVersions:
authorClaus Gittinger <cg@exept.de>
Thu, 26 Jul 2012 13:21:51 +0200
changeset 14251 c0d549a59039
parent 14250 6ac82bdbffbc
child 14252 c6034c343ebb
added: #previousVersions: changed: #previousVersion #previousVersions refactored
Method.st
--- a/Method.st	Thu Jul 26 11:43:46 2012 +0200
+++ b/Method.st	Thu Jul 26 13:21:51 2012 +0200
@@ -2988,28 +2988,34 @@
 !
 
 previousVersion
-    "return the receivers previous versions source code"
-
-    |sel cls previous|
-
-    sel := self selector.
-    sel isNil ifTrue:[ ^ nil ].
-
-    cls := self mclass.
-    cls isNil ifTrue:[ ^ nil ].
-
-    ChangeSet current reverseDo:[:change |
-        (change isMethodChange
-        and:[ (change selector == sel)
-        and:[ change changeClass == cls ]])
-        ifTrue:[
-            previous := change previousVersion.
-            previous notNil ifTrue:[
-                ^ previous
-            ]
-        ]
-    ].
-    ^ nil.
+    "return the receivers previous version's source code"
+
+    |previous|
+
+    previous := self previousVersions:2.
+    previous isEmptyOrNil ifTrue:[^ nil].
+    ^ previous first.
+
+"/    |sel cls previous|
+"/
+"/    sel := self selector.
+"/    sel isNil ifTrue:[ ^ nil ].
+"/
+"/    cls := self mclass.
+"/    cls isNil ifTrue:[ ^ nil ].
+"/
+"/    ChangeSet current reverseDo:[:change |
+"/        (change isMethodChange
+"/            and:[ (change selector == sel)
+"/            and:[ change changeClass == cls ]])
+"/        ifTrue:[
+"/            previous := change previousVersion.
+"/            previous notNil ifTrue:[
+"/                ^ previous
+"/            ]
+"/        ]
+"/    ].
+"/    ^ nil.
 
 "/    history := Class methodHistory.
 "/    history isNil ifTrue:[^ nil].
@@ -3029,7 +3035,7 @@
 "/    ^ entry second.
 "/    ^ history at:self ifAbsent:nil
 
-    "Modified: 7.11.1996 / 19:06:22 / cg"
+    "Modified: / 26-07-2012 / 13:16:34 / cg"
 !
 
 previousVersionCode
@@ -3044,7 +3050,16 @@
 !
 
 previousVersions
-    "return a collection of the receivers previous versions (sources)"
+    "return a collection of the receiver's previous versions (sources)"
+
+    ^ self previousVersions:nil
+
+    "Modified (comment): / 26-07-2012 / 12:04:15 / cg"
+!
+
+previousVersions:count
+    "return a collection of the receiver's count previous versions (sources).
+     A nil count will retrieve all versions"
 
     |sel cls versions lastChange firstSrc last|
 
@@ -3057,12 +3072,15 @@
     versions := OrderedCollection new.
 
     ChangeSet current reverseDo:[:change |
-         (change isMethodChange
-        and:[ (change selector == sel)
-        and:[ change changeClass == cls ]])
+        (change isMethodChange
+            and:[ (change selector == sel)
+            and:[ change changeClass == cls ]])
         ifTrue:[
             versions addFirst:change.
             lastChange := change.
+            (count notNil and:[versions size == count]) ifTrue:[
+                ^ versions
+            ]
         ]
     ].
 
@@ -3081,6 +3099,12 @@
         ]
     ].
     ^ versions
+
+    "
+     (Method compiledMethodAt:#previousVersions:) previousVersions:nil
+    "
+
+    "Created: / 26-07-2012 / 11:59:57 / cg"
 !
 
 readsField:instVarIndex
@@ -3665,11 +3689,11 @@
 !Method class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.388 2012-07-23 09:17:47 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.389 2012-07-26 11:21:51 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.388 2012-07-23 09:17:47 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.389 2012-07-26 11:21:51 cg Exp $'
 !
 
 version_SVN