Fossil SCM

Add the -f flag to "fossil patch diff".

drh 2021-06-23 20:05 trunk
Commit 5ee62c4033e8362769fa56cbef53c74a68ec3e5119a797dac1c6365c87ed1721
1 file changed +56 -35
+56 -35
--- src/patch.c
+++ src/patch.c
@@ -703,50 +703,54 @@
703703
704704
/*
705705
** Show a diff for the patch currently loaded into database "patch".
706706
*/
707707
static void patch_diff(
708
+ unsigned mFlags, /* Patch flags. only -f is allowed */
708709
const char *zDiffCmd, /* Command used for diffing */
709710
const char *zBinGlob, /* GLOB pattern to determine binary files */
710711
int fIncludeBinary, /* Do diffs against binary files */
711712
u64 diffFlags /* Other diff flags */
712713
){
714
+ int nErr = 0;
713715
Stmt q;
714716
Blob empty;
715717
blob_zero(&empty);
716718
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
+ }
748752
}
749753
}
750754
751755
db_prepare(&q,
752756
"SELECT"
@@ -767,12 +771,22 @@
767771
if( db_column_type(&q,0)!=SQLITE_INTEGER
768772
&& db_column_type(&q,4)==SQLITE_TEXT
769773
){
770774
char *zUuid = fossil_strdup(db_column_text(&q,4));
771775
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
+ }
774788
}
775789
zName = db_column_text(&q, 1);
776790
rid = db_column_int(&q, 0);
777791
778792
if( db_column_type(&q,3)==SQLITE_NULL ){
@@ -807,10 +821,11 @@
807821
blob_reset(&b);
808822
blob_reset(&delta);
809823
}
810824
}
811825
db_finalize(&q);
826
+ if( nErr ) fossil_fatal("abort due to prior errors");
812827
}
813828
814829
815830
/*
816831
** COMMAND: patch
@@ -842,11 +857,15 @@
842857
** -v|--verbose Extra output explaining what happens.
843858
**
844859
** > fossil patch diff [DIRECTORY] FILENAME
845860
**
846861
** 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
848867
**
849868
** > fossil patch push REMOTE-CHECKOUT
850869
**
851870
** Create a patch for the current check-out, transfer that patch to
852871
** a remote machine (using ssh) and apply the patch there. The
@@ -912,10 +931,11 @@
912931
const char *zDiffCmd = 0;
913932
const char *zBinGlob = 0;
914933
int fIncludeBinary = 0;
915934
u64 diffFlags;
916935
char *zIn;
936
+ unsigned flags = 0;
917937
918938
if( find_option("tk",0,0)!=0 ){
919939
db_close(0);
920940
diff_tk("patch diff", 3);
921941
return;
@@ -928,14 +948,15 @@
928948
if( zDiffCmd ){
929949
zBinGlob = diff_get_binary_glob();
930950
fIncludeBinary = diff_include_binary_files();
931951
}
932952
db_find_and_open_repository(0, 0);
953
+ if( find_option("force","f",0) ) flags |= PATCH_FORCE;
933954
verify_all_options();
934955
zIn = patch_find_patch_filename("apply");
935956
patch_attach(zIn, stdin);
936
- patch_diff( zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
957
+ patch_diff(flags, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
937958
fossil_free(zIn);
938959
}else
939960
if( strncmp(zCmd, "pull", n)==0 ){
940961
FILE *pIn = 0;
941962
unsigned flags = 0;
942963
--- 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

Keyboard Shortcuts

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