Fossil SCM
Implement new --ignore-space-at-sol option for all diff variants. And "-w" which means (for now) both --ignore-space-at-sol and --ignore-space-at-eol
Commit
6392c032ce64db58b659cba036fe24db51404e58
Parent
d3f69bd48ec2797…
2 files changed
+15
-7
+3
+15
-7
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -40,10 +40,11 @@ | ||
| 40 | 40 | #define DIFF_WS_WARNING ((u64)0x40000000) /* Warn about whitespace */ |
| 41 | 41 | #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */ |
| 42 | 42 | #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */ |
| 43 | 43 | #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */ |
| 44 | 44 | #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */ |
| 45 | +#define DIFF_IGNORE_SOLWS (((u64)0x10)<<32) /* Ignore start-of-line whitespace */ | |
| 45 | 46 | |
| 46 | 47 | /* |
| 47 | 48 | ** These error messages are shared in multiple locations. They are defined |
| 48 | 49 | ** here for consistency. |
| 49 | 50 | */ |
| @@ -129,14 +130,13 @@ | ||
| 129 | 130 | ** |
| 130 | 131 | ** Profiling show that in most cases this routine consumes the bulk of |
| 131 | 132 | ** the CPU time on a diff. |
| 132 | 133 | */ |
| 133 | 134 | static DLine *break_into_lines(const char *z, int n, int *pnLine, u64 diffFlags){ |
| 134 | - int nLine, i, j, k, x; | |
| 135 | + int nLine, i, j, k, s, x; | |
| 135 | 136 | unsigned int h, h2; |
| 136 | 137 | DLine *a; |
| 137 | - int ignoreWS = (diffFlags & DIFF_IGNORE_EOLWS)!=0; | |
| 138 | 138 | |
| 139 | 139 | /* Count the number of lines. Allocate space to hold |
| 140 | 140 | ** the returned array. |
| 141 | 141 | */ |
| 142 | 142 | for(i=j=0, nLine=1; i<n; i++, j++){ |
| @@ -162,18 +162,24 @@ | ||
| 162 | 162 | return a; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /* Fill in the array */ |
| 166 | 166 | for(i=0; i<nLine; i++){ |
| 167 | - a[i].z = z; | |
| 168 | 167 | for(j=0; z[j] && z[j]!='\n'; j++){} |
| 169 | 168 | k = j; |
| 170 | - while( ignoreWS && k>0 && fossil_isspace(z[k-1]) ){ k--; } | |
| 171 | - for(h=0, x=0; x<k; x++){ | |
| 169 | + s = 0; | |
| 170 | + if( diffFlags & DIFF_IGNORE_EOLWS ){ | |
| 171 | + while( k>0 && fossil_isspace(z[k-1]) ){ k--; } | |
| 172 | + } | |
| 173 | + if( diffFlags & DIFF_IGNORE_SOLWS ){ | |
| 174 | + while( s<k && fossil_isspace(z[s]) ){ s++; } | |
| 175 | + } | |
| 176 | + a[i].z = z+s; | |
| 177 | + for(h=0, x=s; x<k; x++){ | |
| 172 | 178 | h = h ^ (h<<2) ^ z[x]; |
| 173 | 179 | } |
| 174 | - a[i].h = h = (h<<LENGTH_MASK_SZ) | k; | |
| 180 | + a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s); | |
| 175 | 181 | h2 = h % nLine; |
| 176 | 182 | a[i].iNext = a[h2].iHash; |
| 177 | 183 | a[h2].iHash = i+1; |
| 178 | 184 | z += j+1; |
| 179 | 185 | } |
| @@ -1862,11 +1868,13 @@ | ||
| 1862 | 1868 | f *= DIFF_CONTEXT_MASK+1; |
| 1863 | 1869 | if( f > DIFF_WIDTH_MASK ) f = DIFF_CONTEXT_MASK; |
| 1864 | 1870 | diffFlags |= f; |
| 1865 | 1871 | } |
| 1866 | 1872 | if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML; |
| 1867 | - if( find_option("ignore-space-at-eol","w",0)!=0 ) diffFlags |= DIFF_IGNORE_EOLWS; | |
| 1873 | + if( find_option("ignore-space-at-sol",0,0)!=0 ) diffFlags |= DIFF_IGNORE_SOLWS; | |
| 1874 | + if( find_option("ignore-space-at-eol",0,0)!=0 ) diffFlags |= DIFF_IGNORE_EOLWS; | |
| 1875 | + if( find_option("w",0,0)!=0 ) diffFlags |= (DIFF_IGNORE_EOLWS|DIFF_IGNORE_SOLWS); | |
| 1868 | 1876 | if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO; |
| 1869 | 1877 | if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT; |
| 1870 | 1878 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 1871 | 1879 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 1872 | 1880 | return diffFlags; |
| 1873 | 1881 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -40,10 +40,11 @@ | |
| 40 | #define DIFF_WS_WARNING ((u64)0x40000000) /* Warn about whitespace */ |
| 41 | #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */ |
| 42 | #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */ |
| 43 | #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */ |
| 44 | #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */ |
| 45 | |
| 46 | /* |
| 47 | ** These error messages are shared in multiple locations. They are defined |
| 48 | ** here for consistency. |
| 49 | */ |
| @@ -129,14 +130,13 @@ | |
| 129 | ** |
| 130 | ** Profiling show that in most cases this routine consumes the bulk of |
| 131 | ** the CPU time on a diff. |
| 132 | */ |
| 133 | static DLine *break_into_lines(const char *z, int n, int *pnLine, u64 diffFlags){ |
| 134 | int nLine, i, j, k, x; |
| 135 | unsigned int h, h2; |
| 136 | DLine *a; |
| 137 | int ignoreWS = (diffFlags & DIFF_IGNORE_EOLWS)!=0; |
| 138 | |
| 139 | /* Count the number of lines. Allocate space to hold |
| 140 | ** the returned array. |
| 141 | */ |
| 142 | for(i=j=0, nLine=1; i<n; i++, j++){ |
| @@ -162,18 +162,24 @@ | |
| 162 | return a; |
| 163 | } |
| 164 | |
| 165 | /* Fill in the array */ |
| 166 | for(i=0; i<nLine; i++){ |
| 167 | a[i].z = z; |
| 168 | for(j=0; z[j] && z[j]!='\n'; j++){} |
| 169 | k = j; |
| 170 | while( ignoreWS && k>0 && fossil_isspace(z[k-1]) ){ k--; } |
| 171 | for(h=0, x=0; x<k; x++){ |
| 172 | h = h ^ (h<<2) ^ z[x]; |
| 173 | } |
| 174 | a[i].h = h = (h<<LENGTH_MASK_SZ) | k; |
| 175 | h2 = h % nLine; |
| 176 | a[i].iNext = a[h2].iHash; |
| 177 | a[h2].iHash = i+1; |
| 178 | z += j+1; |
| 179 | } |
| @@ -1862,11 +1868,13 @@ | |
| 1862 | f *= DIFF_CONTEXT_MASK+1; |
| 1863 | if( f > DIFF_WIDTH_MASK ) f = DIFF_CONTEXT_MASK; |
| 1864 | diffFlags |= f; |
| 1865 | } |
| 1866 | if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML; |
| 1867 | if( find_option("ignore-space-at-eol","w",0)!=0 ) diffFlags |= DIFF_IGNORE_EOLWS; |
| 1868 | if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO; |
| 1869 | if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT; |
| 1870 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 1871 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 1872 | return diffFlags; |
| 1873 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -40,10 +40,11 @@ | |
| 40 | #define DIFF_WS_WARNING ((u64)0x40000000) /* Warn about whitespace */ |
| 41 | #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */ |
| 42 | #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */ |
| 43 | #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */ |
| 44 | #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */ |
| 45 | #define DIFF_IGNORE_SOLWS (((u64)0x10)<<32) /* Ignore start-of-line whitespace */ |
| 46 | |
| 47 | /* |
| 48 | ** These error messages are shared in multiple locations. They are defined |
| 49 | ** here for consistency. |
| 50 | */ |
| @@ -129,14 +130,13 @@ | |
| 130 | ** |
| 131 | ** Profiling show that in most cases this routine consumes the bulk of |
| 132 | ** the CPU time on a diff. |
| 133 | */ |
| 134 | static DLine *break_into_lines(const char *z, int n, int *pnLine, u64 diffFlags){ |
| 135 | int nLine, i, j, k, s, x; |
| 136 | unsigned int h, h2; |
| 137 | DLine *a; |
| 138 | |
| 139 | /* Count the number of lines. Allocate space to hold |
| 140 | ** the returned array. |
| 141 | */ |
| 142 | for(i=j=0, nLine=1; i<n; i++, j++){ |
| @@ -162,18 +162,24 @@ | |
| 162 | return a; |
| 163 | } |
| 164 | |
| 165 | /* Fill in the array */ |
| 166 | for(i=0; i<nLine; i++){ |
| 167 | for(j=0; z[j] && z[j]!='\n'; j++){} |
| 168 | k = j; |
| 169 | s = 0; |
| 170 | if( diffFlags & DIFF_IGNORE_EOLWS ){ |
| 171 | while( k>0 && fossil_isspace(z[k-1]) ){ k--; } |
| 172 | } |
| 173 | if( diffFlags & DIFF_IGNORE_SOLWS ){ |
| 174 | while( s<k && fossil_isspace(z[s]) ){ s++; } |
| 175 | } |
| 176 | a[i].z = z+s; |
| 177 | for(h=0, x=s; x<k; x++){ |
| 178 | h = h ^ (h<<2) ^ z[x]; |
| 179 | } |
| 180 | a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s); |
| 181 | h2 = h % nLine; |
| 182 | a[i].iNext = a[h2].iHash; |
| 183 | a[h2].iHash = i+1; |
| 184 | z += j+1; |
| 185 | } |
| @@ -1862,11 +1868,13 @@ | |
| 1868 | f *= DIFF_CONTEXT_MASK+1; |
| 1869 | if( f > DIFF_WIDTH_MASK ) f = DIFF_CONTEXT_MASK; |
| 1870 | diffFlags |= f; |
| 1871 | } |
| 1872 | if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML; |
| 1873 | if( find_option("ignore-space-at-sol",0,0)!=0 ) diffFlags |= DIFF_IGNORE_SOLWS; |
| 1874 | if( find_option("ignore-space-at-eol",0,0)!=0 ) diffFlags |= DIFF_IGNORE_EOLWS; |
| 1875 | if( find_option("w",0,0)!=0 ) diffFlags |= (DIFF_IGNORE_EOLWS|DIFF_IGNORE_SOLWS); |
| 1876 | if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO; |
| 1877 | if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT; |
| 1878 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 1879 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 1880 | return diffFlags; |
| 1881 |
+3
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -1087,16 +1087,19 @@ | ||
| 1087 | 1087 | ** --brief Show filenames only |
| 1088 | 1088 | ** --context|-c N Use N lines of context |
| 1089 | 1089 | ** --diff-binary BOOL Include binary files when using external commands |
| 1090 | 1090 | ** --from|-r VERSION select VERSION as source for the diff |
| 1091 | 1091 | ** --ignore-space-at-eol Ignore changes to end-of-line whitespace |
| 1092 | +** --ignore-space-at-sol Ignore changes to start-of-line whitespace | |
| 1092 | 1093 | ** --internal|-i use internal diff logic |
| 1093 | 1094 | ** --side-by-side|-y side-by-side diff |
| 1094 | 1095 | ** --tk Launch a Tcl/Tk GUI for display |
| 1095 | 1096 | ** --to VERSION select VERSION as target for the diff |
| 1096 | 1097 | ** --unified unified diff |
| 1097 | 1098 | ** -v|--verbose output complete text of added or deleted files |
| 1099 | +** -w Ignore changes to start-of-line and end-of-line | |
| 1100 | +** whitespace | |
| 1098 | 1101 | ** -W|--width Width of lines in side-by-side diff |
| 1099 | 1102 | */ |
| 1100 | 1103 | void diff_cmd(void){ |
| 1101 | 1104 | int isGDiff; /* True for gdiff. False for normal diff */ |
| 1102 | 1105 | int isInternDiff; /* True for internal diff */ |
| 1103 | 1106 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -1087,16 +1087,19 @@ | |
| 1087 | ** --brief Show filenames only |
| 1088 | ** --context|-c N Use N lines of context |
| 1089 | ** --diff-binary BOOL Include binary files when using external commands |
| 1090 | ** --from|-r VERSION select VERSION as source for the diff |
| 1091 | ** --ignore-space-at-eol Ignore changes to end-of-line whitespace |
| 1092 | ** --internal|-i use internal diff logic |
| 1093 | ** --side-by-side|-y side-by-side diff |
| 1094 | ** --tk Launch a Tcl/Tk GUI for display |
| 1095 | ** --to VERSION select VERSION as target for the diff |
| 1096 | ** --unified unified diff |
| 1097 | ** -v|--verbose output complete text of added or deleted files |
| 1098 | ** -W|--width Width of lines in side-by-side diff |
| 1099 | */ |
| 1100 | void diff_cmd(void){ |
| 1101 | int isGDiff; /* True for gdiff. False for normal diff */ |
| 1102 | int isInternDiff; /* True for internal diff */ |
| 1103 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -1087,16 +1087,19 @@ | |
| 1087 | ** --brief Show filenames only |
| 1088 | ** --context|-c N Use N lines of context |
| 1089 | ** --diff-binary BOOL Include binary files when using external commands |
| 1090 | ** --from|-r VERSION select VERSION as source for the diff |
| 1091 | ** --ignore-space-at-eol Ignore changes to end-of-line whitespace |
| 1092 | ** --ignore-space-at-sol Ignore changes to start-of-line whitespace |
| 1093 | ** --internal|-i use internal diff logic |
| 1094 | ** --side-by-side|-y side-by-side diff |
| 1095 | ** --tk Launch a Tcl/Tk GUI for display |
| 1096 | ** --to VERSION select VERSION as target for the diff |
| 1097 | ** --unified unified diff |
| 1098 | ** -v|--verbose output complete text of added or deleted files |
| 1099 | ** -w Ignore changes to start-of-line and end-of-line |
| 1100 | ** whitespace |
| 1101 | ** -W|--width Width of lines in side-by-side diff |
| 1102 | */ |
| 1103 | void diff_cmd(void){ |
| 1104 | int isGDiff; /* True for gdiff. False for normal diff */ |
| 1105 | int isInternDiff; /* True for internal diff */ |
| 1106 |