Fossil SCM

Adopt the diff algorithm changes from trunk.

mistachkin 2016-10-04 02:43 UTC binDiffFix merge
Commit f9f2d7692698f5cc5ccc2715534744f35a701cbd
-25
--- src/blob.c
+++ src/blob.c
@@ -87,35 +87,10 @@
8787
#else
8888
#define assert_blob_is_reset(x)
8989
#endif
9090
9191
92
-/*
93
-** The built-in strchr() function cannot deal with NUL characters.
94
-** So here is a substitute. If the character being sought after
95
-** is not NUL, this function will call the built-in strchr(). In
96
-** that case, the "n" argument is ignored. If the value of "n"
97
-** is less than zero, the length of the "str" value will be used;
98
-** however, that is unlikely to produce a useful result.
99
-*/
100
-char *fossil_strchr(
101
- const char *str, /* Null-terminated string being searched. */
102
- int n, /* Length of the string being searched. */
103
- int c /* Character being sought. */
104
-){
105
- if( c=='\0' ){
106
- int i = 0;
107
- if( n<0 ) n = strlen(str); /* pedantic */
108
- for(; i<n; i++){
109
- if( str[i]==c ) return str+i;
110
- }
111
- return 0;
112
- }else{
113
- return strchr(str, c);
114
- }
115
-}
116
-
11792
/*
11893
** We find that the built-in isspace() function does not work for
11994
** some international character sets. So here is a substitute.
12095
*/
12196
int fossil_isspace(char c){
12297
--- src/blob.c
+++ src/blob.c
@@ -87,35 +87,10 @@
87 #else
88 #define assert_blob_is_reset(x)
89 #endif
90
91
92 /*
93 ** The built-in strchr() function cannot deal with NUL characters.
94 ** So here is a substitute. If the character being sought after
95 ** is not NUL, this function will call the built-in strchr(). In
96 ** that case, the "n" argument is ignored. If the value of "n"
97 ** is less than zero, the length of the "str" value will be used;
98 ** however, that is unlikely to produce a useful result.
99 */
100 char *fossil_strchr(
101 const char *str, /* Null-terminated string being searched. */
102 int n, /* Length of the string being searched. */
103 int c /* Character being sought. */
104 ){
105 if( c=='\0' ){
106 int i = 0;
107 if( n<0 ) n = strlen(str); /* pedantic */
108 for(; i<n; i++){
109 if( str[i]==c ) return str+i;
110 }
111 return 0;
112 }else{
113 return strchr(str, c);
114 }
115 }
116
117 /*
118 ** We find that the built-in isspace() function does not work for
119 ** some international character sets. So here is a substitute.
120 */
121 int fossil_isspace(char c){
122
--- src/blob.c
+++ src/blob.c
@@ -87,35 +87,10 @@
87 #else
88 #define assert_blob_is_reset(x)
89 #endif
90
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92 /*
93 ** We find that the built-in isspace() function does not work for
94 ** some international character sets. So here is a substitute.
95 */
96 int fossil_isspace(char c){
97
-25
--- src/blob.c
+++ src/blob.c
@@ -87,35 +87,10 @@
8787
#else
8888
#define assert_blob_is_reset(x)
8989
#endif
9090
9191
92
-/*
93
-** The built-in strchr() function cannot deal with NUL characters.
94
-** So here is a substitute. If the character being sought after
95
-** is not NUL, this function will call the built-in strchr(). In
96
-** that case, the "n" argument is ignored. If the value of "n"
97
-** is less than zero, the length of the "str" value will be used;
98
-** however, that is unlikely to produce a useful result.
99
-*/
100
-char *fossil_strchr(
101
- const char *str, /* Null-terminated string being searched. */
102
- int n, /* Length of the string being searched. */
103
- int c /* Character being sought. */
104
-){
105
- if( c=='\0' ){
106
- int i = 0;
107
- if( n<0 ) n = strlen(str); /* pedantic */
108
- for(; i<n; i++){
109
- if( str[i]==c ) return str+i;
110
- }
111
- return 0;
112
- }else{
113
- return strchr(str, c);
114
- }
115
-}
116
-
11792
/*
11893
** We find that the built-in isspace() function does not work for
11994
** some international character sets. So here is a substitute.
12095
*/
12196
int fossil_isspace(char c){
12297
--- src/blob.c
+++ src/blob.c
@@ -87,35 +87,10 @@
87 #else
88 #define assert_blob_is_reset(x)
89 #endif
90
91
92 /*
93 ** The built-in strchr() function cannot deal with NUL characters.
94 ** So here is a substitute. If the character being sought after
95 ** is not NUL, this function will call the built-in strchr(). In
96 ** that case, the "n" argument is ignored. If the value of "n"
97 ** is less than zero, the length of the "str" value will be used;
98 ** however, that is unlikely to produce a useful result.
99 */
100 char *fossil_strchr(
101 const char *str, /* Null-terminated string being searched. */
102 int n, /* Length of the string being searched. */
103 int c /* Character being sought. */
104 ){
105 if( c=='\0' ){
106 int i = 0;
107 if( n<0 ) n = strlen(str); /* pedantic */
108 for(; i<n; i++){
109 if( str[i]==c ) return str+i;
110 }
111 return 0;
112 }else{
113 return strchr(str, c);
114 }
115 }
116
117 /*
118 ** We find that the built-in isspace() function does not work for
119 ** some international character sets. So here is a substitute.
120 */
121 int fossil_isspace(char c){
122
--- src/blob.c
+++ src/blob.c
@@ -87,35 +87,10 @@
87 #else
88 #define assert_blob_is_reset(x)
89 #endif
90
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92 /*
93 ** We find that the built-in isspace() function does not work for
94 ** some international character sets. So here is a substitute.
95 */
96 int fossil_isspace(char c){
97
+15 -20
--- src/diff.c
+++ src/diff.c
@@ -125,17 +125,23 @@
125125
** function, a string is considered empty if it contains no characters
126126
** -OR- it contains only NUL characters.
127127
*/
128128
static int count_lines(
129129
const char *z,
130
- int n
130
+ int n,
131
+ int *pnLine
131132
){
132133
int nLine;
133134
const char *zNL, *z2;
134
- for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){}
135
- if( z2[0]!='\0' ) nLine++;
136
- return nLine;
135
+ for(nLine=0, z2=z; (zNL = strchr(z2,'\n'))!=0; z2=zNL+1, nLine++){}
136
+ if( z2[0]!='\0' ){
137
+ nLine++;
138
+ do{ z2++; }while( z2[0] );
139
+ }
140
+ if( n!=(int)(z2-z) ) return 0;
141
+ if( pnLine ) *pnLine = nLine;
142
+ return 1;
137143
}
138144
139145
/*
140146
** Return an array of DLine objects containing a pointer to the
141147
** start of each line and a hash of that line. The lower
@@ -160,25 +166,23 @@
160166
int nLine, i, k, nn, s, x;
161167
unsigned int h, h2;
162168
DLine *a;
163169
const char *zNL;
164170
165
- nLine = count_lines(z, n);
171
+ if( count_lines(z, n, &nLine)==0 ){
172
+ return 0;
173
+ }
166174
assert( nLine>0 || z[0]=='\0' );
167175
a = fossil_malloc( sizeof(a[0])*nLine );
168176
memset(a, 0, sizeof(a[0])*nLine);
169177
if( nLine==0 ){
170
- if( fossil_strchr(z,n,'\0')!=0 ){
171
- fossil_free(a);
172
- return 0;
173
- }
174178
*pnLine = 0;
175179
return a;
176180
}
177181
i = 0;
178182
do{
179
- zNL = fossil_strchr(z,n,'\n');
183
+ zNL = strchr(z,'\n');
180184
if( zNL==0 ) zNL = z+n;
181185
nn = (int)(zNL - z);
182186
if( nn>LENGTH_MASK ){
183187
fossil_free(a);
184188
return 0;
@@ -196,14 +200,10 @@
196200
if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
197201
int numws = 0;
198202
while( s<k && fossil_isspace(z[s]) ){ s++; }
199203
for(h=0, x=s; x<k; x++){
200204
char c = z[x];
201
- if( c=='\0' ){
202
- fossil_free(a);
203
- return 0;
204
- }
205205
if( fossil_isspace(c) ){
206206
++numws;
207207
}else{
208208
h += c;
209209
h *= 0x9e3779b1;
@@ -210,16 +210,11 @@
210210
}
211211
}
212212
k -= numws;
213213
}else{
214214
for(h=0, x=s; x<k; x++){
215
- char c = z[x];
216
- if( c=='\0' ){
217
- fossil_free(a);
218
- return 0;
219
- }
220
- h += c;
215
+ h += z[x];
221216
h *= 0x9e3779b1;
222217
}
223218
}
224219
a[i].indent = s;
225220
a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
226221
--- src/diff.c
+++ src/diff.c
@@ -125,17 +125,23 @@
125 ** function, a string is considered empty if it contains no characters
126 ** -OR- it contains only NUL characters.
127 */
128 static int count_lines(
129 const char *z,
130 int n
 
131 ){
132 int nLine;
133 const char *zNL, *z2;
134 for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){}
135 if( z2[0]!='\0' ) nLine++;
136 return nLine;
 
 
 
 
 
137 }
138
139 /*
140 ** Return an array of DLine objects containing a pointer to the
141 ** start of each line and a hash of that line. The lower
@@ -160,25 +166,23 @@
160 int nLine, i, k, nn, s, x;
161 unsigned int h, h2;
162 DLine *a;
163 const char *zNL;
164
165 nLine = count_lines(z, n);
 
 
166 assert( nLine>0 || z[0]=='\0' );
167 a = fossil_malloc( sizeof(a[0])*nLine );
168 memset(a, 0, sizeof(a[0])*nLine);
169 if( nLine==0 ){
170 if( fossil_strchr(z,n,'\0')!=0 ){
171 fossil_free(a);
172 return 0;
173 }
174 *pnLine = 0;
175 return a;
176 }
177 i = 0;
178 do{
179 zNL = fossil_strchr(z,n,'\n');
180 if( zNL==0 ) zNL = z+n;
181 nn = (int)(zNL - z);
182 if( nn>LENGTH_MASK ){
183 fossil_free(a);
184 return 0;
@@ -196,14 +200,10 @@
196 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
197 int numws = 0;
198 while( s<k && fossil_isspace(z[s]) ){ s++; }
199 for(h=0, x=s; x<k; x++){
200 char c = z[x];
201 if( c=='\0' ){
202 fossil_free(a);
203 return 0;
204 }
205 if( fossil_isspace(c) ){
206 ++numws;
207 }else{
208 h += c;
209 h *= 0x9e3779b1;
@@ -210,16 +210,11 @@
210 }
211 }
212 k -= numws;
213 }else{
214 for(h=0, x=s; x<k; x++){
215 char c = z[x];
216 if( c=='\0' ){
217 fossil_free(a);
218 return 0;
219 }
220 h += c;
221 h *= 0x9e3779b1;
222 }
223 }
224 a[i].indent = s;
225 a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
226
--- src/diff.c
+++ src/diff.c
@@ -125,17 +125,23 @@
125 ** function, a string is considered empty if it contains no characters
126 ** -OR- it contains only NUL characters.
127 */
128 static int count_lines(
129 const char *z,
130 int n,
131 int *pnLine
132 ){
133 int nLine;
134 const char *zNL, *z2;
135 for(nLine=0, z2=z; (zNL = strchr(z2,'\n'))!=0; z2=zNL+1, nLine++){}
136 if( z2[0]!='\0' ){
137 nLine++;
138 do{ z2++; }while( z2[0] );
139 }
140 if( n!=(int)(z2-z) ) return 0;
141 if( pnLine ) *pnLine = nLine;
142 return 1;
143 }
144
145 /*
146 ** Return an array of DLine objects containing a pointer to the
147 ** start of each line and a hash of that line. The lower
@@ -160,25 +166,23 @@
166 int nLine, i, k, nn, s, x;
167 unsigned int h, h2;
168 DLine *a;
169 const char *zNL;
170
171 if( count_lines(z, n, &nLine)==0 ){
172 return 0;
173 }
174 assert( nLine>0 || z[0]=='\0' );
175 a = fossil_malloc( sizeof(a[0])*nLine );
176 memset(a, 0, sizeof(a[0])*nLine);
177 if( nLine==0 ){
 
 
 
 
178 *pnLine = 0;
179 return a;
180 }
181 i = 0;
182 do{
183 zNL = strchr(z,'\n');
184 if( zNL==0 ) zNL = z+n;
185 nn = (int)(zNL - z);
186 if( nn>LENGTH_MASK ){
187 fossil_free(a);
188 return 0;
@@ -196,14 +200,10 @@
200 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
201 int numws = 0;
202 while( s<k && fossil_isspace(z[s]) ){ s++; }
203 for(h=0, x=s; x<k; x++){
204 char c = z[x];
 
 
 
 
205 if( fossil_isspace(c) ){
206 ++numws;
207 }else{
208 h += c;
209 h *= 0x9e3779b1;
@@ -210,16 +210,11 @@
210 }
211 }
212 k -= numws;
213 }else{
214 for(h=0, x=s; x<k; x++){
215 h += z[x];
 
 
 
 
 
216 h *= 0x9e3779b1;
217 }
218 }
219 a[i].indent = s;
220 a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
221
+15 -20
--- src/diff.c
+++ src/diff.c
@@ -125,17 +125,23 @@
125125
** function, a string is considered empty if it contains no characters
126126
** -OR- it contains only NUL characters.
127127
*/
128128
static int count_lines(
129129
const char *z,
130
- int n
130
+ int n,
131
+ int *pnLine
131132
){
132133
int nLine;
133134
const char *zNL, *z2;
134
- for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){}
135
- if( z2[0]!='\0' ) nLine++;
136
- return nLine;
135
+ for(nLine=0, z2=z; (zNL = strchr(z2,'\n'))!=0; z2=zNL+1, nLine++){}
136
+ if( z2[0]!='\0' ){
137
+ nLine++;
138
+ do{ z2++; }while( z2[0] );
139
+ }
140
+ if( n!=(int)(z2-z) ) return 0;
141
+ if( pnLine ) *pnLine = nLine;
142
+ return 1;
137143
}
138144
139145
/*
140146
** Return an array of DLine objects containing a pointer to the
141147
** start of each line and a hash of that line. The lower
@@ -160,25 +166,23 @@
160166
int nLine, i, k, nn, s, x;
161167
unsigned int h, h2;
162168
DLine *a;
163169
const char *zNL;
164170
165
- nLine = count_lines(z, n);
171
+ if( count_lines(z, n, &nLine)==0 ){
172
+ return 0;
173
+ }
166174
assert( nLine>0 || z[0]=='\0' );
167175
a = fossil_malloc( sizeof(a[0])*nLine );
168176
memset(a, 0, sizeof(a[0])*nLine);
169177
if( nLine==0 ){
170
- if( fossil_strchr(z,n,'\0')!=0 ){
171
- fossil_free(a);
172
- return 0;
173
- }
174178
*pnLine = 0;
175179
return a;
176180
}
177181
i = 0;
178182
do{
179
- zNL = fossil_strchr(z,n,'\n');
183
+ zNL = strchr(z,'\n');
180184
if( zNL==0 ) zNL = z+n;
181185
nn = (int)(zNL - z);
182186
if( nn>LENGTH_MASK ){
183187
fossil_free(a);
184188
return 0;
@@ -196,14 +200,10 @@
196200
if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
197201
int numws = 0;
198202
while( s<k && fossil_isspace(z[s]) ){ s++; }
199203
for(h=0, x=s; x<k; x++){
200204
char c = z[x];
201
- if( c=='\0' ){
202
- fossil_free(a);
203
- return 0;
204
- }
205205
if( fossil_isspace(c) ){
206206
++numws;
207207
}else{
208208
h += c;
209209
h *= 0x9e3779b1;
@@ -210,16 +210,11 @@
210210
}
211211
}
212212
k -= numws;
213213
}else{
214214
for(h=0, x=s; x<k; x++){
215
- char c = z[x];
216
- if( c=='\0' ){
217
- fossil_free(a);
218
- return 0;
219
- }
220
- h += c;
215
+ h += z[x];
221216
h *= 0x9e3779b1;
222217
}
223218
}
224219
a[i].indent = s;
225220
a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
226221
--- src/diff.c
+++ src/diff.c
@@ -125,17 +125,23 @@
125 ** function, a string is considered empty if it contains no characters
126 ** -OR- it contains only NUL characters.
127 */
128 static int count_lines(
129 const char *z,
130 int n
 
131 ){
132 int nLine;
133 const char *zNL, *z2;
134 for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){}
135 if( z2[0]!='\0' ) nLine++;
136 return nLine;
 
 
 
 
 
137 }
138
139 /*
140 ** Return an array of DLine objects containing a pointer to the
141 ** start of each line and a hash of that line. The lower
@@ -160,25 +166,23 @@
160 int nLine, i, k, nn, s, x;
161 unsigned int h, h2;
162 DLine *a;
163 const char *zNL;
164
165 nLine = count_lines(z, n);
 
 
166 assert( nLine>0 || z[0]=='\0' );
167 a = fossil_malloc( sizeof(a[0])*nLine );
168 memset(a, 0, sizeof(a[0])*nLine);
169 if( nLine==0 ){
170 if( fossil_strchr(z,n,'\0')!=0 ){
171 fossil_free(a);
172 return 0;
173 }
174 *pnLine = 0;
175 return a;
176 }
177 i = 0;
178 do{
179 zNL = fossil_strchr(z,n,'\n');
180 if( zNL==0 ) zNL = z+n;
181 nn = (int)(zNL - z);
182 if( nn>LENGTH_MASK ){
183 fossil_free(a);
184 return 0;
@@ -196,14 +200,10 @@
196 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
197 int numws = 0;
198 while( s<k && fossil_isspace(z[s]) ){ s++; }
199 for(h=0, x=s; x<k; x++){
200 char c = z[x];
201 if( c=='\0' ){
202 fossil_free(a);
203 return 0;
204 }
205 if( fossil_isspace(c) ){
206 ++numws;
207 }else{
208 h += c;
209 h *= 0x9e3779b1;
@@ -210,16 +210,11 @@
210 }
211 }
212 k -= numws;
213 }else{
214 for(h=0, x=s; x<k; x++){
215 char c = z[x];
216 if( c=='\0' ){
217 fossil_free(a);
218 return 0;
219 }
220 h += c;
221 h *= 0x9e3779b1;
222 }
223 }
224 a[i].indent = s;
225 a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
226
--- src/diff.c
+++ src/diff.c
@@ -125,17 +125,23 @@
125 ** function, a string is considered empty if it contains no characters
126 ** -OR- it contains only NUL characters.
127 */
128 static int count_lines(
129 const char *z,
130 int n,
131 int *pnLine
132 ){
133 int nLine;
134 const char *zNL, *z2;
135 for(nLine=0, z2=z; (zNL = strchr(z2,'\n'))!=0; z2=zNL+1, nLine++){}
136 if( z2[0]!='\0' ){
137 nLine++;
138 do{ z2++; }while( z2[0] );
139 }
140 if( n!=(int)(z2-z) ) return 0;
141 if( pnLine ) *pnLine = nLine;
142 return 1;
143 }
144
145 /*
146 ** Return an array of DLine objects containing a pointer to the
147 ** start of each line and a hash of that line. The lower
@@ -160,25 +166,23 @@
166 int nLine, i, k, nn, s, x;
167 unsigned int h, h2;
168 DLine *a;
169 const char *zNL;
170
171 if( count_lines(z, n, &nLine)==0 ){
172 return 0;
173 }
174 assert( nLine>0 || z[0]=='\0' );
175 a = fossil_malloc( sizeof(a[0])*nLine );
176 memset(a, 0, sizeof(a[0])*nLine);
177 if( nLine==0 ){
 
 
 
 
178 *pnLine = 0;
179 return a;
180 }
181 i = 0;
182 do{
183 zNL = strchr(z,'\n');
184 if( zNL==0 ) zNL = z+n;
185 nn = (int)(zNL - z);
186 if( nn>LENGTH_MASK ){
187 fossil_free(a);
188 return 0;
@@ -196,14 +200,10 @@
200 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
201 int numws = 0;
202 while( s<k && fossil_isspace(z[s]) ){ s++; }
203 for(h=0, x=s; x<k; x++){
204 char c = z[x];
 
 
 
 
205 if( fossil_isspace(c) ){
206 ++numws;
207 }else{
208 h += c;
209 h *= 0x9e3779b1;
@@ -210,16 +210,11 @@
210 }
211 }
212 k -= numws;
213 }else{
214 for(h=0, x=s; x<k; x++){
215 h += z[x];
 
 
 
 
 
216 h *= 0x9e3779b1;
217 }
218 }
219 a[i].indent = s;
220 a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
221

Keyboard Shortcuts

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