Fossil SCM

The "-f" flag on "fossil patch create" causes an existing patch with the same name to be overwritten.

drh 2021-06-23 19:14 trunk
Commit a332f1a64fb890b37dc25c9decd083a12e57f3e6b18a49398f3240934a069e7e
1 file changed +17 -4
+17 -4
--- src/patch.c
+++ src/patch.c
@@ -145,16 +145,21 @@
145145
146146
/*
147147
** Generate a binary patch file and store it into the file
148148
** named zOut.
149149
*/
150
-void patch_create(const char *zOut, FILE *out){
150
+void patch_create(unsigned mFlags, const char *zOut, FILE *out){
151151
int vid;
152152
char *z;
153153
154154
if( zOut && file_isdir(zOut, ExtFILE)!=0 ){
155
- fossil_fatal("patch file already exists: %s", zOut);
155
+ if( mFlags & PATCH_FORCE ){
156
+ file_delete(zOut);
157
+ }
158
+ if( file_isdir(zOut, ExtFILE)!=0 ){
159
+ fossil_fatal("patch file already exists: %s", zOut);
160
+ }
156161
}
157162
add_content_sql_commands(g.db);
158163
deltafunc_init(g.db);
159164
sqlite3_create_function(g.db, "read_co_file", 1, SQLITE_UTF8, 0,
160165
readfileFunc, 0, 0);
@@ -775,10 +780,12 @@
775780
** Create a new binary patch in FILENAME that captures all uncommitted
776781
** changes in the check-out at DIRECTORY, or the current directory if
777782
** DIRECTORY is omitted. If FILENAME is "-" then the binary patch
778783
** is written to standard output.
779784
**
785
+** -f|--force Overwrite an existing patch with the same name.
786
+**
780787
** > fossil patch apply [DIRECTORY] FILENAME
781788
**
782789
** Apply the changes in FILENAME to the check-out a DIRECTORY, or
783790
** in the current directory if DIRECTORY is omitted. Options:
784791
**
@@ -816,10 +823,13 @@
816823
** -v|--verbose Extra output explaining what happens.
817824
**
818825
** > fossil patch view FILENAME
819826
**
820827
** View a summary of the the changes in the binary patch FILENAME.
828
+** Use "fossil patch diff" for detailed patch content.
829
+**
830
+** -v|--verbose Show extra detail about the patch.
821831
**
822832
*/
823833
void patch_cmd(void){
824834
const char *zCmd;
825835
size_t n;
@@ -841,13 +851,16 @@
841851
patch_apply(flags);
842852
fossil_free(zIn);
843853
}else
844854
if( strncmp(zCmd, "create", n)==0 ){
845855
char *zOut;
856
+ unsigned flags = 0;
857
+ if( find_option("force","f",0) ) flags |= PATCH_FORCE;
846858
zOut = patch_find_patch_filename("create");
859
+ verify_all_options();
847860
db_must_be_within_tree();
848
- patch_create(zOut, stdout);
861
+ patch_create(flags, zOut, stdout);
849862
fossil_free(zOut);
850863
}else
851864
if( strncmp(zCmd, "diff", n)==0 ){
852865
const char *zDiffCmd = 0;
853866
const char *zBinGlob = 0;
@@ -899,11 +912,11 @@
899912
if( find_option("force","f",0) ) flags |= PATCH_FORCE;
900913
db_must_be_within_tree();
901914
verify_all_options();
902915
pOut = patch_remote_command(flags, "push", "apply", "w");
903916
if( pOut ){
904
- patch_create(0, pOut);
917
+ patch_create(0, 0, pOut);
905918
pclose(pOut);
906919
}
907920
}else
908921
if( strncmp(zCmd, "view", n)==0 ){
909922
const char *zIn;
910923
--- src/patch.c
+++ src/patch.c
@@ -145,16 +145,21 @@
145
146 /*
147 ** Generate a binary patch file and store it into the file
148 ** named zOut.
149 */
150 void patch_create(const char *zOut, FILE *out){
151 int vid;
152 char *z;
153
154 if( zOut && file_isdir(zOut, ExtFILE)!=0 ){
155 fossil_fatal("patch file already exists: %s", zOut);
 
 
 
 
 
156 }
157 add_content_sql_commands(g.db);
158 deltafunc_init(g.db);
159 sqlite3_create_function(g.db, "read_co_file", 1, SQLITE_UTF8, 0,
160 readfileFunc, 0, 0);
@@ -775,10 +780,12 @@
775 ** Create a new binary patch in FILENAME that captures all uncommitted
776 ** changes in the check-out at DIRECTORY, or the current directory if
777 ** DIRECTORY is omitted. If FILENAME is "-" then the binary patch
778 ** is written to standard output.
779 **
 
 
780 ** > fossil patch apply [DIRECTORY] FILENAME
781 **
782 ** Apply the changes in FILENAME to the check-out a DIRECTORY, or
783 ** in the current directory if DIRECTORY is omitted. Options:
784 **
@@ -816,10 +823,13 @@
816 ** -v|--verbose Extra output explaining what happens.
817 **
818 ** > fossil patch view FILENAME
819 **
820 ** View a summary of the the changes in the binary patch FILENAME.
 
 
 
821 **
822 */
823 void patch_cmd(void){
824 const char *zCmd;
825 size_t n;
@@ -841,13 +851,16 @@
841 patch_apply(flags);
842 fossil_free(zIn);
843 }else
844 if( strncmp(zCmd, "create", n)==0 ){
845 char *zOut;
 
 
846 zOut = patch_find_patch_filename("create");
 
847 db_must_be_within_tree();
848 patch_create(zOut, stdout);
849 fossil_free(zOut);
850 }else
851 if( strncmp(zCmd, "diff", n)==0 ){
852 const char *zDiffCmd = 0;
853 const char *zBinGlob = 0;
@@ -899,11 +912,11 @@
899 if( find_option("force","f",0) ) flags |= PATCH_FORCE;
900 db_must_be_within_tree();
901 verify_all_options();
902 pOut = patch_remote_command(flags, "push", "apply", "w");
903 if( pOut ){
904 patch_create(0, pOut);
905 pclose(pOut);
906 }
907 }else
908 if( strncmp(zCmd, "view", n)==0 ){
909 const char *zIn;
910
--- src/patch.c
+++ src/patch.c
@@ -145,16 +145,21 @@
145
146 /*
147 ** Generate a binary patch file and store it into the file
148 ** named zOut.
149 */
150 void patch_create(unsigned mFlags, const char *zOut, FILE *out){
151 int vid;
152 char *z;
153
154 if( zOut && file_isdir(zOut, ExtFILE)!=0 ){
155 if( mFlags & PATCH_FORCE ){
156 file_delete(zOut);
157 }
158 if( file_isdir(zOut, ExtFILE)!=0 ){
159 fossil_fatal("patch file already exists: %s", zOut);
160 }
161 }
162 add_content_sql_commands(g.db);
163 deltafunc_init(g.db);
164 sqlite3_create_function(g.db, "read_co_file", 1, SQLITE_UTF8, 0,
165 readfileFunc, 0, 0);
@@ -775,10 +780,12 @@
780 ** Create a new binary patch in FILENAME that captures all uncommitted
781 ** changes in the check-out at DIRECTORY, or the current directory if
782 ** DIRECTORY is omitted. If FILENAME is "-" then the binary patch
783 ** is written to standard output.
784 **
785 ** -f|--force Overwrite an existing patch with the same name.
786 **
787 ** > fossil patch apply [DIRECTORY] FILENAME
788 **
789 ** Apply the changes in FILENAME to the check-out a DIRECTORY, or
790 ** in the current directory if DIRECTORY is omitted. Options:
791 **
@@ -816,10 +823,13 @@
823 ** -v|--verbose Extra output explaining what happens.
824 **
825 ** > fossil patch view FILENAME
826 **
827 ** View a summary of the the changes in the binary patch FILENAME.
828 ** Use "fossil patch diff" for detailed patch content.
829 **
830 ** -v|--verbose Show extra detail about the patch.
831 **
832 */
833 void patch_cmd(void){
834 const char *zCmd;
835 size_t n;
@@ -841,13 +851,16 @@
851 patch_apply(flags);
852 fossil_free(zIn);
853 }else
854 if( strncmp(zCmd, "create", n)==0 ){
855 char *zOut;
856 unsigned flags = 0;
857 if( find_option("force","f",0) ) flags |= PATCH_FORCE;
858 zOut = patch_find_patch_filename("create");
859 verify_all_options();
860 db_must_be_within_tree();
861 patch_create(flags, zOut, stdout);
862 fossil_free(zOut);
863 }else
864 if( strncmp(zCmd, "diff", n)==0 ){
865 const char *zDiffCmd = 0;
866 const char *zBinGlob = 0;
@@ -899,11 +912,11 @@
912 if( find_option("force","f",0) ) flags |= PATCH_FORCE;
913 db_must_be_within_tree();
914 verify_all_options();
915 pOut = patch_remote_command(flags, "push", "apply", "w");
916 if( pOut ){
917 patch_create(0, 0, pOut);
918 pclose(pOut);
919 }
920 }else
921 if( strncmp(zCmd, "view", n)==0 ){
922 const char *zIn;
923

Keyboard Shortcuts

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