Fossil SCM

Infrastructure changes toward adding graphical merging options.

drh 2011-02-21 14:21 trunk
Commit b9abb86798611bd490b32acd19632aeb314d3a76
+2 -5
--- src/merge.c
+++ src/merge.c
@@ -346,11 +346,11 @@
346346
int ridv = db_column_int(&q, 3);
347347
int isBinary = db_column_int(&q, 4);
348348
const char *zName = db_column_text(&q, 5);
349349
int rc;
350350
char *zFullPath;
351
- Blob m, p, v, r;
351
+ Blob m, p, r;
352352
/* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */
353353
if( detailFlag ){
354354
printf("MERGE %s (pivot=%d v1=%d v2=%d)\n", zName, ridp, ridm, ridv);
355355
}else{
356356
printf("MERGE %s\n", zName);
@@ -357,17 +357,15 @@
357357
}
358358
undo_save(zName);
359359
zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
360360
content_get(ridp, &p);
361361
content_get(ridm, &m);
362
- blob_zero(&v);
363
- blob_read_from_file(&v, zFullPath);
364362
if( isBinary ){
365363
rc = -1;
366364
blob_zero(&r);
367365
}else{
368
- rc = blob_merge(&p, &v, &m, &r);
366
+ rc = merge_3way(&p, zFullPath, &m, &r);
369367
}
370368
if( rc>=0 ){
371369
if( !nochangeFlag ){
372370
blob_write_to_file(&r, zFullPath);
373371
}
@@ -380,11 +378,10 @@
380378
printf("***** Cannot merge binary file %s\n", zName);
381379
nConflict++;
382380
}
383381
blob_reset(&p);
384382
blob_reset(&m);
385
- blob_reset(&v);
386383
blob_reset(&r);
387384
db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
388385
idv,ridm);
389386
}
390387
db_finalize(&q);
391388
--- src/merge.c
+++ src/merge.c
@@ -346,11 +346,11 @@
346 int ridv = db_column_int(&q, 3);
347 int isBinary = db_column_int(&q, 4);
348 const char *zName = db_column_text(&q, 5);
349 int rc;
350 char *zFullPath;
351 Blob m, p, v, r;
352 /* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */
353 if( detailFlag ){
354 printf("MERGE %s (pivot=%d v1=%d v2=%d)\n", zName, ridp, ridm, ridv);
355 }else{
356 printf("MERGE %s\n", zName);
@@ -357,17 +357,15 @@
357 }
358 undo_save(zName);
359 zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
360 content_get(ridp, &p);
361 content_get(ridm, &m);
362 blob_zero(&v);
363 blob_read_from_file(&v, zFullPath);
364 if( isBinary ){
365 rc = -1;
366 blob_zero(&r);
367 }else{
368 rc = blob_merge(&p, &v, &m, &r);
369 }
370 if( rc>=0 ){
371 if( !nochangeFlag ){
372 blob_write_to_file(&r, zFullPath);
373 }
@@ -380,11 +378,10 @@
380 printf("***** Cannot merge binary file %s\n", zName);
381 nConflict++;
382 }
383 blob_reset(&p);
384 blob_reset(&m);
385 blob_reset(&v);
386 blob_reset(&r);
387 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
388 idv,ridm);
389 }
390 db_finalize(&q);
391
--- src/merge.c
+++ src/merge.c
@@ -346,11 +346,11 @@
346 int ridv = db_column_int(&q, 3);
347 int isBinary = db_column_int(&q, 4);
348 const char *zName = db_column_text(&q, 5);
349 int rc;
350 char *zFullPath;
351 Blob m, p, r;
352 /* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */
353 if( detailFlag ){
354 printf("MERGE %s (pivot=%d v1=%d v2=%d)\n", zName, ridp, ridm, ridv);
355 }else{
356 printf("MERGE %s\n", zName);
@@ -357,17 +357,15 @@
357 }
358 undo_save(zName);
359 zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
360 content_get(ridp, &p);
361 content_get(ridm, &m);
 
 
362 if( isBinary ){
363 rc = -1;
364 blob_zero(&r);
365 }else{
366 rc = merge_3way(&p, zFullPath, &m, &r);
367 }
368 if( rc>=0 ){
369 if( !nochangeFlag ){
370 blob_write_to_file(&r, zFullPath);
371 }
@@ -380,11 +378,10 @@
378 printf("***** Cannot merge binary file %s\n", zName);
379 nConflict++;
380 }
381 blob_reset(&p);
382 blob_reset(&m);
 
383 blob_reset(&r);
384 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
385 idv,ridm);
386 }
387 db_finalize(&q);
388
+31 -1
--- src/merge3.c
+++ src/merge3.c
@@ -144,11 +144,11 @@
144144
** The return is 0 upon complete success. If any input file is binary,
145145
** -1 is returned and pOut is unmodified. If there are merge
146146
** conflicts, the merge proceeds as best as it can and the number
147147
** of conflicts is returns
148148
*/
149
-int blob_merge(Blob *pPivot, Blob *pV1, Blob *pV2, Blob *pOut){
149
+static int blob_merge(Blob *pPivot, Blob *pV1, Blob *pV2, Blob *pOut){
150150
int *aC1; /* Changes from pPivot to pV1 */
151151
int *aC2; /* Changes from pPivot to pV2 */
152152
int i1, i2; /* Index into aC1[] and aC2[] */
153153
int nCpy, nDel, nIns; /* Number of lines to copy, delete, or insert */
154154
int limit1, limit2; /* Sizes of aC1[] and aC2[] */
@@ -329,5 +329,35 @@
329329
blob_reset(&pivot);
330330
blob_reset(&v1);
331331
blob_reset(&v2);
332332
blob_reset(&merged);
333333
}
334
+
335
+/*
336
+** This routine is a wrapper around blob_merge() with enhancements:
337
+**
338
+** (1) If the merge-command is defined, then use the external merging
339
+** program specified instead of the built-in blob-merge to do the
340
+** merging. Panic if the external merger fails.
341
+**
342
+** (2) If gmerge-command is defined and there are merge conflicts in
343
+** blob_merge() then invoke the external graphical merger to resolve
344
+** the conflicts.
345
+**
346
+** Otherwise, the interface and actions are the same as for blob_merge().
347
+**
348
+** The enhancements are planned - they are not yet implemented.
349
+*/
350
+int merge_3way(
351
+ Blob *pPivot, /* Common ancestor (older) */
352
+ const char *zV1, /* Name of file for version merging into (mine) */
353
+ Blob *pV2, /* Version merging from (yours) */
354
+ Blob *pOut /* Output written here */
355
+){
356
+ Blob v1; /* Content of zV1 */
357
+ int rc; /* Return code of subroutines and this routine */
358
+
359
+ blob_read_from_file(&v1, zV1);
360
+ rc = blob_merge(pPivot, &v1, pV2, pOut);
361
+ blob_reset(&v1);
362
+ return rc;
363
+}
334364
--- src/merge3.c
+++ src/merge3.c
@@ -144,11 +144,11 @@
144 ** The return is 0 upon complete success. If any input file is binary,
145 ** -1 is returned and pOut is unmodified. If there are merge
146 ** conflicts, the merge proceeds as best as it can and the number
147 ** of conflicts is returns
148 */
149 int blob_merge(Blob *pPivot, Blob *pV1, Blob *pV2, Blob *pOut){
150 int *aC1; /* Changes from pPivot to pV1 */
151 int *aC2; /* Changes from pPivot to pV2 */
152 int i1, i2; /* Index into aC1[] and aC2[] */
153 int nCpy, nDel, nIns; /* Number of lines to copy, delete, or insert */
154 int limit1, limit2; /* Sizes of aC1[] and aC2[] */
@@ -329,5 +329,35 @@
329 blob_reset(&pivot);
330 blob_reset(&v1);
331 blob_reset(&v2);
332 blob_reset(&merged);
333 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334
--- src/merge3.c
+++ src/merge3.c
@@ -144,11 +144,11 @@
144 ** The return is 0 upon complete success. If any input file is binary,
145 ** -1 is returned and pOut is unmodified. If there are merge
146 ** conflicts, the merge proceeds as best as it can and the number
147 ** of conflicts is returns
148 */
149 static int blob_merge(Blob *pPivot, Blob *pV1, Blob *pV2, Blob *pOut){
150 int *aC1; /* Changes from pPivot to pV1 */
151 int *aC2; /* Changes from pPivot to pV2 */
152 int i1, i2; /* Index into aC1[] and aC2[] */
153 int nCpy, nDel, nIns; /* Number of lines to copy, delete, or insert */
154 int limit1, limit2; /* Sizes of aC1[] and aC2[] */
@@ -329,5 +329,35 @@
329 blob_reset(&pivot);
330 blob_reset(&v1);
331 blob_reset(&v2);
332 blob_reset(&merged);
333 }
334
335 /*
336 ** This routine is a wrapper around blob_merge() with enhancements:
337 **
338 ** (1) If the merge-command is defined, then use the external merging
339 ** program specified instead of the built-in blob-merge to do the
340 ** merging. Panic if the external merger fails.
341 **
342 ** (2) If gmerge-command is defined and there are merge conflicts in
343 ** blob_merge() then invoke the external graphical merger to resolve
344 ** the conflicts.
345 **
346 ** Otherwise, the interface and actions are the same as for blob_merge().
347 **
348 ** The enhancements are planned - they are not yet implemented.
349 */
350 int merge_3way(
351 Blob *pPivot, /* Common ancestor (older) */
352 const char *zV1, /* Name of file for version merging into (mine) */
353 Blob *pV2, /* Version merging from (yours) */
354 Blob *pOut /* Output written here */
355 ){
356 Blob v1; /* Content of zV1 */
357 int rc; /* Return code of subroutines and this routine */
358
359 blob_read_from_file(&v1, zV1);
360 rc = blob_merge(pPivot, &v1, pV2, pOut);
361 blob_reset(&v1);
362 return rc;
363 }
364
+1 -1
--- src/stash.c
+++ src/stash.c
@@ -199,11 +199,11 @@
199199
blob_delta_apply(&a, &delta, &b);
200200
if( blob_compare(&disk, &a)==0 ){
201201
blob_write_to_file(&b, zNPath);
202202
printf("UPDATE %s\n", zNew);
203203
}else{
204
- int rc = blob_merge(&a, &disk, &b, &out);
204
+ int rc = merge_3way(&a, zOPath, &b, &out);
205205
blob_write_to_file(&out, zNPath);
206206
if( rc ){
207207
printf("CONFLICT %s\n", zNew);
208208
nConflict++;
209209
}else{
210210
--- src/stash.c
+++ src/stash.c
@@ -199,11 +199,11 @@
199 blob_delta_apply(&a, &delta, &b);
200 if( blob_compare(&disk, &a)==0 ){
201 blob_write_to_file(&b, zNPath);
202 printf("UPDATE %s\n", zNew);
203 }else{
204 int rc = blob_merge(&a, &disk, &b, &out);
205 blob_write_to_file(&out, zNPath);
206 if( rc ){
207 printf("CONFLICT %s\n", zNew);
208 nConflict++;
209 }else{
210
--- src/stash.c
+++ src/stash.c
@@ -199,11 +199,11 @@
199 blob_delta_apply(&a, &delta, &b);
200 if( blob_compare(&disk, &a)==0 ){
201 blob_write_to_file(&b, zNPath);
202 printf("UPDATE %s\n", zNew);
203 }else{
204 int rc = merge_3way(&a, zOPath, &b, &out);
205 blob_write_to_file(&out, zNPath);
206 if( rc ){
207 printf("CONFLICT %s\n", zNew);
208 nConflict++;
209 }else{
210
+2 -5
--- src/update.c
+++ src/update.c
@@ -362,23 +362,21 @@
362362
undo_save(zName);
363363
if( !nochangeFlag ) unlink(zFullPath);
364364
}
365365
}else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
366366
/* Merge the changes in the current tree into the target version */
367
- Blob e, r, t, v;
367
+ Blob r, t, v;
368368
int rc;
369369
if( nameChng ){
370370
printf("MERGE %s -> %s\n", zName, zNewName);
371371
}else{
372372
printf("MERGE %s\n", zName);
373373
}
374374
undo_save(zName);
375375
content_get(ridt, &t);
376376
content_get(ridv, &v);
377
- blob_zero(&e);
378
- blob_read_from_file(&e, zFullPath);
379
- rc = blob_merge(&v, &e, &t, &r);
377
+ rc = merge_3way(&v, zFullPath, &t, &r);
380378
if( rc>=0 ){
381379
if( !nochangeFlag ) blob_write_to_file(&r, zFullNewPath);
382380
if( rc>0 ){
383381
printf("***** %d merge conflicts in %s\n", rc, zNewName);
384382
nConflict++;
@@ -388,11 +386,10 @@
388386
printf("***** Cannot merge binary file %s\n", zNewName);
389387
nConflict++;
390388
}
391389
if( nameChng && !nochangeFlag ) unlink(zFullPath);
392390
blob_reset(&v);
393
- blob_reset(&e);
394391
blob_reset(&t);
395392
blob_reset(&r);
396393
}else{
397394
if( chnged ){
398395
if( verboseFlag ) printf("EDITED %s\n", zName);
399396
--- src/update.c
+++ src/update.c
@@ -362,23 +362,21 @@
362 undo_save(zName);
363 if( !nochangeFlag ) unlink(zFullPath);
364 }
365 }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
366 /* Merge the changes in the current tree into the target version */
367 Blob e, r, t, v;
368 int rc;
369 if( nameChng ){
370 printf("MERGE %s -> %s\n", zName, zNewName);
371 }else{
372 printf("MERGE %s\n", zName);
373 }
374 undo_save(zName);
375 content_get(ridt, &t);
376 content_get(ridv, &v);
377 blob_zero(&e);
378 blob_read_from_file(&e, zFullPath);
379 rc = blob_merge(&v, &e, &t, &r);
380 if( rc>=0 ){
381 if( !nochangeFlag ) blob_write_to_file(&r, zFullNewPath);
382 if( rc>0 ){
383 printf("***** %d merge conflicts in %s\n", rc, zNewName);
384 nConflict++;
@@ -388,11 +386,10 @@
388 printf("***** Cannot merge binary file %s\n", zNewName);
389 nConflict++;
390 }
391 if( nameChng && !nochangeFlag ) unlink(zFullPath);
392 blob_reset(&v);
393 blob_reset(&e);
394 blob_reset(&t);
395 blob_reset(&r);
396 }else{
397 if( chnged ){
398 if( verboseFlag ) printf("EDITED %s\n", zName);
399
--- src/update.c
+++ src/update.c
@@ -362,23 +362,21 @@
362 undo_save(zName);
363 if( !nochangeFlag ) unlink(zFullPath);
364 }
365 }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
366 /* Merge the changes in the current tree into the target version */
367 Blob r, t, v;
368 int rc;
369 if( nameChng ){
370 printf("MERGE %s -> %s\n", zName, zNewName);
371 }else{
372 printf("MERGE %s\n", zName);
373 }
374 undo_save(zName);
375 content_get(ridt, &t);
376 content_get(ridv, &v);
377 rc = merge_3way(&v, zFullPath, &t, &r);
 
 
378 if( rc>=0 ){
379 if( !nochangeFlag ) blob_write_to_file(&r, zFullNewPath);
380 if( rc>0 ){
381 printf("***** %d merge conflicts in %s\n", rc, zNewName);
382 nConflict++;
@@ -388,11 +386,10 @@
386 printf("***** Cannot merge binary file %s\n", zNewName);
387 nConflict++;
388 }
389 if( nameChng && !nochangeFlag ) unlink(zFullPath);
390 blob_reset(&v);
 
391 blob_reset(&t);
392 blob_reset(&r);
393 }else{
394 if( chnged ){
395 if( verboseFlag ) printf("EDITED %s\n", zName);
396

Keyboard Shortcuts

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