Fossil SCM

In versioned settings, make again possible for globs to begin with a hash by escaping it (i.e. such lines should start with '\#').

danield 2023-04-20 12:02 trunk
Commit 6d2dbf985a1eda3b7ce4484741032d251722a1fc68863a40c52e428eb627f540
1 file changed +11 -3
+11 -3
--- src/blob.c
+++ src/blob.c
@@ -854,36 +854,43 @@
854854
pFrom->iCursor = i;
855855
}
856856
857857
/*
858858
** Remove comment lines (starting with '#') from a blob pIn.
859
+** Keep lines starting with "\#" but remove the initial backslash.
860
+**
859861
** Store the result in pOut. It is ok for pIn and pOut to be the same blob.
860862
**
861863
** pOut must either be the same as pIn or else uninitialized.
862864
*/
863865
void blob_strip_comment_lines(Blob *pIn, Blob *pOut){
864866
char *z = pIn->aData;
865867
unsigned int i = 0;
866868
unsigned int n = pIn->nUsed;
867869
unsigned int lineStart = 0;
870
+ unsigned int copyStart = 0;
868871
int doCopy = 1;
869872
Blob temp;
870873
blob_zero(&temp);
871874
872875
while( i<n ){
873876
if( i==lineStart && z[i]=='#' ){
877
+ copyStart = i;
874878
doCopy = 0;
879
+ }else if( i==lineStart && z[i]=='\\' && z[i+1]=='#' ){
880
+ /* keep lines starting with an escaped '#' (and unescape it) */
881
+ copyStart = i + 1;
875882
}
876883
if( z[i]=='\n' ){
877
- if( doCopy ) blob_append(&temp,&pIn->aData[lineStart], i - lineStart + 1);
878
- lineStart = i + 1;
884
+ if( doCopy ) blob_append(&temp,&pIn->aData[copyStart], i - copyStart + 1);
885
+ lineStart = copyStart = i + 1;
879886
doCopy = 1;
880887
}
881888
i++;
882889
}
883890
/* Last line */
884
- if( doCopy ) blob_append(&temp, &pIn->aData[lineStart], i - lineStart);
891
+ if( doCopy ) blob_append(&temp, &pIn->aData[copyStart], i - copyStart);
885892
886893
if( pOut==pIn ) blob_reset(pOut);
887894
*pOut = temp;
888895
}
889896
@@ -891,10 +898,11 @@
891898
** COMMAND: test-strip-comment-lines
892899
**
893900
** Usage: %fossil test-strip-comment-lines ?OPTIONS? INPUTFILE
894901
**
895902
** Read INPUTFILE and print it without comment lines (starting with '#').
903
+** Keep lines starting with "\#" but remove the initial backslash.
896904
**
897905
** This is used to test and debug the blob_strip_comment_lines() routine.
898906
**
899907
** Options:
900908
** -y|--side-by-side Show diff of INPUTFILE and output side-by-side
901909
--- src/blob.c
+++ src/blob.c
@@ -854,36 +854,43 @@
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
@@ -891,10 +898,11 @@
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
--- src/blob.c
+++ src/blob.c
@@ -854,36 +854,43 @@
854 pFrom->iCursor = i;
855 }
856
857 /*
858 ** Remove comment lines (starting with '#') from a blob pIn.
859 ** Keep lines starting with "\#" but remove the initial backslash.
860 **
861 ** Store the result in pOut. It is ok for pIn and pOut to be the same blob.
862 **
863 ** pOut must either be the same as pIn or else uninitialized.
864 */
865 void blob_strip_comment_lines(Blob *pIn, Blob *pOut){
866 char *z = pIn->aData;
867 unsigned int i = 0;
868 unsigned int n = pIn->nUsed;
869 unsigned int lineStart = 0;
870 unsigned int copyStart = 0;
871 int doCopy = 1;
872 Blob temp;
873 blob_zero(&temp);
874
875 while( i<n ){
876 if( i==lineStart && z[i]=='#' ){
877 copyStart = i;
878 doCopy = 0;
879 }else if( i==lineStart && z[i]=='\\' && z[i+1]=='#' ){
880 /* keep lines starting with an escaped '#' (and unescape it) */
881 copyStart = i + 1;
882 }
883 if( z[i]=='\n' ){
884 if( doCopy ) blob_append(&temp,&pIn->aData[copyStart], i - copyStart + 1);
885 lineStart = copyStart = i + 1;
886 doCopy = 1;
887 }
888 i++;
889 }
890 /* Last line */
891 if( doCopy ) blob_append(&temp, &pIn->aData[copyStart], i - copyStart);
892
893 if( pOut==pIn ) blob_reset(pOut);
894 *pOut = temp;
895 }
896
@@ -891,10 +898,11 @@
898 ** COMMAND: test-strip-comment-lines
899 **
900 ** Usage: %fossil test-strip-comment-lines ?OPTIONS? INPUTFILE
901 **
902 ** Read INPUTFILE and print it without comment lines (starting with '#').
903 ** Keep lines starting with "\#" but remove the initial backslash.
904 **
905 ** This is used to test and debug the blob_strip_comment_lines() routine.
906 **
907 ** Options:
908 ** -y|--side-by-side Show diff of INPUTFILE and output side-by-side
909

Keyboard Shortcuts

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