Fossil SCM

Allow comment lines (starting with '#') in versioned settings.

danield 2023-04-19 07:19 trunk merge
Commit ef633d4bb5b29f9642a989e53b2c6eb7f01e871e1273f4e218d684b2ae3d9c41
2 files changed +79 +1
+79
--- src/blob.c
+++ src/blob.c
@@ -851,10 +851,89 @@
851851
if( pTo ){
852852
blob_append(pTo, &pFrom->aData[pFrom->iCursor], i - pFrom->iCursor);
853853
}
854854
pFrom->iCursor = i;
855855
}
856
+
857
+/*
858
+** Remove comment lines (starting with '#') from a blob pIn.
859
+** Store the result in pOut. It is ok for pIn and pOut to be the same blob.
860
+**
861
+** pOut must either be the same as pIn or else uninitialized.
862
+*/
863
+void blob_strip_comment_lines(Blob *pIn, Blob *pOut){
864
+ char *z = pIn->aData;
865
+ unsigned int i = 0;
866
+ unsigned int n = pIn->nUsed;
867
+ unsigned int lineStart = 0;
868
+ int doCopy = 1;
869
+ Blob temp;
870
+ blob_zero(&temp);
871
+
872
+ while( i<n ){
873
+ if( i==lineStart && z[i]=='#' ){
874
+ doCopy = 0;
875
+ }
876
+ if( z[i]=='\n' ){
877
+ if( doCopy ) blob_append(&temp,&pIn->aData[lineStart], i - lineStart + 1);
878
+ lineStart = i + 1;
879
+ doCopy = 1;
880
+ }
881
+ i++;
882
+ }
883
+ /* Last line */
884
+ if( doCopy ) blob_append(&temp, &pIn->aData[lineStart], i - lineStart);
885
+
886
+ if( pOut==pIn ) blob_reset(pOut);
887
+ *pOut = temp;
888
+}
889
+
890
+/*
891
+** COMMAND: test-strip-comment-lines
892
+**
893
+** Usage: %fossil test-strip-comment-lines ?OPTIONS? INPUTFILE
894
+**
895
+** Read INPUTFILE and print it without comment lines (starting with '#').
896
+**
897
+** This is used to test and debug the blob_strip_comment_lines() routine.
898
+**
899
+** Options:
900
+** -y|--side-by-side Show diff of INPUTFILE and output side-by-side
901
+** -W|--width N Width of lines in side-by-side diff
902
+*/
903
+void test_strip_comment_lines_cmd(void){
904
+ Blob f, h; /* unitialized */
905
+ Blob out;
906
+ DiffConfig dCfg;
907
+ int sbs = 0;
908
+ const char *z;
909
+ int w = 0;
910
+
911
+ memset(&dCfg, 0, sizeof(dCfg));
912
+
913
+ sbs = find_option("side-by-side","y",0)!=0;
914
+ if( (z = find_option("width","W",1))!=0 && (w = atoi(z))>0 ){
915
+ dCfg.wColumn = w;
916
+ }
917
+ verify_all_options();
918
+ if( g.argc!=3 ) usage("INPUTFILE");
919
+
920
+ blob_read_from_file(&f, g.argv[2], ExtFILE);
921
+ blob_strip_comment_lines(&f, &h);
922
+
923
+ if ( !sbs ){
924
+ blob_write_to_file(&h, "-");
925
+ }else{
926
+ blob_zero(&out);
927
+ dCfg.nContext = -1; /* whole content */
928
+ dCfg.diffFlags = DIFF_SIDEBYSIDE | DIFF_CONTEXT_EX | DIFF_STRIP_EOLCR;
929
+ diff_begin(&dCfg);
930
+ text_diff(&f, &h, &out, &dCfg);
931
+ blob_write_to_file(&out, "-");
932
+ diff_end(&dCfg, 0);
933
+ }
934
+}
856935
857936
/*
858937
** Ensure that the text in pBlob ends with '\n'
859938
*/
860939
void blob_add_final_newline(Blob *pBlob){
861940
--- src/blob.c
+++ src/blob.c
@@ -851,10 +851,89 @@
851 if( pTo ){
852 blob_append(pTo, &pFrom->aData[pFrom->iCursor], i - pFrom->iCursor);
853 }
854 pFrom->iCursor = i;
855 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
856
857 /*
858 ** Ensure that the text in pBlob ends with '\n'
859 */
860 void blob_add_final_newline(Blob *pBlob){
861
--- src/blob.c
+++ src/blob.c
@@ -851,10 +851,89 @@
851 if( pTo ){
852 blob_append(pTo, &pFrom->aData[pFrom->iCursor], i - pFrom->iCursor);
853 }
854 pFrom->iCursor = i;
855 }
856
857 /*
858 ** Remove comment lines (starting with '#') from a blob pIn.
859 ** Store the result in pOut. It is ok for pIn and pOut to be the same blob.
860 **
861 ** pOut must either be the same as pIn or else uninitialized.
862 */
863 void blob_strip_comment_lines(Blob *pIn, Blob *pOut){
864 char *z = pIn->aData;
865 unsigned int i = 0;
866 unsigned int n = pIn->nUsed;
867 unsigned int lineStart = 0;
868 int doCopy = 1;
869 Blob temp;
870 blob_zero(&temp);
871
872 while( i<n ){
873 if( i==lineStart && z[i]=='#' ){
874 doCopy = 0;
875 }
876 if( z[i]=='\n' ){
877 if( doCopy ) blob_append(&temp,&pIn->aData[lineStart], i - lineStart + 1);
878 lineStart = i + 1;
879 doCopy = 1;
880 }
881 i++;
882 }
883 /* Last line */
884 if( doCopy ) blob_append(&temp, &pIn->aData[lineStart], i - lineStart);
885
886 if( pOut==pIn ) blob_reset(pOut);
887 *pOut = temp;
888 }
889
890 /*
891 ** COMMAND: test-strip-comment-lines
892 **
893 ** Usage: %fossil test-strip-comment-lines ?OPTIONS? INPUTFILE
894 **
895 ** Read INPUTFILE and print it without comment lines (starting with '#').
896 **
897 ** This is used to test and debug the blob_strip_comment_lines() routine.
898 **
899 ** Options:
900 ** -y|--side-by-side Show diff of INPUTFILE and output side-by-side
901 ** -W|--width N Width of lines in side-by-side diff
902 */
903 void test_strip_comment_lines_cmd(void){
904 Blob f, h; /* unitialized */
905 Blob out;
906 DiffConfig dCfg;
907 int sbs = 0;
908 const char *z;
909 int w = 0;
910
911 memset(&dCfg, 0, sizeof(dCfg));
912
913 sbs = find_option("side-by-side","y",0)!=0;
914 if( (z = find_option("width","W",1))!=0 && (w = atoi(z))>0 ){
915 dCfg.wColumn = w;
916 }
917 verify_all_options();
918 if( g.argc!=3 ) usage("INPUTFILE");
919
920 blob_read_from_file(&f, g.argv[2], ExtFILE);
921 blob_strip_comment_lines(&f, &h);
922
923 if ( !sbs ){
924 blob_write_to_file(&h, "-");
925 }else{
926 blob_zero(&out);
927 dCfg.nContext = -1; /* whole content */
928 dCfg.diffFlags = DIFF_SIDEBYSIDE | DIFF_CONTEXT_EX | DIFF_STRIP_EOLCR;
929 diff_begin(&dCfg);
930 text_diff(&f, &h, &out, &dCfg);
931 blob_write_to_file(&out, "-");
932 diff_end(&dCfg, 0);
933 }
934 }
935
936 /*
937 ** Ensure that the text in pBlob ends with '\n'
938 */
939 void blob_add_final_newline(Blob *pBlob){
940
+1
--- src/db.c
+++ src/db.c
@@ -3294,10 +3294,11 @@
32943294
noWarn = 1;
32953295
}
32963296
}
32973297
blob_reset(&versionedPathname);
32983298
if( found ){
3299
+ blob_strip_comment_lines(&setting, &setting);
32993300
blob_trim(&setting); /* Avoid non-obvious problems with line endings
33003301
** on boolean properties */
33013302
zVersionedSetting = fossil_strdup(blob_str(&setting));
33023303
}
33033304
blob_reset(&setting);
33043305
--- src/db.c
+++ src/db.c
@@ -3294,10 +3294,11 @@
3294 noWarn = 1;
3295 }
3296 }
3297 blob_reset(&versionedPathname);
3298 if( found ){
 
3299 blob_trim(&setting); /* Avoid non-obvious problems with line endings
3300 ** on boolean properties */
3301 zVersionedSetting = fossil_strdup(blob_str(&setting));
3302 }
3303 blob_reset(&setting);
3304
--- src/db.c
+++ src/db.c
@@ -3294,10 +3294,11 @@
3294 noWarn = 1;
3295 }
3296 }
3297 blob_reset(&versionedPathname);
3298 if( found ){
3299 blob_strip_comment_lines(&setting, &setting);
3300 blob_trim(&setting); /* Avoid non-obvious problems with line endings
3301 ** on boolean properties */
3302 zVersionedSetting = fossil_strdup(blob_str(&setting));
3303 }
3304 blob_reset(&setting);
3305

Keyboard Shortcuts

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