- Tools::TextMergeInfo
changed: #text1:text2:text3:
- Diff3
added: #mergeIndicesDiscardEmpty:
changed: #mergeIndices
--- a/Diff3.st Mon Apr 09 12:37:13 2012 +0100
+++ b/Diff3.st Mon Apr 09 19:34:24 2012 +0100
@@ -232,6 +232,21 @@
'false conflicts', and can return two Diff3Chunks next to each other in
the result."
+ ^self mergeIndicesDiscardEmpty: true
+
+ "Modified: / 09-04-2012 / 16:26:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+mergeIndicesDiscardEmpty: discardEmpty
+ "Returns an Array of Diff3Chunks (representing clean merges) or Diff3Conflicts
+ (containing DiffChunks, representing conflicts), together representing the
+ results of a three-way merge between file1/file0/file2. Does not detect
+ 'false conflicts', and can return two Diff3Chunks next to each other in
+ the result.
+
+ If discard empty is true, empty clean merge chunks are not included
+ "
+
| result commonOffset hunks lastOverlapHunkIndex hunk firstHunkIndex |
hunks := self computeHunks.
@@ -245,7 +260,9 @@
lastOverlapHunkIndex := self findOverlapStartingAt: firstHunkIndex in: hunks.
(firstHunkIndex = lastOverlapHunkIndex) ifTrue: [
- (hunk newChunk length > 0) ifTrue: [
+ (discardEmpty and:[hunk newChunk length == 0]) ifTrue:[
+ "/Empty chunk...
+ ] ifFalse:[
result add: (Diff3::Chunk side: hunk side chunk: hunk newChunk)
].
commonOffset := (hunks at: lastOverlapHunkIndex) oldChunk lastIndex + 1.
@@ -263,8 +280,7 @@
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>"
- "Modified (format): / 20-03-2012 / 18:07:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 09-04-2012 / 16:25:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!Diff3 methodsFor:'private'!
@@ -806,5 +822,5 @@
!Diff3 class methodsFor:'documentation'!
version_SVN
- ^ '$Id: Diff3.st 7974 2012-04-09 11:37:13Z vranyj1 $'
+ ^ '$Id: Diff3.st 7975 2012-04-09 18:34:24Z vranyj1 $'
! !
--- a/Tools__TextMergeInfo.st Mon Apr 09 12:37:13 2012 +0100
+++ b/Tools__TextMergeInfo.st Mon Apr 09 19:34:24 2012 +0100
@@ -85,7 +85,7 @@
text1: text1 text2: text2 text3: text3
- | t1c t2c t3c diff3 diffs merges resolution lnr |
+ | t1c t2c t3c diff3 diffs merges resolution lnr i |
list := StringCollection new.
listInfos := OrderedCollection new.
@@ -100,30 +100,34 @@
file1: t2c; "/A
file2: t3c. "/B\
diffs := diff3 diffIndices.
- merges := diff3 mergeIndices.
+ merges := diff3 mergeIndicesDiscardEmpty: false.
lnr := 1.
- diffs with: merges do:[:diff :merge|
- | lines |
+ i := 1.
+ [ i <= merges size ] whileTrue:[
+ | diff merge lines |
+
+ diff := diffs at: i.
+ merge := merges at: i.
diff isChunk ifTrue:[
lines := merge extractFromDiff: diff3.
- 1 to: diff length do:[:i|
- list add: (lines at: i).
- listInfos add: (LineInfo line: lnr resolution: #NoConflict conflict: diff offset: i ).
+ 1 to: diff length do:[:j|
+ list add: (lines at: j).
+ listInfos add: (LineInfo line: lnr resolution: #NoConflict conflict: diff offset: j ).
lnr := lnr + 1.
].
].
diff isConflict ifTrue:[
- 1 to: diff length do:[:i|
+ 1 to: diff length do:[:j|
merge isConflict ifTrue:[
list add: self conflictLineText.
- listInfos add: (LineInfo line: lnr resolution: #Conflict conflict: diff offset: i).
+ listInfos add: (LineInfo line: lnr resolution: #Conflict conflict: diff offset: j).
] ifFalse:[
lines := merge extractFromDiff: diff3.
resolution := merge extractResolution.
- i <= lines size ifTrue:[
- list add: (lines at: i).
- listInfos add: (LineInfo line: lnr resolution: resolution conflict: diff offset: i).
+ j <= lines size ifTrue:[
+ list add: (lines at: j).
+ listInfos add: (LineInfo line: lnr resolution: resolution conflict: diff offset: j).
] ifFalse:[
list add: self noSourceLineText.
listInfos add: (LineInfo line: lnr resolution: resolution conflict: diff offset: -1).
@@ -132,6 +136,13 @@
lnr := lnr + 1.
].
].
+ i := i + 1.
+ ].
+ "Sanity check:"
+ i < diffs size ifTrue:[
+ i + 1 to: diffs size do:[:j|
+ self assert: (diffs at:j) length == 0.
+ ]
].
self changed: #value
@@ -430,5 +441,5 @@
!TextMergeInfo class methodsFor:'documentation'!
version_SVN
- ^ '$Id: Tools__TextMergeInfo.st 7973 2012-04-06 15:56:16Z vranyj1 $'
+ ^ '$Id: Tools__TextMergeInfo.st 7975 2012-04-09 18:34:24Z vranyj1 $'
! !