13819
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libtool' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Tools }"
|
|
15 |
|
|
16 |
Object subclass:#TextMergeInfo
|
|
17 |
instanceVariableNames:'list listInfos'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-Diff'
|
|
21 |
!
|
|
22 |
|
|
23 |
Object subclass:#LineInfo
|
|
24 |
instanceVariableNames:'line resolution conflict offset'
|
|
25 |
classVariableNames:''
|
|
26 |
poolDictionaries:''
|
|
27 |
privateIn:TextMergeInfo
|
|
28 |
!
|
|
29 |
|
|
30 |
!TextMergeInfo class methodsFor:'documentation'!
|
|
31 |
|
|
32 |
copyright
|
|
33 |
"
|
|
34 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
35 |
All Rights Reserved
|
|
36 |
|
|
37 |
This software is furnished under a license and may be used
|
|
38 |
only in accordance with the terms of that license and with the
|
|
39 |
inclusion of the above copyright notice. This software may not
|
|
40 |
be provided or otherwise made available to, or used by, any
|
|
41 |
other person. No title to or ownership of the software is
|
|
42 |
hereby transferred.
|
|
43 |
"
|
|
44 |
! !
|
|
45 |
|
|
46 |
!TextMergeInfo methodsFor:'* uncategorized *'!
|
|
47 |
|
|
48 |
conflictLineText
|
|
49 |
|
16503
|
50 |
^ '<conflict>' allBold withColor: Color red.
|
13819
|
51 |
|
|
52 |
"Created: / 03-04-2012 / 23:26:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
53 |
!
|
|
54 |
|
|
55 |
noSourceLineText
|
|
56 |
|
16503
|
57 |
^'<no source line>' withColor: Color red.
|
13819
|
58 |
|
|
59 |
"Created: / 03-04-2012 / 23:26:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
60 |
! !
|
|
61 |
|
|
62 |
!TextMergeInfo methodsFor:'accessing'!
|
|
63 |
|
|
64 |
list
|
|
65 |
^ list
|
|
66 |
!
|
|
67 |
|
|
68 |
listInfos
|
|
69 |
^ listInfos
|
|
70 |
!
|
|
71 |
|
|
72 |
text
|
|
73 |
^String streamContents:[:s|
|
|
74 |
list withIndexDo:[:ln :i|
|
|
75 |
| info |
|
|
76 |
|
|
77 |
info := listInfos at: i ifAbsent:[nil].
|
|
78 |
(info isNil or:[info offset ~~ -1]) ifTrue:[
|
|
79 |
ln notNil ifTrue:[
|
|
80 |
s nextPutLine: (list at: i)
|
|
81 |
].
|
|
82 |
]
|
|
83 |
].
|
|
84 |
].
|
|
85 |
|
|
86 |
"Created: / 19-03-2012 / 14:58:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
87 |
! !
|
|
88 |
|
|
89 |
!TextMergeInfo methodsFor:'initialization'!
|
|
90 |
|
|
91 |
text1: text1 text2: text2 text3: text3
|
|
92 |
|
|
93 |
| t1c t2c t3c diff3 diffs merges resolution lnr i |
|
|
94 |
|
|
95 |
list := StringCollection new.
|
|
96 |
listInfos := OrderedCollection new.
|
|
97 |
|
|
98 |
t1c := (text1 ? #()) asStringCollection.
|
|
99 |
t2c := (text2 ? #()) asStringCollection.
|
|
100 |
t3c := (text3 ? #()) asStringCollection.
|
|
101 |
|
|
102 |
|
|
103 |
diff3 := Diff3 new
|
|
104 |
file0: t1c; "/Base version
|
|
105 |
file1: t2c; "/A
|
|
106 |
file2: t3c. "/B\
|
|
107 |
diffs := diff3 diffIndices.
|
|
108 |
merges := diff3 mergeIndicesDiscardEmpty: false.
|
|
109 |
|
|
110 |
lnr := 1.
|
|
111 |
i := 1.
|
|
112 |
[ i <= merges size ] whileTrue:[
|
|
113 |
| diff merge lines |
|
|
114 |
|
|
115 |
diff := diffs at: i.
|
|
116 |
merge := merges at: i.
|
|
117 |
diff isChunk ifTrue:[
|
|
118 |
lines := merge extractFromDiff: diff3.
|
|
119 |
1 to: diff length do:[:j|
|
|
120 |
list add: (lines at: j).
|
|
121 |
listInfos add: (LineInfo line: lnr resolution: #NoConflict conflict: diff offset: j ).
|
|
122 |
lnr := lnr + 1.
|
|
123 |
].
|
|
124 |
].
|
|
125 |
diff isConflict ifTrue:[
|
|
126 |
1 to: diff length do:[:j|
|
|
127 |
merge isConflict ifTrue:[
|
|
128 |
list add: self conflictLineText.
|
|
129 |
listInfos add: (LineInfo line: lnr resolution: #Conflict conflict: diff offset: j).
|
|
130 |
] ifFalse:[
|
|
131 |
lines := merge extractFromDiff: diff3.
|
|
132 |
resolution := merge extractResolution.
|
|
133 |
j <= lines size ifTrue:[
|
|
134 |
list add: (lines at: j).
|
|
135 |
listInfos add: (LineInfo line: lnr resolution: resolution conflict: diff offset: j).
|
|
136 |
] ifFalse:[
|
|
137 |
list add: self noSourceLineText.
|
|
138 |
listInfos add: (LineInfo line: lnr resolution: resolution conflict: diff offset: -1).
|
|
139 |
].
|
|
140 |
].
|
|
141 |
lnr := lnr + 1.
|
|
142 |
].
|
|
143 |
].
|
|
144 |
i := i + 1.
|
|
145 |
].
|
|
146 |
"Sanity check:"
|
|
147 |
i < diffs size ifTrue:[
|
|
148 |
i + 1 to: diffs size do:[:j|
|
|
149 |
self assert: (diffs at:j) length == 0.
|
|
150 |
]
|
|
151 |
].
|
|
152 |
|
|
153 |
self changed: #value
|
|
154 |
|
|
155 |
"Created: / 19-03-2012 / 12:10:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
156 |
! !
|
|
157 |
|
|
158 |
!TextMergeInfo methodsFor:'merging'!
|
|
159 |
|
|
160 |
mergeUsing: text
|
|
161 |
|
|
162 |
list := (text ? #()) asStringCollection.
|
|
163 |
listInfos :=
|
|
164 |
(1 to: list size) collect:[:lineNr|
|
|
165 |
(LineInfo line: lineNr resolution: #Merged )
|
|
166 |
].
|
|
167 |
self changed:#resolution
|
|
168 |
|
|
169 |
"Created: / 30-11-2012 / 14:12:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
170 |
!
|
|
171 |
|
|
172 |
mergeUsingA: textA
|
|
173 |
|
|
174 |
list := (textA ? #()) asStringCollection.
|
|
175 |
listInfos :=
|
|
176 |
(1 to: list size) collect:[:lineNr|
|
|
177 |
(LineInfo line: lineNr resolution: #MergedUsingA )
|
|
178 |
].
|
|
179 |
self changed:#resolution
|
|
180 |
|
|
181 |
"Created: / 21-03-2012 / 12:03:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
182 |
!
|
|
183 |
|
|
184 |
mergeUsingA: textA interval: interval
|
|
185 |
"Given textA and section interval, merges the section
|
|
186 |
using textA."
|
|
187 |
|
|
188 |
| listA offset |
|
|
189 |
listA := (textA ? '') asStringCollection.
|
|
190 |
offset := 0.
|
|
191 |
interval do:[:lineNr|
|
|
192 |
| info chunk line |
|
|
193 |
info := listInfos at: lineNr.
|
|
194 |
chunk := info conflict left.
|
|
195 |
offset < chunk length ifTrue:[
|
|
196 |
line := listA at: chunk offset + offset.
|
|
197 |
info offset: offset + 1.
|
|
198 |
] ifFalse:[
|
|
199 |
line := self noSourceLineText.
|
|
200 |
info offset: -1
|
|
201 |
].
|
|
202 |
list at: lineNr put: line.
|
|
203 |
info resolution: #MergedUsingA.
|
|
204 |
offset := offset + 1.
|
|
205 |
].
|
|
206 |
|
|
207 |
self changed:#resolution
|
|
208 |
|
|
209 |
"Created: / 04-04-2012 / 00:51:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
210 |
!
|
|
211 |
|
|
212 |
mergeUsingB: textB
|
|
213 |
|
|
214 |
list := (textB ? #()) asStringCollection.
|
|
215 |
listInfos :=
|
|
216 |
(1 to: list size) collect:[:lineNr|
|
|
217 |
(LineInfo line: lineNr resolution: #MergedUsingB )
|
|
218 |
].
|
|
219 |
self changed:#resulution
|
|
220 |
|
|
221 |
"Created: / 21-03-2012 / 12:04:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
222 |
!
|
|
223 |
|
|
224 |
mergeUsingB: textA interval: interval
|
|
225 |
"Given textA and section interval, merges the section
|
|
226 |
using textA."
|
|
227 |
|
|
228 |
| listA offset |
|
|
229 |
listA := (textA ? #()) asStringCollection.
|
|
230 |
offset := 0.
|
|
231 |
interval do:[:lineNr|
|
|
232 |
| info chunk line |
|
|
233 |
info := listInfos at: lineNr.
|
|
234 |
chunk := info conflict right.
|
|
235 |
offset < chunk length ifTrue:[
|
|
236 |
line := listA at: chunk offset + offset.
|
|
237 |
info offset: offset + 1.
|
|
238 |
] ifFalse:[
|
|
239 |
line := self noSourceLineText.
|
|
240 |
info offset: -1
|
|
241 |
].
|
|
242 |
list at: lineNr put: line.
|
|
243 |
info resolution: #MergedUsingB.
|
|
244 |
offset := offset + 1.
|
|
245 |
].
|
|
246 |
|
|
247 |
self changed:#resolution
|
|
248 |
|
|
249 |
"Created: / 04-04-2012 / 01:01:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
250 |
!
|
|
251 |
|
|
252 |
mergeUsingBase: textBase
|
|
253 |
|
|
254 |
list := (textBase ? #()) asStringCollection.
|
|
255 |
listInfos :=
|
|
256 |
(1 to: list size) collect:[:lineNr|
|
|
257 |
(LineInfo line: lineNr resolution: #MergedUsingBase )
|
|
258 |
].
|
|
259 |
self changed:#resulution
|
|
260 |
|
|
261 |
"Created: / 21-03-2012 / 12:07:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
262 |
!
|
|
263 |
|
|
264 |
mergeUsingBase: textA interval: interval
|
|
265 |
"Given textA and section interval, merges the section
|
|
266 |
using textA."
|
|
267 |
|
|
268 |
| listA offset |
|
|
269 |
listA := textA asStringCollection.
|
|
270 |
offset := 0.
|
|
271 |
interval do:[:lineNr|
|
|
272 |
| info chunk line |
|
|
273 |
info := listInfos at: lineNr.
|
|
274 |
chunk := info conflict original.
|
|
275 |
offset < chunk length ifTrue:[
|
|
276 |
line := listA at: chunk offset + offset.
|
|
277 |
info offset: offset + 1.
|
|
278 |
] ifFalse:[
|
|
279 |
line := self noSourceLineText.
|
|
280 |
info offset: -1
|
|
281 |
].
|
|
282 |
list at: lineNr put: line.
|
|
283 |
info resolution: #MergedUsingBase.
|
|
284 |
offset := offset + 1.
|
|
285 |
].
|
|
286 |
|
|
287 |
self changed:#resolution
|
|
288 |
|
|
289 |
"Created: / 04-04-2012 / 01:01:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
290 |
! !
|
|
291 |
|
|
292 |
!TextMergeInfo methodsFor:'testing'!
|
|
293 |
|
|
294 |
isMerged
|
|
295 |
|
|
296 |
^listInfos allSatisfy:[:info|info isMergedOrNoConflict].
|
|
297 |
|
|
298 |
"Created: / 19-03-2012 / 15:09:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
299 |
! !
|
|
300 |
|
|
301 |
!TextMergeInfo::LineInfo class methodsFor:'accessing'!
|
|
302 |
|
|
303 |
line:lineArg resolution:resolutionArg
|
|
304 |
^self new line:lineArg resolution:resolutionArg conflict:nil offset: nil
|
|
305 |
|
|
306 |
"Created: / 19-03-2012 / 15:04:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
307 |
!
|
|
308 |
|
|
309 |
line:lineArg resolution:resolutionArg conflict:conflictArg
|
|
310 |
|
|
311 |
^self new line:lineArg resolution:resolutionArg conflict:conflictArg
|
|
312 |
|
|
313 |
"Modified: / 19-03-2012 / 15:07:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
314 |
!
|
|
315 |
|
|
316 |
line:lineArg resolution:resolutionArg conflict:conflictArg offset: offsetArg
|
|
317 |
|
|
318 |
^self new line:lineArg resolution:resolutionArg conflict:conflictArg offset: offsetArg
|
|
319 |
|
|
320 |
"Modified: / 19-03-2012 / 15:07:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
321 |
"Created: / 20-03-2012 / 20:42:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
322 |
! !
|
|
323 |
|
|
324 |
!TextMergeInfo::LineInfo methodsFor:'accessing'!
|
|
325 |
|
|
326 |
color
|
|
327 |
|
|
328 |
| color |
|
|
329 |
|
|
330 |
self isMerged ifTrue:[
|
|
331 |
self isMergedUsingA ifTrue:[
|
|
332 |
color := Tools::TextDiff3Tool colorA
|
|
333 |
] ifFalse:[self isMergedUsingB ifTrue:[
|
|
334 |
color := Tools::TextDiff3Tool colorB
|
|
335 |
] ifFalse:[self isMergedUsingBase ifTrue:[
|
|
336 |
color := Tools::TextDiff3Tool colorBase
|
|
337 |
] ifFalse:[
|
|
338 |
color := Tools::TextDiff3Tool colorMerged
|
|
339 |
]]].
|
|
340 |
offset == -1 ifTrue:[
|
|
341 |
color := color lighter.
|
|
342 |
].
|
|
343 |
] ifFalse:[
|
|
344 |
self isConflict ifTrue:[
|
|
345 |
color := Tools::TextDiff3Tool colorConflict
|
|
346 |
].
|
|
347 |
].
|
|
348 |
|
|
349 |
^color
|
|
350 |
|
|
351 |
"Created: / 19-03-2012 / 15:05:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
352 |
!
|
|
353 |
|
|
354 |
conflict
|
|
355 |
^ conflict
|
|
356 |
!
|
|
357 |
|
|
358 |
line
|
|
359 |
^ line
|
|
360 |
!
|
|
361 |
|
|
362 |
line:lineArg resolution:resolutionArg
|
|
363 |
self line:lineArg resolution:resolutionArg conflict:nil offset: nil
|
|
364 |
|
|
365 |
"Created: / 19-03-2012 / 15:04:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
366 |
!
|
|
367 |
|
|
368 |
line:lineArg resolution:resolutionArg conflict:conflictArg offset: offsetArg
|
|
369 |
line := lineArg.
|
|
370 |
resolution := resolutionArg.
|
|
371 |
conflict := conflictArg.
|
|
372 |
offset := offsetArg
|
|
373 |
|
|
374 |
"Created: / 20-03-2012 / 20:41:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
375 |
!
|
|
376 |
|
|
377 |
offset
|
|
378 |
^ offset
|
|
379 |
!
|
|
380 |
|
|
381 |
offset:something
|
|
382 |
offset := something.
|
|
383 |
!
|
|
384 |
|
|
385 |
resolution
|
|
386 |
^ resolution
|
|
387 |
!
|
|
388 |
|
|
389 |
resolution:something
|
|
390 |
resolution := something.
|
|
391 |
! !
|
|
392 |
|
|
393 |
!TextMergeInfo::LineInfo methodsFor:'printing & storing'!
|
|
394 |
|
|
395 |
printOn:aStream
|
16787
|
396 |
"append a printed representation of the receiver to the argument, aStream"
|
13819
|
397 |
|
|
398 |
self class nameWithoutPrefix printOn:aStream.
|
|
399 |
aStream space.
|
|
400 |
aStream nextPutAll:'line: '.
|
|
401 |
line printOn:aStream.
|
|
402 |
aStream space.
|
|
403 |
aStream nextPutAll:'resolution: '.
|
|
404 |
resolution printOn:aStream.
|
|
405 |
|
|
406 |
"Modified: / 19-03-2012 / 12:30:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
407 |
"Created: / 19-03-2012 / 15:05:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
408 |
! !
|
|
409 |
|
|
410 |
!TextMergeInfo::LineInfo methodsFor:'testing'!
|
|
411 |
|
|
412 |
isConflict
|
|
413 |
|
|
414 |
^resolution == #Conflict
|
|
415 |
|
|
416 |
"Created: / 19-03-2012 / 15:06:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
417 |
!
|
|
418 |
|
|
419 |
isMerged
|
|
420 |
|
|
421 |
^
|
|
422 |
resolution == #Merged
|
|
423 |
or:[self isMergedUsingA
|
|
424 |
or:[self isMergedUsingB
|
|
425 |
or:[self isMergedUsingBase]]]
|
|
426 |
|
|
427 |
"Created: / 19-03-2012 / 15:06:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
428 |
!
|
|
429 |
|
|
430 |
isMergedOrNoConflict
|
|
431 |
|
|
432 |
^resolution == #NoConflict or:[self isMerged]
|
|
433 |
|
|
434 |
"Created: / 06-04-2012 / 10:40:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
435 |
!
|
|
436 |
|
|
437 |
isMergedUsingA
|
|
438 |
|
|
439 |
^resolution == #MergedUsingA
|
|
440 |
|
|
441 |
"Created: / 20-03-2012 / 14:21:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
442 |
!
|
|
443 |
|
|
444 |
isMergedUsingB
|
|
445 |
|
|
446 |
^resolution == #MergedUsingB
|
|
447 |
|
|
448 |
"Created: / 20-03-2012 / 14:21:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
449 |
!
|
|
450 |
|
|
451 |
isMergedUsingBase
|
|
452 |
|
|
453 |
^resolution == #MergedUsingBase
|
|
454 |
|
|
455 |
"Created: / 20-03-2012 / 14:21:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
456 |
! !
|
|
457 |
|
|
458 |
!TextMergeInfo class methodsFor:'documentation'!
|
|
459 |
|
|
460 |
version
|
16503
|
461 |
^ '$Header$'
|
13819
|
462 |
!
|
|
463 |
|
|
464 |
version_CVS
|
16503
|
465 |
^ '$Header$'
|
13819
|
466 |
! !
|
|
467 |
|