Fossil SCM
Infrastructure changes toward adding graphical merging options.
Commit
b9abb86798611bd490b32acd19632aeb314d3a76
Parent
88383d8d4ac1dd7…
4 files changed
+2
-5
+31
-1
+1
-1
+2
-5
+2
-5
| --- src/merge.c | ||
| +++ src/merge.c | ||
| @@ -346,11 +346,11 @@ | ||
| 346 | 346 | int ridv = db_column_int(&q, 3); |
| 347 | 347 | int isBinary = db_column_int(&q, 4); |
| 348 | 348 | const char *zName = db_column_text(&q, 5); |
| 349 | 349 | int rc; |
| 350 | 350 | char *zFullPath; |
| 351 | - Blob m, p, v, r; | |
| 351 | + Blob m, p, r; | |
| 352 | 352 | /* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */ |
| 353 | 353 | if( detailFlag ){ |
| 354 | 354 | printf("MERGE %s (pivot=%d v1=%d v2=%d)\n", zName, ridp, ridm, ridv); |
| 355 | 355 | }else{ |
| 356 | 356 | printf("MERGE %s\n", zName); |
| @@ -357,17 +357,15 @@ | ||
| 357 | 357 | } |
| 358 | 358 | undo_save(zName); |
| 359 | 359 | zFullPath = mprintf("%s/%s", g.zLocalRoot, zName); |
| 360 | 360 | content_get(ridp, &p); |
| 361 | 361 | content_get(ridm, &m); |
| 362 | - blob_zero(&v); | |
| 363 | - blob_read_from_file(&v, zFullPath); | |
| 364 | 362 | if( isBinary ){ |
| 365 | 363 | rc = -1; |
| 366 | 364 | blob_zero(&r); |
| 367 | 365 | }else{ |
| 368 | - rc = blob_merge(&p, &v, &m, &r); | |
| 366 | + rc = merge_3way(&p, zFullPath, &m, &r); | |
| 369 | 367 | } |
| 370 | 368 | if( rc>=0 ){ |
| 371 | 369 | if( !nochangeFlag ){ |
| 372 | 370 | blob_write_to_file(&r, zFullPath); |
| 373 | 371 | } |
| @@ -380,11 +378,10 @@ | ||
| 380 | 378 | printf("***** Cannot merge binary file %s\n", zName); |
| 381 | 379 | nConflict++; |
| 382 | 380 | } |
| 383 | 381 | blob_reset(&p); |
| 384 | 382 | blob_reset(&m); |
| 385 | - blob_reset(&v); | |
| 386 | 383 | blob_reset(&r); |
| 387 | 384 | db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)", |
| 388 | 385 | idv,ridm); |
| 389 | 386 | } |
| 390 | 387 | db_finalize(&q); |
| 391 | 388 |
| --- 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 @@ | ||
| 144 | 144 | ** The return is 0 upon complete success. If any input file is binary, |
| 145 | 145 | ** -1 is returned and pOut is unmodified. If there are merge |
| 146 | 146 | ** conflicts, the merge proceeds as best as it can and the number |
| 147 | 147 | ** of conflicts is returns |
| 148 | 148 | */ |
| 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){ | |
| 150 | 150 | int *aC1; /* Changes from pPivot to pV1 */ |
| 151 | 151 | int *aC2; /* Changes from pPivot to pV2 */ |
| 152 | 152 | int i1, i2; /* Index into aC1[] and aC2[] */ |
| 153 | 153 | int nCpy, nDel, nIns; /* Number of lines to copy, delete, or insert */ |
| 154 | 154 | int limit1, limit2; /* Sizes of aC1[] and aC2[] */ |
| @@ -329,5 +329,35 @@ | ||
| 329 | 329 | blob_reset(&pivot); |
| 330 | 330 | blob_reset(&v1); |
| 331 | 331 | blob_reset(&v2); |
| 332 | 332 | blob_reset(&merged); |
| 333 | 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 | +} | |
| 334 | 364 |
| --- 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 @@ | ||
| 199 | 199 | blob_delta_apply(&a, &delta, &b); |
| 200 | 200 | if( blob_compare(&disk, &a)==0 ){ |
| 201 | 201 | blob_write_to_file(&b, zNPath); |
| 202 | 202 | printf("UPDATE %s\n", zNew); |
| 203 | 203 | }else{ |
| 204 | - int rc = blob_merge(&a, &disk, &b, &out); | |
| 204 | + int rc = merge_3way(&a, zOPath, &b, &out); | |
| 205 | 205 | blob_write_to_file(&out, zNPath); |
| 206 | 206 | if( rc ){ |
| 207 | 207 | printf("CONFLICT %s\n", zNew); |
| 208 | 208 | nConflict++; |
| 209 | 209 | }else{ |
| 210 | 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 = 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 @@ | ||
| 362 | 362 | undo_save(zName); |
| 363 | 363 | if( !nochangeFlag ) unlink(zFullPath); |
| 364 | 364 | } |
| 365 | 365 | }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){ |
| 366 | 366 | /* Merge the changes in the current tree into the target version */ |
| 367 | - Blob e, r, t, v; | |
| 367 | + Blob r, t, v; | |
| 368 | 368 | int rc; |
| 369 | 369 | if( nameChng ){ |
| 370 | 370 | printf("MERGE %s -> %s\n", zName, zNewName); |
| 371 | 371 | }else{ |
| 372 | 372 | printf("MERGE %s\n", zName); |
| 373 | 373 | } |
| 374 | 374 | undo_save(zName); |
| 375 | 375 | content_get(ridt, &t); |
| 376 | 376 | 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); | |
| 380 | 378 | if( rc>=0 ){ |
| 381 | 379 | if( !nochangeFlag ) blob_write_to_file(&r, zFullNewPath); |
| 382 | 380 | if( rc>0 ){ |
| 383 | 381 | printf("***** %d merge conflicts in %s\n", rc, zNewName); |
| 384 | 382 | nConflict++; |
| @@ -388,11 +386,10 @@ | ||
| 388 | 386 | printf("***** Cannot merge binary file %s\n", zNewName); |
| 389 | 387 | nConflict++; |
| 390 | 388 | } |
| 391 | 389 | if( nameChng && !nochangeFlag ) unlink(zFullPath); |
| 392 | 390 | blob_reset(&v); |
| 393 | - blob_reset(&e); | |
| 394 | 391 | blob_reset(&t); |
| 395 | 392 | blob_reset(&r); |
| 396 | 393 | }else{ |
| 397 | 394 | if( chnged ){ |
| 398 | 395 | if( verboseFlag ) printf("EDITED %s\n", zName); |
| 399 | 396 |
| --- 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 |