Fossil SCM
Add the -f flag to "fossil patch diff".
Commit
5ee62c4033e8362769fa56cbef53c74a68ec3e5119a797dac1c6365c87ed1721
Parent
962694ada0de586…
1 file changed
+56
-35
+56
-35
| --- src/patch.c | ||
| +++ src/patch.c | ||
| @@ -703,50 +703,54 @@ | ||
| 703 | 703 | |
| 704 | 704 | /* |
| 705 | 705 | ** Show a diff for the patch currently loaded into database "patch". |
| 706 | 706 | */ |
| 707 | 707 | static void patch_diff( |
| 708 | + unsigned mFlags, /* Patch flags. only -f is allowed */ | |
| 708 | 709 | const char *zDiffCmd, /* Command used for diffing */ |
| 709 | 710 | const char *zBinGlob, /* GLOB pattern to determine binary files */ |
| 710 | 711 | int fIncludeBinary, /* Do diffs against binary files */ |
| 711 | 712 | u64 diffFlags /* Other diff flags */ |
| 712 | 713 | ){ |
| 714 | + int nErr = 0; | |
| 713 | 715 | Stmt q; |
| 714 | 716 | Blob empty; |
| 715 | 717 | blob_zero(&empty); |
| 716 | 718 | |
| 717 | - /* Check to ensure that the patch against the repository that we | |
| 718 | - ** have opened. | |
| 719 | - ** | |
| 720 | - ** To do: If there is a mismatch, should we scan all of the repositories | |
| 721 | - ** listed in the global_config table looking for a match? | |
| 722 | - */ | |
| 723 | - if( db_exists( | |
| 724 | - "SELECT 1 FROM patch.cfg" | |
| 725 | - " WHERE cfg.key='baseline'" | |
| 726 | - " AND NOT EXISTS(SELECT 1 FROM blob WHERE uuid=cfg.value)" | |
| 727 | - )){ | |
| 728 | - char *zBaseline; | |
| 729 | - db_prepare(&q, | |
| 730 | - "SELECT config.value, cfg.value FROM config, cfg" | |
| 731 | - " WHERE config.name='project-name'" | |
| 732 | - " AND cfg.key='project-name'" | |
| 733 | - " AND config.value<>cfg.value" | |
| 734 | - ); | |
| 735 | - if( db_step(&q)==SQLITE_ROW ){ | |
| 736 | - char *zRepo = fossil_strdup(db_column_text(&q,0)); | |
| 737 | - char *zPatch = fossil_strdup(db_column_text(&q,1)); | |
| 738 | - db_finalize(&q); | |
| 739 | - fossil_fatal("the patch is against project \"%z\" but you are using " | |
| 740 | - "project \"%z\"", zPatch, zRepo); | |
| 741 | - } | |
| 742 | - db_finalize(&q); | |
| 743 | - zBaseline = db_text(0, "SELECT value FROM patch.cfg" | |
| 744 | - " WHERE key='baseline'"); | |
| 745 | - if( zBaseline ){ | |
| 746 | - fossil_fatal("the baseline of the patch (check-in %S) is not found " | |
| 747 | - "in the %s repository", zBaseline, g.zRepositoryName); | |
| 719 | + if( (mFlags & PATCH_FORCE)==0 ){ | |
| 720 | + /* Check to ensure that the patch against the repository that we | |
| 721 | + ** have opened. | |
| 722 | + ** | |
| 723 | + ** To do: If there is a mismatch, should we scan all of the repositories | |
| 724 | + ** listed in the global_config table looking for a match? | |
| 725 | + */ | |
| 726 | + if( db_exists( | |
| 727 | + "SELECT 1 FROM patch.cfg" | |
| 728 | + " WHERE cfg.key='baseline'" | |
| 729 | + " AND NOT EXISTS(SELECT 1 FROM blob WHERE uuid=cfg.value)" | |
| 730 | + )){ | |
| 731 | + char *zBaseline; | |
| 732 | + db_prepare(&q, | |
| 733 | + "SELECT config.value, cfg.value FROM config, cfg" | |
| 734 | + " WHERE config.name='project-name'" | |
| 735 | + " AND cfg.key='project-name'" | |
| 736 | + " AND config.value<>cfg.value" | |
| 737 | + ); | |
| 738 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 739 | + char *zRepo = fossil_strdup(db_column_text(&q,0)); | |
| 740 | + char *zPatch = fossil_strdup(db_column_text(&q,1)); | |
| 741 | + db_finalize(&q); | |
| 742 | + fossil_fatal("the patch is against project \"%z\" but you are using " | |
| 743 | + "project \"%z\"", zPatch, zRepo); | |
| 744 | + } | |
| 745 | + db_finalize(&q); | |
| 746 | + zBaseline = db_text(0, "SELECT value FROM patch.cfg" | |
| 747 | + " WHERE key='baseline'"); | |
| 748 | + if( zBaseline ){ | |
| 749 | + fossil_fatal("the baseline of the patch (check-in %S) is not found " | |
| 750 | + "in the %s repository", zBaseline, g.zRepositoryName); | |
| 751 | + } | |
| 748 | 752 | } |
| 749 | 753 | } |
| 750 | 754 | |
| 751 | 755 | db_prepare(&q, |
| 752 | 756 | "SELECT" |
| @@ -767,12 +771,22 @@ | ||
| 767 | 771 | if( db_column_type(&q,0)!=SQLITE_INTEGER |
| 768 | 772 | && db_column_type(&q,4)==SQLITE_TEXT |
| 769 | 773 | ){ |
| 770 | 774 | char *zUuid = fossil_strdup(db_column_text(&q,4)); |
| 771 | 775 | char *zName = fossil_strdup(db_column_text(&q,1)); |
| 772 | - db_finalize(&q); | |
| 773 | - fossil_fatal("base artifact %S for file \"%s\" not found", zUuid, zName); | |
| 776 | + if( mFlags && PATCH_FORCE ){ | |
| 777 | + fossil_print("ERROR cannot find base artifact %S for file \"%s\"\n", | |
| 778 | + zUuid, zName); | |
| 779 | + nErr++; | |
| 780 | + fossil_free(zUuid); | |
| 781 | + fossil_free(zName); | |
| 782 | + continue; | |
| 783 | + }else{ | |
| 784 | + db_finalize(&q); | |
| 785 | + fossil_fatal("base artifact %S for file \"%s\" not found", | |
| 786 | + zUuid, zName); | |
| 787 | + } | |
| 774 | 788 | } |
| 775 | 789 | zName = db_column_text(&q, 1); |
| 776 | 790 | rid = db_column_int(&q, 0); |
| 777 | 791 | |
| 778 | 792 | if( db_column_type(&q,3)==SQLITE_NULL ){ |
| @@ -807,10 +821,11 @@ | ||
| 807 | 821 | blob_reset(&b); |
| 808 | 822 | blob_reset(&delta); |
| 809 | 823 | } |
| 810 | 824 | } |
| 811 | 825 | db_finalize(&q); |
| 826 | + if( nErr ) fossil_fatal("abort due to prior errors"); | |
| 812 | 827 | } |
| 813 | 828 | |
| 814 | 829 | |
| 815 | 830 | /* |
| 816 | 831 | ** COMMAND: patch |
| @@ -842,11 +857,15 @@ | ||
| 842 | 857 | ** -v|--verbose Extra output explaining what happens. |
| 843 | 858 | ** |
| 844 | 859 | ** > fossil patch diff [DIRECTORY] FILENAME |
| 845 | 860 | ** |
| 846 | 861 | ** Show a human-readable diff for the patch. All the usual |
| 847 | -** diff flags apply. (See help for "fossil diff"). | |
| 862 | +** diff flags described at "fossil help diff" apply. In addition: | |
| 863 | +** | |
| 864 | +** -f|--force Continue trying to perform the diff even if | |
| 865 | +** baseline information is missing from the current | |
| 866 | +** repository | |
| 848 | 867 | ** |
| 849 | 868 | ** > fossil patch push REMOTE-CHECKOUT |
| 850 | 869 | ** |
| 851 | 870 | ** Create a patch for the current check-out, transfer that patch to |
| 852 | 871 | ** a remote machine (using ssh) and apply the patch there. The |
| @@ -912,10 +931,11 @@ | ||
| 912 | 931 | const char *zDiffCmd = 0; |
| 913 | 932 | const char *zBinGlob = 0; |
| 914 | 933 | int fIncludeBinary = 0; |
| 915 | 934 | u64 diffFlags; |
| 916 | 935 | char *zIn; |
| 936 | + unsigned flags = 0; | |
| 917 | 937 | |
| 918 | 938 | if( find_option("tk",0,0)!=0 ){ |
| 919 | 939 | db_close(0); |
| 920 | 940 | diff_tk("patch diff", 3); |
| 921 | 941 | return; |
| @@ -928,14 +948,15 @@ | ||
| 928 | 948 | if( zDiffCmd ){ |
| 929 | 949 | zBinGlob = diff_get_binary_glob(); |
| 930 | 950 | fIncludeBinary = diff_include_binary_files(); |
| 931 | 951 | } |
| 932 | 952 | db_find_and_open_repository(0, 0); |
| 953 | + if( find_option("force","f",0) ) flags |= PATCH_FORCE; | |
| 933 | 954 | verify_all_options(); |
| 934 | 955 | zIn = patch_find_patch_filename("apply"); |
| 935 | 956 | patch_attach(zIn, stdin); |
| 936 | - patch_diff( zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); | |
| 957 | + patch_diff(flags, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); | |
| 937 | 958 | fossil_free(zIn); |
| 938 | 959 | }else |
| 939 | 960 | if( strncmp(zCmd, "pull", n)==0 ){ |
| 940 | 961 | FILE *pIn = 0; |
| 941 | 962 | unsigned flags = 0; |
| 942 | 963 |
| --- src/patch.c | |
| +++ src/patch.c | |
| @@ -703,50 +703,54 @@ | |
| 703 | |
| 704 | /* |
| 705 | ** Show a diff for the patch currently loaded into database "patch". |
| 706 | */ |
| 707 | static void patch_diff( |
| 708 | const char *zDiffCmd, /* Command used for diffing */ |
| 709 | const char *zBinGlob, /* GLOB pattern to determine binary files */ |
| 710 | int fIncludeBinary, /* Do diffs against binary files */ |
| 711 | u64 diffFlags /* Other diff flags */ |
| 712 | ){ |
| 713 | Stmt q; |
| 714 | Blob empty; |
| 715 | blob_zero(&empty); |
| 716 | |
| 717 | /* Check to ensure that the patch against the repository that we |
| 718 | ** have opened. |
| 719 | ** |
| 720 | ** To do: If there is a mismatch, should we scan all of the repositories |
| 721 | ** listed in the global_config table looking for a match? |
| 722 | */ |
| 723 | if( db_exists( |
| 724 | "SELECT 1 FROM patch.cfg" |
| 725 | " WHERE cfg.key='baseline'" |
| 726 | " AND NOT EXISTS(SELECT 1 FROM blob WHERE uuid=cfg.value)" |
| 727 | )){ |
| 728 | char *zBaseline; |
| 729 | db_prepare(&q, |
| 730 | "SELECT config.value, cfg.value FROM config, cfg" |
| 731 | " WHERE config.name='project-name'" |
| 732 | " AND cfg.key='project-name'" |
| 733 | " AND config.value<>cfg.value" |
| 734 | ); |
| 735 | if( db_step(&q)==SQLITE_ROW ){ |
| 736 | char *zRepo = fossil_strdup(db_column_text(&q,0)); |
| 737 | char *zPatch = fossil_strdup(db_column_text(&q,1)); |
| 738 | db_finalize(&q); |
| 739 | fossil_fatal("the patch is against project \"%z\" but you are using " |
| 740 | "project \"%z\"", zPatch, zRepo); |
| 741 | } |
| 742 | db_finalize(&q); |
| 743 | zBaseline = db_text(0, "SELECT value FROM patch.cfg" |
| 744 | " WHERE key='baseline'"); |
| 745 | if( zBaseline ){ |
| 746 | fossil_fatal("the baseline of the patch (check-in %S) is not found " |
| 747 | "in the %s repository", zBaseline, g.zRepositoryName); |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | db_prepare(&q, |
| 752 | "SELECT" |
| @@ -767,12 +771,22 @@ | |
| 767 | if( db_column_type(&q,0)!=SQLITE_INTEGER |
| 768 | && db_column_type(&q,4)==SQLITE_TEXT |
| 769 | ){ |
| 770 | char *zUuid = fossil_strdup(db_column_text(&q,4)); |
| 771 | char *zName = fossil_strdup(db_column_text(&q,1)); |
| 772 | db_finalize(&q); |
| 773 | fossil_fatal("base artifact %S for file \"%s\" not found", zUuid, zName); |
| 774 | } |
| 775 | zName = db_column_text(&q, 1); |
| 776 | rid = db_column_int(&q, 0); |
| 777 | |
| 778 | if( db_column_type(&q,3)==SQLITE_NULL ){ |
| @@ -807,10 +821,11 @@ | |
| 807 | blob_reset(&b); |
| 808 | blob_reset(&delta); |
| 809 | } |
| 810 | } |
| 811 | db_finalize(&q); |
| 812 | } |
| 813 | |
| 814 | |
| 815 | /* |
| 816 | ** COMMAND: patch |
| @@ -842,11 +857,15 @@ | |
| 842 | ** -v|--verbose Extra output explaining what happens. |
| 843 | ** |
| 844 | ** > fossil patch diff [DIRECTORY] FILENAME |
| 845 | ** |
| 846 | ** Show a human-readable diff for the patch. All the usual |
| 847 | ** diff flags apply. (See help for "fossil diff"). |
| 848 | ** |
| 849 | ** > fossil patch push REMOTE-CHECKOUT |
| 850 | ** |
| 851 | ** Create a patch for the current check-out, transfer that patch to |
| 852 | ** a remote machine (using ssh) and apply the patch there. The |
| @@ -912,10 +931,11 @@ | |
| 912 | const char *zDiffCmd = 0; |
| 913 | const char *zBinGlob = 0; |
| 914 | int fIncludeBinary = 0; |
| 915 | u64 diffFlags; |
| 916 | char *zIn; |
| 917 | |
| 918 | if( find_option("tk",0,0)!=0 ){ |
| 919 | db_close(0); |
| 920 | diff_tk("patch diff", 3); |
| 921 | return; |
| @@ -928,14 +948,15 @@ | |
| 928 | if( zDiffCmd ){ |
| 929 | zBinGlob = diff_get_binary_glob(); |
| 930 | fIncludeBinary = diff_include_binary_files(); |
| 931 | } |
| 932 | db_find_and_open_repository(0, 0); |
| 933 | verify_all_options(); |
| 934 | zIn = patch_find_patch_filename("apply"); |
| 935 | patch_attach(zIn, stdin); |
| 936 | patch_diff( zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); |
| 937 | fossil_free(zIn); |
| 938 | }else |
| 939 | if( strncmp(zCmd, "pull", n)==0 ){ |
| 940 | FILE *pIn = 0; |
| 941 | unsigned flags = 0; |
| 942 |
| --- src/patch.c | |
| +++ src/patch.c | |
| @@ -703,50 +703,54 @@ | |
| 703 | |
| 704 | /* |
| 705 | ** Show a diff for the patch currently loaded into database "patch". |
| 706 | */ |
| 707 | static void patch_diff( |
| 708 | unsigned mFlags, /* Patch flags. only -f is allowed */ |
| 709 | const char *zDiffCmd, /* Command used for diffing */ |
| 710 | const char *zBinGlob, /* GLOB pattern to determine binary files */ |
| 711 | int fIncludeBinary, /* Do diffs against binary files */ |
| 712 | u64 diffFlags /* Other diff flags */ |
| 713 | ){ |
| 714 | int nErr = 0; |
| 715 | Stmt q; |
| 716 | Blob empty; |
| 717 | blob_zero(&empty); |
| 718 | |
| 719 | if( (mFlags & PATCH_FORCE)==0 ){ |
| 720 | /* Check to ensure that the patch against the repository that we |
| 721 | ** have opened. |
| 722 | ** |
| 723 | ** To do: If there is a mismatch, should we scan all of the repositories |
| 724 | ** listed in the global_config table looking for a match? |
| 725 | */ |
| 726 | if( db_exists( |
| 727 | "SELECT 1 FROM patch.cfg" |
| 728 | " WHERE cfg.key='baseline'" |
| 729 | " AND NOT EXISTS(SELECT 1 FROM blob WHERE uuid=cfg.value)" |
| 730 | )){ |
| 731 | char *zBaseline; |
| 732 | db_prepare(&q, |
| 733 | "SELECT config.value, cfg.value FROM config, cfg" |
| 734 | " WHERE config.name='project-name'" |
| 735 | " AND cfg.key='project-name'" |
| 736 | " AND config.value<>cfg.value" |
| 737 | ); |
| 738 | if( db_step(&q)==SQLITE_ROW ){ |
| 739 | char *zRepo = fossil_strdup(db_column_text(&q,0)); |
| 740 | char *zPatch = fossil_strdup(db_column_text(&q,1)); |
| 741 | db_finalize(&q); |
| 742 | fossil_fatal("the patch is against project \"%z\" but you are using " |
| 743 | "project \"%z\"", zPatch, zRepo); |
| 744 | } |
| 745 | db_finalize(&q); |
| 746 | zBaseline = db_text(0, "SELECT value FROM patch.cfg" |
| 747 | " WHERE key='baseline'"); |
| 748 | if( zBaseline ){ |
| 749 | fossil_fatal("the baseline of the patch (check-in %S) is not found " |
| 750 | "in the %s repository", zBaseline, g.zRepositoryName); |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | db_prepare(&q, |
| 756 | "SELECT" |
| @@ -767,12 +771,22 @@ | |
| 771 | if( db_column_type(&q,0)!=SQLITE_INTEGER |
| 772 | && db_column_type(&q,4)==SQLITE_TEXT |
| 773 | ){ |
| 774 | char *zUuid = fossil_strdup(db_column_text(&q,4)); |
| 775 | char *zName = fossil_strdup(db_column_text(&q,1)); |
| 776 | if( mFlags && PATCH_FORCE ){ |
| 777 | fossil_print("ERROR cannot find base artifact %S for file \"%s\"\n", |
| 778 | zUuid, zName); |
| 779 | nErr++; |
| 780 | fossil_free(zUuid); |
| 781 | fossil_free(zName); |
| 782 | continue; |
| 783 | }else{ |
| 784 | db_finalize(&q); |
| 785 | fossil_fatal("base artifact %S for file \"%s\" not found", |
| 786 | zUuid, zName); |
| 787 | } |
| 788 | } |
| 789 | zName = db_column_text(&q, 1); |
| 790 | rid = db_column_int(&q, 0); |
| 791 | |
| 792 | if( db_column_type(&q,3)==SQLITE_NULL ){ |
| @@ -807,10 +821,11 @@ | |
| 821 | blob_reset(&b); |
| 822 | blob_reset(&delta); |
| 823 | } |
| 824 | } |
| 825 | db_finalize(&q); |
| 826 | if( nErr ) fossil_fatal("abort due to prior errors"); |
| 827 | } |
| 828 | |
| 829 | |
| 830 | /* |
| 831 | ** COMMAND: patch |
| @@ -842,11 +857,15 @@ | |
| 857 | ** -v|--verbose Extra output explaining what happens. |
| 858 | ** |
| 859 | ** > fossil patch diff [DIRECTORY] FILENAME |
| 860 | ** |
| 861 | ** Show a human-readable diff for the patch. All the usual |
| 862 | ** diff flags described at "fossil help diff" apply. In addition: |
| 863 | ** |
| 864 | ** -f|--force Continue trying to perform the diff even if |
| 865 | ** baseline information is missing from the current |
| 866 | ** repository |
| 867 | ** |
| 868 | ** > fossil patch push REMOTE-CHECKOUT |
| 869 | ** |
| 870 | ** Create a patch for the current check-out, transfer that patch to |
| 871 | ** a remote machine (using ssh) and apply the patch there. The |
| @@ -912,10 +931,11 @@ | |
| 931 | const char *zDiffCmd = 0; |
| 932 | const char *zBinGlob = 0; |
| 933 | int fIncludeBinary = 0; |
| 934 | u64 diffFlags; |
| 935 | char *zIn; |
| 936 | unsigned flags = 0; |
| 937 | |
| 938 | if( find_option("tk",0,0)!=0 ){ |
| 939 | db_close(0); |
| 940 | diff_tk("patch diff", 3); |
| 941 | return; |
| @@ -928,14 +948,15 @@ | |
| 948 | if( zDiffCmd ){ |
| 949 | zBinGlob = diff_get_binary_glob(); |
| 950 | fIncludeBinary = diff_include_binary_files(); |
| 951 | } |
| 952 | db_find_and_open_repository(0, 0); |
| 953 | if( find_option("force","f",0) ) flags |= PATCH_FORCE; |
| 954 | verify_all_options(); |
| 955 | zIn = patch_find_patch_filename("apply"); |
| 956 | patch_attach(zIn, stdin); |
| 957 | patch_diff(flags, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); |
| 958 | fossil_free(zIn); |
| 959 | }else |
| 960 | if( strncmp(zCmd, "pull", n)==0 ){ |
| 961 | FILE *pIn = 0; |
| 962 | unsigned flags = 0; |
| 963 |