Fossil

Check-in [f9f2d769]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Adopt the diff algorithm changes from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | binDiffFix
Files: files | file ages | folders
SHA1:f9f2d7692698f5cc5ccc2715534744f35a701cbd
User & Date: mistachkin 2016-10-04 02:43:17
Context
2016-10-04
02:44
Whitespace tweak. check-in: 4ed91cda user: mistachkin tags: binDiffFix
02:43
Adopt the diff algorithm changes from trunk. check-in: f9f2d769 user: mistachkin tags: binDiffFix
02:16
Detect binary files that look like text but end with a sequence of zeros. check-in: 0e0e29ae user: drh tags: trunk
2016-10-03
23:23
Minor optimization. check-in: 9903ce5a user: mistachkin tags: binDiffFix
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/blob.c.

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#if 0  /* Enable for debugging only */
#define assert_blob_is_reset(x) assert(blob_is_reset(x))
#else
#define assert_blob_is_reset(x)
#endif


/*
** The built-in strchr() function cannot deal with NUL characters.
** So here is a substitute.  If the character being sought after
** is not NUL, this function will call the built-in strchr().  In
** that case, the "n" argument is ignored.  If the value of "n"
** is less than zero, the length of the "str" value will be used;
** however, that is unlikely to produce a useful result.
*/
char *fossil_strchr(
  const char *str, /* Null-terminated string being searched. */
  int n,           /* Length of the string being searched. */
  int c            /* Character being sought. */
){
  if( c=='\0' ){
    int i = 0;
    if( n<0 ) n = strlen(str); /* pedantic */
    for(; i<n; i++){
      if( str[i]==c ) return str+i;
    }
    return 0;
  }else{
    return strchr(str, c);
  }
}

/*
** We find that the built-in isspace() function does not work for
** some international character sets.  So here is a substitute.
*/
int fossil_isspace(char c){
  return c==' ' || (c<='\r' && c>='\t');
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







85
86
87
88
89
90
91

























92
93
94
95
96
97
98
#if 0  /* Enable for debugging only */
#define assert_blob_is_reset(x) assert(blob_is_reset(x))
#else
#define assert_blob_is_reset(x)
#endif



























/*
** We find that the built-in isspace() function does not work for
** some international character sets.  So here is a substitute.
*/
int fossil_isspace(char c){
  return c==' ' || (c<='\r' && c>='\t');
}

Changes to src/diff.c.

123
124
125
126
127
128
129
130

131
132
133
134
135





136
137
138
139
140
141
142
143
...
158
159
160
161
162
163
164
165


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
** in the count even if it lacks the \n terminator.  If an empty string
** is specified, the number of lines is zero.  For the purposes of this
** function, a string is considered empty if it contains no characters
** -OR- it contains only NUL characters.
*/
static int count_lines(
  const char *z,
  int n

){
  int nLine;
  const char *zNL, *z2;
  for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){}
  if( z2[0]!='\0' ) nLine++;





  return nLine;
}

/*
** Return an array of DLine objects containing a pointer to the
** start of each line and a hash of that line.  The lower
** bits of the hash store the length of each line.
**
................................................................................
  u64 diffFlags
){
  int nLine, i, k, nn, s, x;
  unsigned int h, h2;
  DLine *a;
  const char *zNL;

  nLine = count_lines(z, n);


  assert( nLine>0 || z[0]=='\0' );
  a = fossil_malloc( sizeof(a[0])*nLine );
  memset(a, 0, sizeof(a[0])*nLine);
  if( nLine==0 ){
    if( fossil_strchr(z,n,'\0')!=0 ){
      fossil_free(a);
      return 0;
    }
    *pnLine = 0;
    return a;
  }
  i = 0;
  do{
    zNL = fossil_strchr(z,n,'\n');
    if( zNL==0 ) zNL = z+n;
    nn = (int)(zNL - z);
    if( nn>LENGTH_MASK ){
      fossil_free(a);
      return 0;
    }
    a[i].z = z;
................................................................................
      while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
    }
    if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
      int numws = 0;
      while( s<k && fossil_isspace(z[s]) ){ s++; }
      for(h=0, x=s; x<k; x++){
        char c = z[x];
        if( c=='\0' ){
          fossil_free(a);
          return 0;
        }
        if( fossil_isspace(c) ){
          ++numws;
        }else{
          h += c;
          h *= 0x9e3779b1;
        }
      }
      k -= numws;
    }else{
      for(h=0, x=s; x<k; x++){
        char c = z[x];
        if( c=='\0' ){
          fossil_free(a);
          return 0;
        }
        h += c;
        h *= 0x9e3779b1;
      }
    }
    a[i].indent = s;
    a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
    h2 = h % nLine;
    a[i].iNext = a[h2].iHash;







|
>



|
|
>
>
>
>
>
|







 







|
>
>




<
<
<
<





|







 







<
<
<
<










<
<
<
<
<
|







123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177




178
179
180
181
182
183
184
185
186
187
188
189
190
...
198
199
200
201
202
203
204




205
206
207
208
209
210
211
212
213
214





215
216
217
218
219
220
221
222
** in the count even if it lacks the \n terminator.  If an empty string
** is specified, the number of lines is zero.  For the purposes of this
** function, a string is considered empty if it contains no characters
** -OR- it contains only NUL characters.
*/
static int count_lines(
  const char *z,
  int n,
  int *pnLine
){
  int nLine;
  const char *zNL, *z2;
  for(nLine=0, z2=z; (zNL = strchr(z2,'\n'))!=0; z2=zNL+1, nLine++){}
  if( z2[0]!='\0' ){
    nLine++;
    do{ z2++; }while( z2[0] );
  }
  if( n!=(int)(z2-z) ) return 0;
  if( pnLine ) *pnLine = nLine;
  return 1;
}

/*
** Return an array of DLine objects containing a pointer to the
** start of each line and a hash of that line.  The lower
** bits of the hash store the length of each line.
**
................................................................................
  u64 diffFlags
){
  int nLine, i, k, nn, s, x;
  unsigned int h, h2;
  DLine *a;
  const char *zNL;

  if( count_lines(z, n, &nLine)==0 ){
    return 0;
  }
  assert( nLine>0 || z[0]=='\0' );
  a = fossil_malloc( sizeof(a[0])*nLine );
  memset(a, 0, sizeof(a[0])*nLine);
  if( nLine==0 ){




    *pnLine = 0;
    return a;
  }
  i = 0;
  do{
    zNL = strchr(z,'\n');
    if( zNL==0 ) zNL = z+n;
    nn = (int)(zNL - z);
    if( nn>LENGTH_MASK ){
      fossil_free(a);
      return 0;
    }
    a[i].z = z;
................................................................................
      while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
    }
    if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
      int numws = 0;
      while( s<k && fossil_isspace(z[s]) ){ s++; }
      for(h=0, x=s; x<k; x++){
        char c = z[x];




        if( fossil_isspace(c) ){
          ++numws;
        }else{
          h += c;
          h *= 0x9e3779b1;
        }
      }
      k -= numws;
    }else{
      for(h=0, x=s; x<k; x++){





        h += z[x];
        h *= 0x9e3779b1;
      }
    }
    a[i].indent = s;
    a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
    h2 = h % nLine;
    a[i].iNext = a[h2].iHash;