Fossil SCM
Enhancements to "fossil patch". The -f flag now causes a revert prior to applying the patch. The -f, -v and -n flags work with "patch push".
Commit
136d2004084130180da22cf6368c50fbf1b785dca6f554869fd21d0455d5f97a
Parent
08be0c75b9be066…
1 file changed
+30
-6
+30
-6
| --- src/patch.c | ||
| +++ src/patch.c | ||
| @@ -372,14 +372,28 @@ | ||
| 372 | 372 | */ |
| 373 | 373 | void patch_apply(unsigned mFlags){ |
| 374 | 374 | Stmt q; |
| 375 | 375 | Blob cmd; |
| 376 | 376 | |
| 377 | - if( (mFlags & PATCH_FORCE)==0 && unsaved_changes(0) ){ | |
| 378 | - fossil_fatal("there are unsaved changes in the current checkout"); | |
| 379 | - } | |
| 380 | 377 | blob_init(&cmd, 0, 0); |
| 378 | + if( unsaved_changes(0) ){ | |
| 379 | + if( (mFlags & PATCH_FORCE)==0 ){ | |
| 380 | + fossil_fatal("there are unsaved changes in the current checkout"); | |
| 381 | + }else{ | |
| 382 | + blob_appendf(&cmd, "%$ revert", g.nameOfExe); | |
| 383 | + if( mFlags & PATCH_DRYRUN ){ | |
| 384 | + fossil_print("%s\n", blob_str(&cmd)); | |
| 385 | + }else{ | |
| 386 | + int rc = fossil_system(blob_str(&cmd)); | |
| 387 | + if( rc ){ | |
| 388 | + fossil_fatal("unable to revert preexisting changes: %s", | |
| 389 | + blob_str(&cmd)); | |
| 390 | + } | |
| 391 | + } | |
| 392 | + blob_reset(&cmd); | |
| 393 | + } | |
| 394 | + } | |
| 381 | 395 | file_chdir(g.zLocalRoot, 0); |
| 382 | 396 | db_prepare(&q, |
| 383 | 397 | "SELECT patch.cfg.value" |
| 384 | 398 | " FROM patch.cfg, localdb.vvar" |
| 385 | 399 | " WHERE patch.cfg.key='baseline'" |
| @@ -653,11 +667,18 @@ | ||
| 653 | 667 | ){ |
| 654 | 668 | char *zRemote; |
| 655 | 669 | char *zDir; |
| 656 | 670 | Blob cmd; |
| 657 | 671 | FILE *f; |
| 658 | - const char *zForce = (mFlags & PATCH_FORCE)!=0 ? " -f" : ""; | |
| 672 | + Blob flgs; | |
| 673 | + char *zForce; | |
| 674 | + | |
| 675 | + blob_init(&flgs, 0, 0); | |
| 676 | + if( mFlags & PATCH_FORCE ) blob_appendf(&flgs, " -f"); | |
| 677 | + if( mFlags & PATCH_VERBOSE ) blob_appendf(&flgs, " -v"); | |
| 678 | + if( mFlags & PATCH_DRYRUN ) blob_appendf(&flgs, " -n"); | |
| 679 | + zForce = blob_size(&flgs)>0 ? blob_str(&flgs) : ""; | |
| 659 | 680 | if( g.argc!=4 ){ |
| 660 | 681 | usage(mprintf("%s [USER@]HOST:DIRECTORY", zThisCmd)); |
| 661 | 682 | } |
| 662 | 683 | zRemote = fossil_strdup(g.argv[3]); |
| 663 | 684 | zDir = (char*)file_skip_userhost(zRemote); |
| @@ -685,10 +706,11 @@ | ||
| 685 | 706 | f = popen(blob_str(&cmd), zRW); |
| 686 | 707 | if( f==0 ){ |
| 687 | 708 | fossil_fatal("cannot run command: %s", blob_str(&cmd)); |
| 688 | 709 | } |
| 689 | 710 | blob_reset(&cmd); |
| 711 | + blob_reset(&flgs); | |
| 690 | 712 | return f; |
| 691 | 713 | } |
| 692 | 714 | |
| 693 | 715 | /* |
| 694 | 716 | ** Show a diff for the patch currently loaded into database "patch". |
| @@ -839,11 +861,12 @@ | ||
| 839 | 861 | ** |
| 840 | 862 | ** Apply the changes in FILENAME to the check-out at DIRECTORY, or |
| 841 | 863 | ** in the current directory if DIRECTORY is omitted. Options: |
| 842 | 864 | ** |
| 843 | 865 | ** -f|--force Apply the patch even though there are unsaved |
| 844 | -** changes in the current check-out. | |
| 866 | +** changes in the current check-out. Unsaved changes | |
| 867 | +** are reverted and permanently lost. | |
| 845 | 868 | ** -n|--dryrun Do nothing, but print what would have happened. |
| 846 | 869 | ** -v|--verbose Extra output explaining what happens. |
| 847 | 870 | ** |
| 848 | 871 | ** > fossil patch diff [DIRECTORY] FILENAME |
| 849 | 872 | ** |
| @@ -871,11 +894,12 @@ | ||
| 871 | 894 | ** |
| 872 | 895 | ** Create a patch on a remote check-out, transfer that patch to the |
| 873 | 896 | ** local machine (using ssh) and apply the patch in the local checkout. |
| 874 | 897 | ** |
| 875 | 898 | ** -f|--force Apply the patch even though there are unsaved |
| 876 | -** changes in the current check-out. | |
| 899 | +** changes in the current check-out. Unsaved changes | |
| 900 | +** will be reverted and then the patch is applied. | |
| 877 | 901 | ** -n|--dryrun Do nothing, but print what would have happened. |
| 878 | 902 | ** -v|--verbose Extra output explaining what happens. |
| 879 | 903 | ** |
| 880 | 904 | ** > fossil patch view FILENAME |
| 881 | 905 | ** |
| 882 | 906 |
| --- src/patch.c | |
| +++ src/patch.c | |
| @@ -372,14 +372,28 @@ | |
| 372 | */ |
| 373 | void patch_apply(unsigned mFlags){ |
| 374 | Stmt q; |
| 375 | Blob cmd; |
| 376 | |
| 377 | if( (mFlags & PATCH_FORCE)==0 && unsaved_changes(0) ){ |
| 378 | fossil_fatal("there are unsaved changes in the current checkout"); |
| 379 | } |
| 380 | blob_init(&cmd, 0, 0); |
| 381 | file_chdir(g.zLocalRoot, 0); |
| 382 | db_prepare(&q, |
| 383 | "SELECT patch.cfg.value" |
| 384 | " FROM patch.cfg, localdb.vvar" |
| 385 | " WHERE patch.cfg.key='baseline'" |
| @@ -653,11 +667,18 @@ | |
| 653 | ){ |
| 654 | char *zRemote; |
| 655 | char *zDir; |
| 656 | Blob cmd; |
| 657 | FILE *f; |
| 658 | const char *zForce = (mFlags & PATCH_FORCE)!=0 ? " -f" : ""; |
| 659 | if( g.argc!=4 ){ |
| 660 | usage(mprintf("%s [USER@]HOST:DIRECTORY", zThisCmd)); |
| 661 | } |
| 662 | zRemote = fossil_strdup(g.argv[3]); |
| 663 | zDir = (char*)file_skip_userhost(zRemote); |
| @@ -685,10 +706,11 @@ | |
| 685 | f = popen(blob_str(&cmd), zRW); |
| 686 | if( f==0 ){ |
| 687 | fossil_fatal("cannot run command: %s", blob_str(&cmd)); |
| 688 | } |
| 689 | blob_reset(&cmd); |
| 690 | return f; |
| 691 | } |
| 692 | |
| 693 | /* |
| 694 | ** Show a diff for the patch currently loaded into database "patch". |
| @@ -839,11 +861,12 @@ | |
| 839 | ** |
| 840 | ** Apply the changes in FILENAME to the check-out at DIRECTORY, or |
| 841 | ** in the current directory if DIRECTORY is omitted. Options: |
| 842 | ** |
| 843 | ** -f|--force Apply the patch even though there are unsaved |
| 844 | ** changes in the current check-out. |
| 845 | ** -n|--dryrun Do nothing, but print what would have happened. |
| 846 | ** -v|--verbose Extra output explaining what happens. |
| 847 | ** |
| 848 | ** > fossil patch diff [DIRECTORY] FILENAME |
| 849 | ** |
| @@ -871,11 +894,12 @@ | |
| 871 | ** |
| 872 | ** Create a patch on a remote check-out, transfer that patch to the |
| 873 | ** local machine (using ssh) and apply the patch in the local checkout. |
| 874 | ** |
| 875 | ** -f|--force Apply the patch even though there are unsaved |
| 876 | ** changes in the current check-out. |
| 877 | ** -n|--dryrun Do nothing, but print what would have happened. |
| 878 | ** -v|--verbose Extra output explaining what happens. |
| 879 | ** |
| 880 | ** > fossil patch view FILENAME |
| 881 | ** |
| 882 |
| --- src/patch.c | |
| +++ src/patch.c | |
| @@ -372,14 +372,28 @@ | |
| 372 | */ |
| 373 | void patch_apply(unsigned mFlags){ |
| 374 | Stmt q; |
| 375 | Blob cmd; |
| 376 | |
| 377 | blob_init(&cmd, 0, 0); |
| 378 | if( unsaved_changes(0) ){ |
| 379 | if( (mFlags & PATCH_FORCE)==0 ){ |
| 380 | fossil_fatal("there are unsaved changes in the current checkout"); |
| 381 | }else{ |
| 382 | blob_appendf(&cmd, "%$ revert", g.nameOfExe); |
| 383 | if( mFlags & PATCH_DRYRUN ){ |
| 384 | fossil_print("%s\n", blob_str(&cmd)); |
| 385 | }else{ |
| 386 | int rc = fossil_system(blob_str(&cmd)); |
| 387 | if( rc ){ |
| 388 | fossil_fatal("unable to revert preexisting changes: %s", |
| 389 | blob_str(&cmd)); |
| 390 | } |
| 391 | } |
| 392 | blob_reset(&cmd); |
| 393 | } |
| 394 | } |
| 395 | file_chdir(g.zLocalRoot, 0); |
| 396 | db_prepare(&q, |
| 397 | "SELECT patch.cfg.value" |
| 398 | " FROM patch.cfg, localdb.vvar" |
| 399 | " WHERE patch.cfg.key='baseline'" |
| @@ -653,11 +667,18 @@ | |
| 667 | ){ |
| 668 | char *zRemote; |
| 669 | char *zDir; |
| 670 | Blob cmd; |
| 671 | FILE *f; |
| 672 | Blob flgs; |
| 673 | char *zForce; |
| 674 | |
| 675 | blob_init(&flgs, 0, 0); |
| 676 | if( mFlags & PATCH_FORCE ) blob_appendf(&flgs, " -f"); |
| 677 | if( mFlags & PATCH_VERBOSE ) blob_appendf(&flgs, " -v"); |
| 678 | if( mFlags & PATCH_DRYRUN ) blob_appendf(&flgs, " -n"); |
| 679 | zForce = blob_size(&flgs)>0 ? blob_str(&flgs) : ""; |
| 680 | if( g.argc!=4 ){ |
| 681 | usage(mprintf("%s [USER@]HOST:DIRECTORY", zThisCmd)); |
| 682 | } |
| 683 | zRemote = fossil_strdup(g.argv[3]); |
| 684 | zDir = (char*)file_skip_userhost(zRemote); |
| @@ -685,10 +706,11 @@ | |
| 706 | f = popen(blob_str(&cmd), zRW); |
| 707 | if( f==0 ){ |
| 708 | fossil_fatal("cannot run command: %s", blob_str(&cmd)); |
| 709 | } |
| 710 | blob_reset(&cmd); |
| 711 | blob_reset(&flgs); |
| 712 | return f; |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | ** Show a diff for the patch currently loaded into database "patch". |
| @@ -839,11 +861,12 @@ | |
| 861 | ** |
| 862 | ** Apply the changes in FILENAME to the check-out at DIRECTORY, or |
| 863 | ** in the current directory if DIRECTORY is omitted. Options: |
| 864 | ** |
| 865 | ** -f|--force Apply the patch even though there are unsaved |
| 866 | ** changes in the current check-out. Unsaved changes |
| 867 | ** are reverted and permanently lost. |
| 868 | ** -n|--dryrun Do nothing, but print what would have happened. |
| 869 | ** -v|--verbose Extra output explaining what happens. |
| 870 | ** |
| 871 | ** > fossil patch diff [DIRECTORY] FILENAME |
| 872 | ** |
| @@ -871,11 +894,12 @@ | |
| 894 | ** |
| 895 | ** Create a patch on a remote check-out, transfer that patch to the |
| 896 | ** local machine (using ssh) and apply the patch in the local checkout. |
| 897 | ** |
| 898 | ** -f|--force Apply the patch even though there are unsaved |
| 899 | ** changes in the current check-out. Unsaved changes |
| 900 | ** will be reverted and then the patch is applied. |
| 901 | ** -n|--dryrun Do nothing, but print what would have happened. |
| 902 | ** -v|--verbose Extra output explaining what happens. |
| 903 | ** |
| 904 | ** > fossil patch view FILENAME |
| 905 | ** |
| 906 |