initial checkin
authorvrany
Wed, 06 Jul 2011 13:47:14 +0200
changeset 2407 239b5c4aef83
parent 2406 cf06c39b234c
child 2408 c5c99ce9ab0d
initial checkin
ChangeSetDiff.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChangeSetDiff.st	Wed Jul 06 13:47:14 2011 +0200
@@ -0,0 +1,186 @@
+"
+ Copyright (c) 2007-2010 Jan Vrany, SWING Research Group,
+                           Czech Technical University in Prague
+ Copyright (c) 2009-2010 eXept Software AG
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+"
+"{ Package: 'stx:libbasic3' }"
+
+Object subclass:#ChangeSetDiff
+	instanceVariableNames:'diffset'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'System-Changes-Diff'
+!
+
+!ChangeSetDiff class methodsFor:'documentation'!
+
+copyright
+"
+ Copyright (c) 2007-2010 Jan Vrany, SWING Research Group,
+                           Czech Technical University in Prague
+ Copyright (c) 2009-2010 eXept Software AG
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+"
+! !
+
+!ChangeSetDiff class methodsFor:'instance creation'!
+
+new
+    ^ self basicNew initialize.
+! !
+
+!ChangeSetDiff class methodsFor:'utilities'!
+
+versionA:changesetA versionB:changesetB 
+    ^ (self new)
+        versionA:changesetA versionB:changesetB;
+        diffset
+
+    "Created: / 02-11-2009 / 16:12:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+versionA:changesetA versionB:changesetB versionBase: versionBase 
+    ^ (self new)
+        versionA:changesetA versionB:changesetB versionBase: versionBase;
+        diffset
+
+    "Created: / 03-11-2009 / 07:58:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ChangeSetDiff methodsFor:'accessing'!
+
+diffset
+    ^ diffset
+! !
+
+!ChangeSetDiff methodsFor:'diffing'!
+
+versionA:changesetA versionB:changesetB 
+
+    self versionA:changesetA versionB:changesetB versionBase: nil
+
+    "Created: / 31-10-2009 / 19:12:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-11-2009 / 18:38:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+versionA:a versionB:b versionBase: base
+    |ds diffsByClass  |
+
+    "For now, use diff algorithm in ChangeSet>>difSetsAgainst:
+     it looks very optimized"
+    diffsByClass := Dictionary new.
+    ds := a diffSetsAgainst:b.
+    ds onlyInReceiver do:
+        [:chg | 
+        (diffsByClass 
+            at: (chg nonMetaClassName ifNil:[chg class name])
+            ifAbsentPut:[ChangeSetDiffSet new name: chg nonMetaClassName]) 
+            add:(ChangeSetDiffEntry versionA:chg)].
+    ds changed do:
+        [:chgPair | | include |
+        include := chgPair first isMethodChange not
+                        or:[(AbstractSourceCodeManager isVersionMethodSelector:
+                            chgPair first selector) not].
+        include ifTrue:[
+        (diffsByClass 
+            at: chgPair first nonMetaClassName
+            ifAbsentPut:[ChangeSetDiffSet new name: chgPair first nonMetaClassName]) 
+            add:(ChangeSetDiffEntry versionA:chgPair first versionB:chgPair second)]].
+    ds onlyInArg do:
+        [:chg | 
+        (diffsByClass 
+            at: chg nonMetaClassName
+            ifAbsentPut:[ChangeSetDiffSet new name: chg nonMetaClassName]) 
+            add:(ChangeSetDiffEntry versionB:chg)].
+
+
+    base ifNotNil:[
+        "Try to assign base version to each diff item"
+        "Sorry, we are using O^2 algorithm here, I'm too lazy now :-)"
+        diffsByClass do:
+            [:diffs|
+            diffs do:
+                [:diff| | versionBase |
+                versionBase := base detect:[:each|each isForSameAs: diff versionA] ifNone:[nil].
+                versionBase ifNil:
+                    [diff versionA isClassRemoveChangeOrMethodRemoveChange not
+                        ifTrue:[versionBase := diff versionA asAntiChange]
+                        ifFalse:[versionBase := diff versionA copy]].
+                diff versionBase: versionBase.
+                diff automerge]]].
+
+    diffsByClass size = 1 
+        ifTrue:[diffset addAll: diffsByClass anyOne diffs]
+        ifFalse:[diffset addAll: diffsByClass values].
+
+    diffset versionALabel: a name.
+    diffset versionBLabel: b name.
+    base ifNotNil:[
+        diffset versionBaseLabel: base name.        
+    ].
+
+    "Created: / 02-11-2009 / 16:17:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-06-2011 / 08:22:49 / Jan Vrany <enter your email here>"
+    "Modified: / 06-07-2011 / 13:00:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ChangeSetDiff methodsFor:'initialization'!
+
+initialize
+    "Invoked when a new instance is created."
+
+    "/ please change as required (and remove this comment)
+    diffset := ChangeSetDiffSet new.
+
+    "/ super initialize.   -- commented since inherited method does nothing
+
+    "Modified: / 06-07-2011 / 13:00:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ChangeSetDiff class methodsFor:'documentation'!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libbasic3/ChangeSetDiff.st,v 1.1 2011-07-06 11:47:14 vrany Exp $'
+! !