Diff3TextView.st
changeset 2851 1d2fabb348d2
parent 2245 0d94b4d7d4bc
child 2852 ebc382a8d67f
--- a/Diff3TextView.st	Thu Nov 16 17:14:41 2000 +0100
+++ b/Diff3TextView.st	Thu Nov 16 18:34:35 2000 +0100
@@ -10,6 +10,8 @@
  hereby transferred.
 "
 
+"{ Package: 'stx:libtool' }"
+
 ThreeColumnTextView subclass:#Diff3TextView
 	instanceVariableNames:'useColors showSeparators addedColor addedBgColor removedColor
 		removedBgColor changedColor changedBgColor'
@@ -107,7 +109,12 @@
      CAVEAT: this is a highly specialized method - probably not the right place
      for it here ..."
 
-    |dIdx dEnd state s entry c list skip sep|
+    |dIdx dEnd state s entry c list skip l1 l2 buffer
+     sameAtStart sameAtEnd sepYourVersion sepOtherVersion sepLine|
+
+    sepYourVersion  := '----- your version -----'.
+    sepOtherVersion := '----- other version ----'.
+    sepLine := '------------------------'.
 
     list := OrderedCollection new.
 
@@ -127,13 +134,14 @@
         skip := false.
 
         entry notNil ifTrue:[
-            sep := nil.
-
             (entry startsWith:'<<<<<<<') ifTrue:[
-                state := 1. skip := true. sep := '----- your version ----'.
+                state := 1. skip := true. 
+                l1 := OrderedCollection new.
+                buffer := l1.
             ] ifFalse:[
                 (entry startsWith:'|||||||') ifTrue:[
                     state := 2. skip := true.
+                    buffer := nil.
                 ] ifFalse:[
                     (entry startsWith:'=======') ifTrue:[
                         state == 2 ifFalse:[
@@ -142,21 +150,43 @@
                             state := 3         "/ only in 3
                         ].
                         skip := true.
-                        sep := '----- other version ----'.
+                        l2 := OrderedCollection new.
+                        buffer := l2.
                     ] ifFalse:[
                         (entry startsWith:'>>>>>>>') ifTrue:[
                             state := #initial.
                             skip := true.
-                            sep := '------------------------'.
+                            buffer := nil.
                         ]
                     ]
                 ]
             ].
 
-            sep notNil ifTrue:[
-                list add:(Text 
-                            string:sep 
-                            emphasis:e3).
+            state == #initial ifTrue:[
+                l1 notNil ifTrue:[
+                    "/ diff3-output is sometimes stupid; fix some here
+                    sameAtStart := OrderedCollection new.
+                    [l1 notEmpty and:[l2 notEmpty and:[l1 first = l2 first or:[l1 first withTabsExpanded = l2 first withTabsExpanded]]]] whileTrue:[
+                        sameAtStart addLast:l1 removeFirst.
+                        l2 removeFirst
+                    ].
+                    sameAtEnd := OrderedCollection new.
+                    [l1 notEmpty and:[l2 notEmpty and:[l1 last = l2 last or:[l1 last withTabsExpanded = l2 last withTabsExpanded]]]] whileTrue:[
+                        sameAtEnd addFirst:l1 removeLast.
+                        l2 removeLast
+                    ].
+                    sameAtStart do:[:eachEntry | list add:eachEntry].
+
+                    (l1 notEmpty or:[l2 notEmpty]) ifTrue:[
+                        list add:(e3 isNil ifTrue:[sepYourVersion] ifFalse:[Text string:sepYourVersion emphasis:e3]).
+                        l1 do:[:eachEntry | list add:(e1 isNil ifTrue:[eachEntry] ifFalse:[Text string:eachEntry emphasis:e1])].
+                        list add:(e3 isNil ifTrue:[sepOtherVersion] ifFalse:[Text string:sepOtherVersion emphasis:e3]).
+                        l2 do:[:eachEntry | list add:(e2 isNil ifTrue:[eachEntry] ifFalse:[Text string:eachEntry emphasis:e2])].
+                        list add:(e3 isNil ifTrue:[sepLine] ifFalse:[Text string:sepLine emphasis:e3]).
+                    ].
+                    sameAtEnd do:[:eachEntry | list add:eachEntry].
+                    l1 := l2 := nil.
+                ].
             ].
 
             skip ifFalse:[
@@ -164,23 +194,41 @@
                     list add:entry
                 ].
                 state == 1 ifTrue:[
-                    e1 notNil ifTrue:[
-                        list add:(Text string:entry emphasis:e1)
-                    ] ifFalse:[
-                        list add:entry
-                    ]
+                    l1 add:entry.
+"/                    e1 notNil ifTrue:[
+"/                        list add:(Text string:entry emphasis:e1)
+"/                    ] ifFalse:[
+"/                        list add:entry
+"/                    ]
                 ].
                 (state == 3 or:[state == 23]) ifTrue:[
-                    e2 notNil ifTrue:[
-                        list add:(Text string:entry emphasis:e2)
-                    ] ifFalse:[
-                        list add:entry
-                    ]
+                    l2 add:entry
+"/                    e2 notNil ifTrue:[
+"/                        list add:(Text string:entry emphasis:e2)
+"/                    ] ifFalse:[
+"/                        list add:entry
+"/                    ]
                 ].
             ].
         ].
     ].
 
+    l1 notNil ifTrue:[
+        state ~~ #initial ifTrue:[self halt].
+
+        "/ diff3-output is sometimes stupid; fix some here
+        [l1 notEmpty and:[l2 notEmpty and:[l1 first = l2 first or:[l1 first withTabsExpanded = l2 first withTabsExpanded]]]] whileTrue:[l1 removeFirst. l2 removeFirst].
+        [l1 notEmpty and:[l2 notEmpty and:[l1 last = l2 last or:[l1 last withTabsExpanded = l2 last withTabsExpanded]]]] whileTrue:[l1 removeLast. l2 removeLast].
+
+        (l1 notEmpty or:[l2 notEmpty]) ifTrue:[
+            list add:(e3 isNil ifTrue:[sepYourVersion] ifFalse:[Text string:sepYourVersion emphasis:e3]).
+            l1 do:[:eachEntry | list add:(e1 isNil ifTrue:[eachEntry] ifFalse:[Text string:eachEntry emphasis:e1])].
+            list add:(e3 isNil ifTrue:[sepOtherVersion] ifFalse:[Text string:sepOtherVersion emphasis:e3]).
+            l2 do:[:eachEntry | list add:(e2 isNil ifTrue:[eachEntry] ifFalse:[Text string:eachEntry emphasis:e2])].
+            list add:(e3 isNil ifTrue:[sepLine] ifFalse:[Text string:sepLine emphasis:e3]).
+        ].
+        l1 := l2 := nil.
+    ].
     ^ list
 
     "Created: 9.9.1996 / 19:54:00 / cg"
@@ -337,5 +385,5 @@
 !Diff3TextView class methodsFor:'documentation'!
 
 version
-^ '$Header: /cvs/stx/stx/libtool/Diff3TextView.st,v 1.5 1999-07-09 14:55:32 cg Exp $'
+^ '$Header: /cvs/stx/stx/libtool/Diff3TextView.st,v 1.6 2000-11-16 17:34:35 cg Exp $'
 ! !