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 '\#').
Commit
6d2dbf985a1eda3b7ce4484741032d251722a1fc68863a40c52e428eb627f540
Parent
ac30c2d9966f725…
1 file changed
+11
-3
+11
-3
| --- src/blob.c | ||
| +++ src/blob.c | ||
| @@ -854,36 +854,43 @@ | ||
| 854 | 854 | pFrom->iCursor = i; |
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /* |
| 858 | 858 | ** Remove comment lines (starting with '#') from a blob pIn. |
| 859 | +** Keep lines starting with "\#" but remove the initial backslash. | |
| 860 | +** | |
| 859 | 861 | ** Store the result in pOut. It is ok for pIn and pOut to be the same blob. |
| 860 | 862 | ** |
| 861 | 863 | ** pOut must either be the same as pIn or else uninitialized. |
| 862 | 864 | */ |
| 863 | 865 | void blob_strip_comment_lines(Blob *pIn, Blob *pOut){ |
| 864 | 866 | char *z = pIn->aData; |
| 865 | 867 | unsigned int i = 0; |
| 866 | 868 | unsigned int n = pIn->nUsed; |
| 867 | 869 | unsigned int lineStart = 0; |
| 870 | + unsigned int copyStart = 0; | |
| 868 | 871 | int doCopy = 1; |
| 869 | 872 | Blob temp; |
| 870 | 873 | blob_zero(&temp); |
| 871 | 874 | |
| 872 | 875 | while( i<n ){ |
| 873 | 876 | if( i==lineStart && z[i]=='#' ){ |
| 877 | + copyStart = i; | |
| 874 | 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; | |
| 875 | 882 | } |
| 876 | 883 | 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; | |
| 879 | 886 | doCopy = 1; |
| 880 | 887 | } |
| 881 | 888 | i++; |
| 882 | 889 | } |
| 883 | 890 | /* Last line */ |
| 884 | - if( doCopy ) blob_append(&temp, &pIn->aData[lineStart], i - lineStart); | |
| 891 | + if( doCopy ) blob_append(&temp, &pIn->aData[copyStart], i - copyStart); | |
| 885 | 892 | |
| 886 | 893 | if( pOut==pIn ) blob_reset(pOut); |
| 887 | 894 | *pOut = temp; |
| 888 | 895 | } |
| 889 | 896 | |
| @@ -891,10 +898,11 @@ | ||
| 891 | 898 | ** COMMAND: test-strip-comment-lines |
| 892 | 899 | ** |
| 893 | 900 | ** Usage: %fossil test-strip-comment-lines ?OPTIONS? INPUTFILE |
| 894 | 901 | ** |
| 895 | 902 | ** Read INPUTFILE and print it without comment lines (starting with '#'). |
| 903 | +** Keep lines starting with "\#" but remove the initial backslash. | |
| 896 | 904 | ** |
| 897 | 905 | ** This is used to test and debug the blob_strip_comment_lines() routine. |
| 898 | 906 | ** |
| 899 | 907 | ** Options: |
| 900 | 908 | ** -y|--side-by-side Show diff of INPUTFILE and output side-by-side |
| 901 | 909 |
| --- 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 |