Tools__Diff3CodeView2.st
branchjv
changeset 12202 eaa1f6cb6ce8
parent 12192 15f47901fb64
child 12226 4e263f50f1c6
--- a/Tools__Diff3CodeView2.st	Tue Mar 20 16:59:54 2012 +0000
+++ b/Tools__Diff3CodeView2.st	Wed Mar 21 01:52:35 2012 +0000
@@ -186,16 +186,20 @@
 addLines: total from: src to: dst offset: offset length: len
     | start stop |
 
-    start := offset.
-    stop  := (offset + len - 1).
+    start := offset max:1.
+    stop  := (offset + (len max:0) - 1).
 
 
-    start to: stop do:[:i|                     
-        dst add: (src at: i).
+    start to: (stop min: src size) do:[:i|                     
+        (src size >= i) ifTrue:[
+            dst add: (src at: i).
+        ] ifFalse:[
+            src add: nil.
+        ]
     ].
 
 
-    (total - (stop - start + 1)) timesRepeat: [ dst add: nil ].
+    (total - ((stop min: src size) - start + 1)) timesRepeat: [ dst add: nil ].
 
     "Created: / 16-03-2012 / 22:20:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
@@ -211,6 +215,78 @@
     inserted2 := OrderedCollection new.
     inserted3 := OrderedCollection new.
 
+"/    t1 isNil ifTrue:[ ^self ].
+"/    t2 isNil ifTrue:[ ^self ].
+"/    t3 isNil ifTrue:[ ^self ].
+
+
+    t1c := (text1 := t1 ? #()) asStringCollection.
+    t2c := (text2 := t2 ? #()) asStringCollection.
+    t3c := (text3 := t3 ? #()) asStringCollection.
+
+    
+    diff3chunks := Diff3 new
+                    file0: t1c; "/Base version
+                    file1: t2c; "/A
+                    file2: t3c; "/B
+                    diffIndices.
+    lnr := 1.
+    diff3chunks do:[:chunk|
+        | len |
+
+        len := chunk length.
+        chunk isConflict ifTrue:[
+            self addLines: len from: t1c to: list1 offset: chunk original offset length: chunk original length.
+            self addLines: len from: t2c to: list2 offset: chunk left     offset length: chunk left     length.
+            self addLines: len from: t3c to: list3 offset: chunk right    offset length: chunk right    length.
+            chunk isInsertionInOriginal ifTrue:[
+                lnr to:(lnr + len -1) do:[:i|inserted1 add: i].
+            ] ifFalse:[chunk isInsertionInLeft ifTrue:[
+                lnr to:(lnr + len -1) do:[:i|inserted2 add: i].
+            ] ifFalse:[chunk isInsertionInRight ifTrue:[
+                lnr to:(lnr + len -1) do:[:i|inserted3 add: i].
+            ] ifFalse:[
+                lnr to:(lnr + len -1) do:[:i|changed add: i].
+            ]]]
+        ].
+        chunk isChunk ifTrue:[
+            chunk side == #original ifTrue:[
+                self addLines: len from: t1c to: list1 offset: chunk offset length: len.
+                self addLines: len from: t1c to: list2 offset: chunk offset length: len.
+                self addLines: len from: t1c to: list3 offset: chunk offset length: len.
+            ].
+            chunk side == #left ifTrue:[
+                self breakPoint: #jv info: 'Should no longer happen'.
+                self addLines: len from: t1c to: list1 offset: chunk offset length: 0"len".
+                self addLines: len from: t2c to: list2 offset: chunk offset length: len.
+                self addLines: len from: t3c to: list3 offset: chunk offset length: 0"len".
+                lnr to:(lnr + len - 1) do:[:i| "changed"inserted2 add:i ].
+            ].
+            chunk side == #right ifTrue:[
+                self breakPoint: #jv info: 'Should no longer happen'.
+                self addLines: len from: t1c to: list1 offset: chunk offset length: 0"len".
+                self addLines: len from: t2c to: list2 offset: chunk offset length: 0"len".
+                self addLines: len from: t3c to: list3 offset: chunk offset length: len.
+                lnr to:(lnr + len - 1) do:[:i|"changed"inserted3 add: i].
+            ]
+        ].
+        lnr := lnr + len.
+    ].
+
+    "Created: / 16-03-2012 / 22:07:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+old_computeDiffDataForText1:t1 text2:t2 text3: t3
+    | t1c t2c  t3c  diff3chunks lnr |
+
+    list1 := StringCollection new.
+    list2 := StringCollection new.
+    list3 := StringCollection new.
+    changed := OrderedCollection new.
+    inserted1 := OrderedCollection new.
+    inserted2 := OrderedCollection new.
+    inserted3 := OrderedCollection new.
+
     t1 isNil ifTrue:[ ^self ].
     t2 isNil ifTrue:[ ^self ].
     t3 isNil ifTrue:[ ^self ].
@@ -267,11 +343,11 @@
         lnr := lnr + len.
     ].
 
-    "Created: / 16-03-2012 / 22:07:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 20-03-2012 / 17:42:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !Diff3CodeView2 class methodsFor:'documentation'!
 
 version_SVN
-    ^ '$Id: Tools__Diff3CodeView2.st 7938 2012-03-17 10:21:50Z vranyj1 $'
+    ^ '$Id: Tools__Diff3CodeView2.st 7948 2012-03-21 01:52:35Z vranyj1 $'
 ! !