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

jan.nijtmans 2014-03-03 10:50 diff-eolws
Commit 6392c032ce64db58b659cba036fe24db51404e58
2 files changed +15 -7 +3
+15 -7
--- src/diff.c
+++ src/diff.c
@@ -40,10 +40,11 @@
4040
#define DIFF_WS_WARNING ((u64)0x40000000) /* Warn about whitespace */
4141
#define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */
4242
#define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */
4343
#define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */
4444
#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 */
4546
4647
/*
4748
** These error messages are shared in multiple locations. They are defined
4849
** here for consistency.
4950
*/
@@ -129,14 +130,13 @@
129130
**
130131
** Profiling show that in most cases this routine consumes the bulk of
131132
** the CPU time on a diff.
132133
*/
133134
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;
135136
unsigned int h, h2;
136137
DLine *a;
137
- int ignoreWS = (diffFlags & DIFF_IGNORE_EOLWS)!=0;
138138
139139
/* Count the number of lines. Allocate space to hold
140140
** the returned array.
141141
*/
142142
for(i=j=0, nLine=1; i<n; i++, j++){
@@ -162,18 +162,24 @@
162162
return a;
163163
}
164164
165165
/* Fill in the array */
166166
for(i=0; i<nLine; i++){
167
- a[i].z = z;
168167
for(j=0; z[j] && z[j]!='\n'; j++){}
169168
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++){
172178
h = h ^ (h<<2) ^ z[x];
173179
}
174
- a[i].h = h = (h<<LENGTH_MASK_SZ) | k;
180
+ a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
175181
h2 = h % nLine;
176182
a[i].iNext = a[h2].iHash;
177183
a[h2].iHash = i+1;
178184
z += j+1;
179185
}
@@ -1862,11 +1868,13 @@
18621868
f *= DIFF_CONTEXT_MASK+1;
18631869
if( f > DIFF_WIDTH_MASK ) f = DIFF_CONTEXT_MASK;
18641870
diffFlags |= f;
18651871
}
18661872
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);
18681876
if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO;
18691877
if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT;
18701878
if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT;
18711879
if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF;
18721880
return diffFlags;
18731881
--- 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
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -1087,16 +1087,19 @@
10871087
** --brief Show filenames only
10881088
** --context|-c N Use N lines of context
10891089
** --diff-binary BOOL Include binary files when using external commands
10901090
** --from|-r VERSION select VERSION as source for the diff
10911091
** --ignore-space-at-eol Ignore changes to end-of-line whitespace
1092
+** --ignore-space-at-sol Ignore changes to start-of-line whitespace
10921093
** --internal|-i use internal diff logic
10931094
** --side-by-side|-y side-by-side diff
10941095
** --tk Launch a Tcl/Tk GUI for display
10951096
** --to VERSION select VERSION as target for the diff
10961097
** --unified unified diff
10971098
** -v|--verbose output complete text of added or deleted files
1099
+** -w Ignore changes to start-of-line and end-of-line
1100
+** whitespace
10981101
** -W|--width Width of lines in side-by-side diff
10991102
*/
11001103
void diff_cmd(void){
11011104
int isGDiff; /* True for gdiff. False for normal diff */
11021105
int isInternDiff; /* True for internal diff */
11031106
--- 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

Keyboard Shortcuts

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