Fossil SCM

More improvements to the 3-way merge. Additional test cases added.

drh 2009-03-21 19:18 trunk
Commit 81122988ba271d135ce26071eb584f0d8bbe1caf
+3 -3
--- src/merge3.c
+++ src/merge3.c
@@ -110,11 +110,11 @@
110110
int i, /* Index in aC[] of current location in pSrc */
111111
int sz /* Number of lines in unedited source to output */
112112
){
113113
while( sz>0 ){
114114
if( aC[i]==0 && aC[i+1]==0 && aC[i+2]==0 ) break;
115
- if( aC[i]>sz ){
115
+ if( aC[i]>=sz ){
116116
blob_copy_lines(pOut, pSrc, sz);
117117
aC[i] -= sz;
118118
break;
119119
}
120120
blob_copy_lines(pOut, pSrc, aC[i]);
@@ -192,21 +192,21 @@
192192
blob_copy_lines(0, pV1, nCpy);
193193
blob_copy_lines(0, pV2, nCpy);
194194
aC1[i1] -= nCpy;
195195
aC2[i2] -= nCpy;
196196
}else
197
- if( aC1[i1] >= aC2[i2+1] && aC2[i2+1]+aC2[i2+2]>0 ){
197
+ if( aC1[i1] >= aC2[i2+1] && aC1[i1]>0 && aC2[i2+1]+aC2[i2+2]>0 ){
198198
nDel = aC2[i2+1];
199199
nIns = aC2[i2+2];
200200
DEBUG( printf("EDIT -%d+%d left\n", nDel, nIns); )
201201
blob_copy_lines(0, pPivot, nDel);
202202
blob_copy_lines(0, pV1, nDel);
203203
blob_copy_lines(pOut, pV2, nIns);
204204
aC1[i1] -= nDel;
205205
i2 += 3;
206206
}else
207
- if( aC2[i2] >= aC1[i1+1] && aC1[i1+1]+aC1[i1+2]>0 ){
207
+ if( aC2[i2] >= aC1[i1+1] && aC2[i2]>0 && aC1[i1+1]+aC1[i1+2]>0 ){
208208
nDel = aC1[i1+1];
209209
nIns = aC1[i1+2];
210210
DEBUG( printf("EDIT -%d+%d right\n", nDel, nIns); )
211211
blob_copy_lines(0, pPivot, nDel);
212212
blob_copy_lines(0, pV2, nDel);
213213
--- src/merge3.c
+++ src/merge3.c
@@ -110,11 +110,11 @@
110 int i, /* Index in aC[] of current location in pSrc */
111 int sz /* Number of lines in unedited source to output */
112 ){
113 while( sz>0 ){
114 if( aC[i]==0 && aC[i+1]==0 && aC[i+2]==0 ) break;
115 if( aC[i]>sz ){
116 blob_copy_lines(pOut, pSrc, sz);
117 aC[i] -= sz;
118 break;
119 }
120 blob_copy_lines(pOut, pSrc, aC[i]);
@@ -192,21 +192,21 @@
192 blob_copy_lines(0, pV1, nCpy);
193 blob_copy_lines(0, pV2, nCpy);
194 aC1[i1] -= nCpy;
195 aC2[i2] -= nCpy;
196 }else
197 if( aC1[i1] >= aC2[i2+1] && aC2[i2+1]+aC2[i2+2]>0 ){
198 nDel = aC2[i2+1];
199 nIns = aC2[i2+2];
200 DEBUG( printf("EDIT -%d+%d left\n", nDel, nIns); )
201 blob_copy_lines(0, pPivot, nDel);
202 blob_copy_lines(0, pV1, nDel);
203 blob_copy_lines(pOut, pV2, nIns);
204 aC1[i1] -= nDel;
205 i2 += 3;
206 }else
207 if( aC2[i2] >= aC1[i1+1] && aC1[i1+1]+aC1[i1+2]>0 ){
208 nDel = aC1[i1+1];
209 nIns = aC1[i1+2];
210 DEBUG( printf("EDIT -%d+%d right\n", nDel, nIns); )
211 blob_copy_lines(0, pPivot, nDel);
212 blob_copy_lines(0, pV2, nDel);
213
--- src/merge3.c
+++ src/merge3.c
@@ -110,11 +110,11 @@
110 int i, /* Index in aC[] of current location in pSrc */
111 int sz /* Number of lines in unedited source to output */
112 ){
113 while( sz>0 ){
114 if( aC[i]==0 && aC[i+1]==0 && aC[i+2]==0 ) break;
115 if( aC[i]>=sz ){
116 blob_copy_lines(pOut, pSrc, sz);
117 aC[i] -= sz;
118 break;
119 }
120 blob_copy_lines(pOut, pSrc, aC[i]);
@@ -192,21 +192,21 @@
192 blob_copy_lines(0, pV1, nCpy);
193 blob_copy_lines(0, pV2, nCpy);
194 aC1[i1] -= nCpy;
195 aC2[i2] -= nCpy;
196 }else
197 if( aC1[i1] >= aC2[i2+1] && aC1[i1]>0 && aC2[i2+1]+aC2[i2+2]>0 ){
198 nDel = aC2[i2+1];
199 nIns = aC2[i2+2];
200 DEBUG( printf("EDIT -%d+%d left\n", nDel, nIns); )
201 blob_copy_lines(0, pPivot, nDel);
202 blob_copy_lines(0, pV1, nDel);
203 blob_copy_lines(pOut, pV2, nIns);
204 aC1[i1] -= nDel;
205 i2 += 3;
206 }else
207 if( aC2[i2] >= aC1[i1+1] && aC2[i2]>0 && aC1[i1+1]+aC1[i1+2]>0 ){
208 nDel = aC1[i1+1];
209 nIns = aC1[i1+2];
210 DEBUG( printf("EDIT -%d+%d right\n", nDel, nIns); )
211 blob_copy_lines(0, pPivot, nDel);
212 blob_copy_lines(0, pV2, nDel);
213
--- test/delta1.test
+++ test/delta1.test
@@ -32,10 +32,11 @@
3232
# work properly.
3333
#
3434
set filelist [glob $testdir/*]
3535
foreach f $filelist {
3636
set base [file root [file tail $f]]
37
+puts "base=$base f=$f"
3738
set f1 [read_file $f]
3839
write_file t1 $f1
3940
for {set i 0} {$i<100} {incr i} {
4041
write_file t2 [random_changes $f1 1 1 0 0.1]
4142
fossil test-delta t1 t2
4243
--- test/delta1.test
+++ test/delta1.test
@@ -32,10 +32,11 @@
32 # work properly.
33 #
34 set filelist [glob $testdir/*]
35 foreach f $filelist {
36 set base [file root [file tail $f]]
 
37 set f1 [read_file $f]
38 write_file t1 $f1
39 for {set i 0} {$i<100} {incr i} {
40 write_file t2 [random_changes $f1 1 1 0 0.1]
41 fossil test-delta t1 t2
42
--- test/delta1.test
+++ test/delta1.test
@@ -32,10 +32,11 @@
32 # work properly.
33 #
34 set filelist [glob $testdir/*]
35 foreach f $filelist {
36 set base [file root [file tail $f]]
37 puts "base=$base f=$f"
38 set f1 [read_file $f]
39 write_file t1 $f1
40 for {set i 0} {$i<100} {incr i} {
41 write_file t2 [random_changes $f1 1 1 0 0.1]
42 fossil test-delta t1 t2
43
+146 -5
--- test/merge1.test
+++ test/merge1.test
@@ -19,11 +19,11 @@
1919
# [email protected]
2020
# http://www.hwaci.com/drh/
2121
#
2222
############################################################################
2323
#
24
-# Tests of the delta mechanism.
24
+# Tests of the 3-way merge
2525
#
2626
2727
write_file_indented t1 {
2828
111 - This is line one of the demo program - 1111
2929
222 - The second line program line in code - 2222
@@ -77,24 +77,26 @@
7777
333 - This is a test of the merging algohm - 3333
7878
444 - If all goes well, we will be pleased - 4444
7979
555 - we think it well and other stuff too - 5555
8080
}
8181
write_file_indented t23 {
82
- >>>>>>>> BEGIN MERGE CONFLICT <<<<<<<<
82
+ >>>>>>> BEGIN MERGE CONFLICT
8383
111 - This is line ONE of the demo program - 1111
84
+ ============================
8485
111 - This is line one OF the demo program - 1111
85
- >>>>>>>>> END MERGE CONFLICT <<<<<<<<<
86
+ <<<<<<< END MERGE CONFLICT
8687
222 - The second line program line in code - 2222
8788
333 - This is a test of the merging algohm - 3333
8889
444 - If all goes well, we will be pleased - 4444
8990
555 - we think it well and other stuff too - 5555
9091
}
9192
write_file_indented t32 {
92
- >>>>>>>> BEGIN MERGE CONFLICT <<<<<<<<
93
+ >>>>>>> BEGIN MERGE CONFLICT
9394
111 - This is line one OF the demo program - 1111
95
+ ============================
9496
111 - This is line ONE of the demo program - 1111
95
- >>>>>>>>> END MERGE CONFLICT <<<<<<<<<
97
+ <<<<<<< END MERGE CONFLICT
9698
222 - The second line program line in code - 2222
9799
333 - This is a test of the merging algohm - 3333
98100
444 - If all goes well, we will be pleased - 4444
99101
555 - we think it well and other stuff too - 5555
100102
}
@@ -156,18 +158,26 @@
156158
333 - This is a test of the merging algohm - 3333
157159
444 - If all goes well, we will be pleased - 4444
158160
555 - we think it well and other stuff too - 5555
159161
}
160162
write_file_indented t32 {
163
+ >>>>>>> BEGIN MERGE CONFLICT
164
+ ============================
161165
000 - Zero lines added to the beginning of - 0000
166
+ 111 - This is line one of the demo program - 1111
167
+ <<<<<<< END MERGE CONFLICT
162168
222 - The second line program line in code - 2222
163169
333 - This is a test of the merging algohm - 3333
164170
444 - If all goes well, we will be pleased - 4444
165171
555 - we think it well and other stuff too - 5555
166172
}
167173
write_file_indented t23 {
174
+ >>>>>>> BEGIN MERGE CONFLICT
168175
000 - Zero lines added to the beginning of - 0000
176
+ 111 - This is line one of the demo program - 1111
177
+ ============================
178
+ <<<<<<< END MERGE CONFLICT
169179
222 - The second line program line in code - 2222
170180
333 - This is a test of the merging algohm - 3333
171181
444 - If all goes well, we will be pleased - 4444
172182
555 - we think it well and other stuff too - 5555
173183
}
@@ -235,5 +245,136 @@
235245
}
236246
fossil test-3 t1 t3 t2 a32
237247
test merge1-6.1 {[same_file t32 a32]}
238248
fossil test-3 t1 t2 t3 a23
239249
test merge1-6.2 {[same_file t32 a23]}
250
+
251
+write_file_indented t1 {
252
+ abcd
253
+ efgh
254
+ ijkl
255
+ mnop
256
+ qrst
257
+ uvwx
258
+ yzAB
259
+ CDEF
260
+ GHIJ
261
+ KLMN
262
+ OPQR
263
+ STUV
264
+ XYZ.
265
+}
266
+write_file_indented t2 {
267
+ abcd
268
+ efgh 2
269
+ ijkl 2
270
+ mnop 2
271
+ qrst
272
+ uvwx
273
+ yzAB 2
274
+ CDEF 2
275
+ GHIJ 2
276
+ KLMN
277
+ OPQR
278
+ STUV
279
+ XYZ.
280
+}
281
+write_file_indented t3 {
282
+ abcd
283
+ efgh
284
+ ijkl
285
+ mnop 3
286
+ qrst 3
287
+ uvwx 3
288
+ yzAB 3
289
+ CDEF
290
+ GHIJ
291
+ KLMN
292
+ OPQR
293
+ STUV
294
+ XYZ.
295
+}
296
+write_file_indented t23 {
297
+ abcd
298
+ >>>>>>> BEGIN MERGE CONFLICT
299
+ efgh 2
300
+ ijkl 2
301
+ mnop 2
302
+ qrst
303
+ uvwx
304
+ yzAB 2
305
+ CDEF 2
306
+ GHIJ 2
307
+ ============================
308
+ efgh
309
+ ijkl
310
+ mnop 3
311
+ qrst 3
312
+ uvwx 3
313
+ yzAB 3
314
+ CDEF
315
+ GHIJ
316
+ <<<<<<< END MERGE CONFLICT
317
+ KLMN
318
+ OPQR
319
+ STUV
320
+ XYZ.
321
+}
322
+fossil test-3 t1 t2 t3 a23
323
+test merge1-7.1 {[same_file t23 a23]}
324
+
325
+write_file_indented t2 {
326
+ abcd
327
+ efgh 2
328
+ ijkl 2
329
+ mnop
330
+ qrst
331
+ uvwx
332
+ yzAB 2
333
+ CDEF 2
334
+ GHIJ 2
335
+ KLMN
336
+ OPQR
337
+ STUV
338
+ XYZ.
339
+}
340
+write_file_indented t3 {
341
+ abcd
342
+ efgh
343
+ ijkl
344
+ mnop 3
345
+ qrst 3
346
+ uvwx 3
347
+ yzAB 3
348
+ CDEF
349
+ GHIJ
350
+ KLMN
351
+ OPQR
352
+ STUV
353
+ XYZ.
354
+}
355
+write_file_indented t23 {
356
+ abcd
357
+ efgh 2
358
+ ijkl 2
359
+ >>>>>>> BEGIN MERGE CONFLICT
360
+ mnop
361
+ qrst
362
+ uvwx
363
+ yzAB 2
364
+ CDEF 2
365
+ GHIJ 2
366
+ ============================
367
+ mnop 3
368
+ qrst 3
369
+ uvwx 3
370
+ yzAB 3
371
+ CDEF
372
+ GHIJ
373
+ <<<<<<< END MERGE CONFLICT
374
+ KLMN
375
+ OPQR
376
+ STUV
377
+ XYZ.
378
+}
379
+fossil test-3 t1 t2 t3 a23
380
+test merge1-7.2 {[same_file t23 a23]}
240381
--- test/merge1.test
+++ test/merge1.test
@@ -19,11 +19,11 @@
19 # [email protected]
20 # http://www.hwaci.com/drh/
21 #
22 ############################################################################
23 #
24 # Tests of the delta mechanism.
25 #
26
27 write_file_indented t1 {
28 111 - This is line one of the demo program - 1111
29 222 - The second line program line in code - 2222
@@ -77,24 +77,26 @@
77 333 - This is a test of the merging algohm - 3333
78 444 - If all goes well, we will be pleased - 4444
79 555 - we think it well and other stuff too - 5555
80 }
81 write_file_indented t23 {
82 >>>>>>>> BEGIN MERGE CONFLICT <<<<<<<<
83 111 - This is line ONE of the demo program - 1111
 
84 111 - This is line one OF the demo program - 1111
85 >>>>>>>>> END MERGE CONFLICT <<<<<<<<<
86 222 - The second line program line in code - 2222
87 333 - This is a test of the merging algohm - 3333
88 444 - If all goes well, we will be pleased - 4444
89 555 - we think it well and other stuff too - 5555
90 }
91 write_file_indented t32 {
92 >>>>>>>> BEGIN MERGE CONFLICT <<<<<<<<
93 111 - This is line one OF the demo program - 1111
 
94 111 - This is line ONE of the demo program - 1111
95 >>>>>>>>> END MERGE CONFLICT <<<<<<<<<
96 222 - The second line program line in code - 2222
97 333 - This is a test of the merging algohm - 3333
98 444 - If all goes well, we will be pleased - 4444
99 555 - we think it well and other stuff too - 5555
100 }
@@ -156,18 +158,26 @@
156 333 - This is a test of the merging algohm - 3333
157 444 - If all goes well, we will be pleased - 4444
158 555 - we think it well and other stuff too - 5555
159 }
160 write_file_indented t32 {
 
 
161 000 - Zero lines added to the beginning of - 0000
 
 
162 222 - The second line program line in code - 2222
163 333 - This is a test of the merging algohm - 3333
164 444 - If all goes well, we will be pleased - 4444
165 555 - we think it well and other stuff too - 5555
166 }
167 write_file_indented t23 {
 
168 000 - Zero lines added to the beginning of - 0000
 
 
 
169 222 - The second line program line in code - 2222
170 333 - This is a test of the merging algohm - 3333
171 444 - If all goes well, we will be pleased - 4444
172 555 - we think it well and other stuff too - 5555
173 }
@@ -235,5 +245,136 @@
235 }
236 fossil test-3 t1 t3 t2 a32
237 test merge1-6.1 {[same_file t32 a32]}
238 fossil test-3 t1 t2 t3 a23
239 test merge1-6.2 {[same_file t32 a23]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
--- test/merge1.test
+++ test/merge1.test
@@ -19,11 +19,11 @@
19 # [email protected]
20 # http://www.hwaci.com/drh/
21 #
22 ############################################################################
23 #
24 # Tests of the 3-way merge
25 #
26
27 write_file_indented t1 {
28 111 - This is line one of the demo program - 1111
29 222 - The second line program line in code - 2222
@@ -77,24 +77,26 @@
77 333 - This is a test of the merging algohm - 3333
78 444 - If all goes well, we will be pleased - 4444
79 555 - we think it well and other stuff too - 5555
80 }
81 write_file_indented t23 {
82 >>>>>>> BEGIN MERGE CONFLICT
83 111 - This is line ONE of the demo program - 1111
84 ============================
85 111 - This is line one OF the demo program - 1111
86 <<<<<<< END MERGE CONFLICT
87 222 - The second line program line in code - 2222
88 333 - This is a test of the merging algohm - 3333
89 444 - If all goes well, we will be pleased - 4444
90 555 - we think it well and other stuff too - 5555
91 }
92 write_file_indented t32 {
93 >>>>>>> BEGIN MERGE CONFLICT
94 111 - This is line one OF the demo program - 1111
95 ============================
96 111 - This is line ONE of the demo program - 1111
97 <<<<<<< END MERGE CONFLICT
98 222 - The second line program line in code - 2222
99 333 - This is a test of the merging algohm - 3333
100 444 - If all goes well, we will be pleased - 4444
101 555 - we think it well and other stuff too - 5555
102 }
@@ -156,18 +158,26 @@
158 333 - This is a test of the merging algohm - 3333
159 444 - If all goes well, we will be pleased - 4444
160 555 - we think it well and other stuff too - 5555
161 }
162 write_file_indented t32 {
163 >>>>>>> BEGIN MERGE CONFLICT
164 ============================
165 000 - Zero lines added to the beginning of - 0000
166 111 - This is line one of the demo program - 1111
167 <<<<<<< END MERGE CONFLICT
168 222 - The second line program line in code - 2222
169 333 - This is a test of the merging algohm - 3333
170 444 - If all goes well, we will be pleased - 4444
171 555 - we think it well and other stuff too - 5555
172 }
173 write_file_indented t23 {
174 >>>>>>> BEGIN MERGE CONFLICT
175 000 - Zero lines added to the beginning of - 0000
176 111 - This is line one of the demo program - 1111
177 ============================
178 <<<<<<< END MERGE CONFLICT
179 222 - The second line program line in code - 2222
180 333 - This is a test of the merging algohm - 3333
181 444 - If all goes well, we will be pleased - 4444
182 555 - we think it well and other stuff too - 5555
183 }
@@ -235,5 +245,136 @@
245 }
246 fossil test-3 t1 t3 t2 a32
247 test merge1-6.1 {[same_file t32 a32]}
248 fossil test-3 t1 t2 t3 a23
249 test merge1-6.2 {[same_file t32 a23]}
250
251 write_file_indented t1 {
252 abcd
253 efgh
254 ijkl
255 mnop
256 qrst
257 uvwx
258 yzAB
259 CDEF
260 GHIJ
261 KLMN
262 OPQR
263 STUV
264 XYZ.
265 }
266 write_file_indented t2 {
267 abcd
268 efgh 2
269 ijkl 2
270 mnop 2
271 qrst
272 uvwx
273 yzAB 2
274 CDEF 2
275 GHIJ 2
276 KLMN
277 OPQR
278 STUV
279 XYZ.
280 }
281 write_file_indented t3 {
282 abcd
283 efgh
284 ijkl
285 mnop 3
286 qrst 3
287 uvwx 3
288 yzAB 3
289 CDEF
290 GHIJ
291 KLMN
292 OPQR
293 STUV
294 XYZ.
295 }
296 write_file_indented t23 {
297 abcd
298 >>>>>>> BEGIN MERGE CONFLICT
299 efgh 2
300 ijkl 2
301 mnop 2
302 qrst
303 uvwx
304 yzAB 2
305 CDEF 2
306 GHIJ 2
307 ============================
308 efgh
309 ijkl
310 mnop 3
311 qrst 3
312 uvwx 3
313 yzAB 3
314 CDEF
315 GHIJ
316 <<<<<<< END MERGE CONFLICT
317 KLMN
318 OPQR
319 STUV
320 XYZ.
321 }
322 fossil test-3 t1 t2 t3 a23
323 test merge1-7.1 {[same_file t23 a23]}
324
325 write_file_indented t2 {
326 abcd
327 efgh 2
328 ijkl 2
329 mnop
330 qrst
331 uvwx
332 yzAB 2
333 CDEF 2
334 GHIJ 2
335 KLMN
336 OPQR
337 STUV
338 XYZ.
339 }
340 write_file_indented t3 {
341 abcd
342 efgh
343 ijkl
344 mnop 3
345 qrst 3
346 uvwx 3
347 yzAB 3
348 CDEF
349 GHIJ
350 KLMN
351 OPQR
352 STUV
353 XYZ.
354 }
355 write_file_indented t23 {
356 abcd
357 efgh 2
358 ijkl 2
359 >>>>>>> BEGIN MERGE CONFLICT
360 mnop
361 qrst
362 uvwx
363 yzAB 2
364 CDEF 2
365 GHIJ 2
366 ============================
367 mnop 3
368 qrst 3
369 uvwx 3
370 yzAB 3
371 CDEF
372 GHIJ
373 <<<<<<< END MERGE CONFLICT
374 KLMN
375 OPQR
376 STUV
377 XYZ.
378 }
379 fossil test-3 t1 t2 t3 a23
380 test merge1-7.2 {[same_file t23 a23]}
381

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button