--- a/Diff3.st Thu Apr 05 18:53:51 2012 +0100
+++ b/Diff3.st Fri Apr 06 16:56:16 2012 +0100
@@ -175,18 +175,18 @@
commonOffset := 1.
firstHunkIndex := 1.
[firstHunkIndex <= hunks size] whileTrue: [
+ | conflict |
hunk := hunks at: firstHunkIndex.
self addCommonChunkTo: result between: commonOffset and: hunk oldChunk offset.
lastOverlapHunkIndex := self findOverlapStartingAt: firstHunkIndex in: hunks.
- "(firstHunkIndex = lastOverlapHunkIndex)"false ifTrue: [
- (hunk newChunk length > 0) ifTrue: [
- result add: (Diff3::Chunk side: hunk side chunk: hunk newChunk)
- ].
+ (firstHunkIndex = lastOverlapHunkIndex)"false" ifTrue: [
+ conflict := self computeConflictFromCleanMerge: hunk.
+ result add: conflict.
commonOffset := (hunks at: lastOverlapHunkIndex) oldChunk lastIndex + 1.
] ifFalse: [
- | conflict |
+
conflict := self computeConflictFrom: firstHunkIndex
to: lastOverlapHunkIndex
hunks: hunks.
@@ -199,7 +199,6 @@
self addCommonChunkTo: result between: commonOffset and: file0 size + 1.
^ result asArray
- "Modified: / 16-03-2012 / 19:24:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Created: / 20-03-2012 / 18:27:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
@@ -281,6 +280,24 @@
"Modified: / 16-03-2012 / 19:20:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+computeConflictChunk: side fromCleanMerge: hunk old: old new: new into: conflict
+
+ side == hunk side ifTrue:[
+ conflict at: side put: hunk newChunk.
+ ^self
+ ].
+ "Hmm....we have to compare"
+
+
+ (hunk newChunk extractSafeFrom: (self fileAt: side)) = new ifTrue:[
+ conflict at: side put: hunk newChunk.
+ ] ifFalse:[
+ conflict at: side put: hunk oldChunk.
+ ]
+
+ "Created: / 06-04-2012 / 12:31:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
computeConflictFrom: i1 to: i2 hunks: hunks
| hunk conflict l o r lo ro chunk chunkOrig |
conflict := Diff3::Conflict new.
@@ -307,6 +324,23 @@
"Modified: / 16-03-2012 / 19:20:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+computeConflictFromCleanMerge: hunk
+ | conflict old new |
+
+ conflict := Conflict new.
+
+ "/old := hunk oldChunk extractFrom: (self fileAt: hunk side).
+ new := hunk newChunk extractFrom: (self fileAt: hunk side).
+
+ self computeConflictChunk: #left fromCleanMerge: hunk old: old new: new into: conflict.
+ self computeConflictChunk: #original fromCleanMerge: hunk old: old new: new into: conflict.
+ self computeConflictChunk: #right fromCleanMerge: hunk old: old new: new into: conflict.
+
+ ^conflict.
+
+ "Created: / 06-04-2012 / 12:13:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
computeHunks
| diff2 diff1 hunks |
diff1 := self diffClass new file1: file0; file2: file1; diffIndices.
@@ -610,6 +644,39 @@
!Diff3::Conflict methodsFor:'accessing'!
+at: side
+
+ "Given a side (#left, #original or #right), returns the
+ corresponding chunk"
+
+ side == #left ifTrue:[ ^ left ].
+ side == #original ifTrue:[ ^ original ].
+ side == #right ifTrue:[ ^ right ].
+
+ self error:'Invalid parameter, must be one of #left, #original or #right'.
+
+ "Created: / 06-04-2012 / 12:26:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+at: side put: chunk
+
+ "Given a side (#left, #original or #right), sets the
+ corresponding chunk"
+
+ side == #left ifTrue:[ left := chunk. ^ self].
+ side == #original ifTrue:[ original := chunk. ^ self ].
+ side == #right ifTrue:[ right := chunk. ^ self ].
+
+ self error:'Invalid parameter, must be one of #left, #original or #right'.
+
+ "Created: / 06-04-2012 / 12:26:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+chunkAt: side
+
+ "Created: / 06-04-2012 / 12:25:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
left
^ left
!
@@ -743,5 +810,5 @@
!Diff3 class methodsFor:'documentation'!
version_SVN
- ^ '$Id: Diff3.st 7965 2012-04-04 00:09:32Z vranyj1 $'
+ ^ '$Id: Diff3.st 7973 2012-04-06 15:56:16Z vranyj1 $'
! !