Fossil SCM

Fix multiple bugs in the comment parser of the commit command. Allow blank lines in comments.

drh 2007-08-30 19:46 trunk
Commit f030c0aea76a40c60e420db1aaaf82bab07ebe4b
+8 -6
--- src/blob.c
+++ src/blob.c
@@ -343,11 +343,13 @@
343343
}
344344
345345
/*
346346
** Extract a single line of text from pFrom beginning at the current
347347
** cursor location and use that line of text to initialize pTo.
348
-** Return the number of bytes in the line.
348
+** pTo will include the terminating \n. Return the number of bytes
349
+** in the line including the \n at the end. 0 is returned at
350
+** end-of-file.
349351
**
350352
** The cursor of pFrom is left pointing at the first byte past the
351353
** \n that terminated the line.
352354
**
353355
** pTo will be an ephermeral blob. If pFrom changes, it might alter
@@ -355,17 +357,17 @@
355357
*/
356358
int blob_line(Blob *pFrom, Blob *pTo){
357359
char *aData = pFrom->aData;
358360
int n = pFrom->nUsed;
359361
int i = pFrom->iCursor;
360
- /* Do not skip blank lines
361
- ** while( i<n && aData[i]=='\n' ){ i++; }
362
- ** pFrom->iCursor = i;
363
- */
362
+
364363
while( i<n && aData[i]!='\n' ){ i++; }
364
+ if( i<n ){
365
+ assert( aData[i]=='\n' );
366
+ i++;
367
+ }
365368
blob_extract(pFrom, i-pFrom->iCursor, pTo);
366
- if( i<n && aData[i]=='\n' ){ pFrom->iCursor++; }
367369
return pTo->nUsed;
368370
}
369371
370372
/*
371373
** Extract a single token from pFrom and use it to initialize pTo.
372374
--- src/blob.c
+++ src/blob.c
@@ -343,11 +343,13 @@
343 }
344
345 /*
346 ** Extract a single line of text from pFrom beginning at the current
347 ** cursor location and use that line of text to initialize pTo.
348 ** Return the number of bytes in the line.
 
 
349 **
350 ** The cursor of pFrom is left pointing at the first byte past the
351 ** \n that terminated the line.
352 **
353 ** pTo will be an ephermeral blob. If pFrom changes, it might alter
@@ -355,17 +357,17 @@
355 */
356 int blob_line(Blob *pFrom, Blob *pTo){
357 char *aData = pFrom->aData;
358 int n = pFrom->nUsed;
359 int i = pFrom->iCursor;
360 /* Do not skip blank lines
361 ** while( i<n && aData[i]=='\n' ){ i++; }
362 ** pFrom->iCursor = i;
363 */
364 while( i<n && aData[i]!='\n' ){ i++; }
 
 
 
 
365 blob_extract(pFrom, i-pFrom->iCursor, pTo);
366 if( i<n && aData[i]=='\n' ){ pFrom->iCursor++; }
367 return pTo->nUsed;
368 }
369
370 /*
371 ** Extract a single token from pFrom and use it to initialize pTo.
372
--- src/blob.c
+++ src/blob.c
@@ -343,11 +343,13 @@
343 }
344
345 /*
346 ** Extract a single line of text from pFrom beginning at the current
347 ** cursor location and use that line of text to initialize pTo.
348 ** pTo will include the terminating \n. Return the number of bytes
349 ** in the line including the \n at the end. 0 is returned at
350 ** end-of-file.
351 **
352 ** The cursor of pFrom is left pointing at the first byte past the
353 ** \n that terminated the line.
354 **
355 ** pTo will be an ephermeral blob. If pFrom changes, it might alter
@@ -355,17 +357,17 @@
357 */
358 int blob_line(Blob *pFrom, Blob *pTo){
359 char *aData = pFrom->aData;
360 int n = pFrom->nUsed;
361 int i = pFrom->iCursor;
362
 
 
 
363 while( i<n && aData[i]!='\n' ){ i++; }
364 if( i<n ){
365 assert( aData[i]=='\n' );
366 i++;
367 }
368 blob_extract(pFrom, i-pFrom->iCursor, pTo);
 
369 return pTo->nUsed;
370 }
371
372 /*
373 ** Extract a single token from pFrom and use it to initialize pTo.
374
+3 -1
--- src/checkin.c
+++ src/checkin.c
@@ -235,11 +235,13 @@
235235
char *z;
236236
n = blob_size(&line);
237237
z = blob_buffer(&line);
238238
for(i=0; i<n && isspace(z[i]); i++){}
239239
if( i<n && z[i]=='#' ) continue;
240
- blob_appendf(pComment, "%b\n", &line);
240
+ if( i<n || blob_size(pComment)>0 ){
241
+ blob_appendf(pComment, "%b", &line);
242
+ }
241243
}
242244
blob_reset(&text);
243245
zComment = blob_str(pComment);
244246
i = strlen(zComment);
245247
while( i>0 && isspace(zComment[i-1]) ){ i--; }
246248
--- src/checkin.c
+++ src/checkin.c
@@ -235,11 +235,13 @@
235 char *z;
236 n = blob_size(&line);
237 z = blob_buffer(&line);
238 for(i=0; i<n && isspace(z[i]); i++){}
239 if( i<n && z[i]=='#' ) continue;
240 blob_appendf(pComment, "%b\n", &line);
 
 
241 }
242 blob_reset(&text);
243 zComment = blob_str(pComment);
244 i = strlen(zComment);
245 while( i>0 && isspace(zComment[i-1]) ){ i--; }
246
--- src/checkin.c
+++ src/checkin.c
@@ -235,11 +235,13 @@
235 char *z;
236 n = blob_size(&line);
237 z = blob_buffer(&line);
238 for(i=0; i<n && isspace(z[i]); i++){}
239 if( i<n && z[i]=='#' ) continue;
240 if( i<n || blob_size(pComment)>0 ){
241 blob_appendf(pComment, "%b", &line);
242 }
243 }
244 blob_reset(&text);
245 zComment = blob_str(pComment);
246 i = strlen(zComment);
247 while( i>0 && isspace(zComment[i-1]) ){ i--; }
248
+7 -7
--- src/manifest.c
+++ src/manifest.c
@@ -94,19 +94,19 @@
9494
goto manifest_syntax_error;
9595
}
9696
if( seenHeader ){
9797
break;
9898
}
99
- while( blob_line(pContent, &line)>1 ){}
99
+ while( blob_line(pContent, &line)>2 ){}
100100
if( blob_line(pContent, &line)==0 ) break;
101101
z = blob_buffer(&line);
102102
}
103103
seenHeader = 1;
104104
if( blob_token(&line, &token)!=1 ) goto manifest_syntax_error;
105105
if( z[0]=='F' ){
106106
char *zName, *zUuid;
107
- md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
107
+ md5sum_step_text(blob_buffer(&line), blob_size(&line));
108108
if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
109109
if( blob_token(&line, &a2)==0 ) goto manifest_syntax_error;
110110
if( blob_token(&line, &a3)!=0 ) goto manifest_syntax_error;
111111
zName = blob_terminate(&a1);
112112
zUuid = blob_terminate(&a2);
@@ -126,41 +126,41 @@
126126
p->aFile[i].zUuid = zUuid;
127127
if( i>0 && strcmp(p->aFile[i-1].zName, zName)>=0 ){
128128
goto manifest_syntax_error;
129129
}
130130
}else if( z[0]=='C' ){
131
- md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
131
+ md5sum_step_text(blob_buffer(&line), blob_size(&line));
132132
if( p->zComment!=0 ) goto manifest_syntax_error;
133133
if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
134134
if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
135135
p->zComment = blob_terminate(&a1);
136136
defossilize(p->zComment);
137137
}else if( z[0]=='D' ){
138138
char *zDate;
139
- md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
139
+ md5sum_step_text(blob_buffer(&line), blob_size(&line));
140140
if( p->rDate!=0.0 ) goto manifest_syntax_error;
141141
if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
142142
if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
143143
zDate = blob_terminate(&a1);
144144
p->rDate = db_double(0.0, "SELECT julianday(%Q)", zDate);
145145
}else if( z[0]=='U' ){
146
- md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
146
+ md5sum_step_text(blob_buffer(&line), blob_size(&line));
147147
if( p->zUser!=0 ) goto manifest_syntax_error;
148148
if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
149149
if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
150150
p->zUser = blob_terminate(&a1);
151151
defossilize(p->zUser);
152152
}else if( z[0]=='R' ){
153
- md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
153
+ md5sum_step_text(blob_buffer(&line), blob_size(&line));
154154
if( p->zRepoCksum!=0 ) goto manifest_syntax_error;
155155
if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
156156
if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
157157
if( blob_size(&a1)!=32 ) goto manifest_syntax_error;
158158
p->zRepoCksum = blob_terminate(&a1);
159159
if( !validate16(p->zRepoCksum, 32) ) goto manifest_syntax_error;
160160
}else if( z[0]=='P' ){
161
- md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
161
+ md5sum_step_text(blob_buffer(&line), blob_size(&line));
162162
while( blob_token(&line, &a1) ){
163163
char *zUuid;
164164
if( blob_size(&a1)!=UUID_SIZE ) goto manifest_syntax_error;
165165
zUuid = blob_terminate(&a1);
166166
if( !validate16(zUuid, UUID_SIZE) ) goto manifest_syntax_error;
167167
--- src/manifest.c
+++ src/manifest.c
@@ -94,19 +94,19 @@
94 goto manifest_syntax_error;
95 }
96 if( seenHeader ){
97 break;
98 }
99 while( blob_line(pContent, &line)>1 ){}
100 if( blob_line(pContent, &line)==0 ) break;
101 z = blob_buffer(&line);
102 }
103 seenHeader = 1;
104 if( blob_token(&line, &token)!=1 ) goto manifest_syntax_error;
105 if( z[0]=='F' ){
106 char *zName, *zUuid;
107 md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
108 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
109 if( blob_token(&line, &a2)==0 ) goto manifest_syntax_error;
110 if( blob_token(&line, &a3)!=0 ) goto manifest_syntax_error;
111 zName = blob_terminate(&a1);
112 zUuid = blob_terminate(&a2);
@@ -126,41 +126,41 @@
126 p->aFile[i].zUuid = zUuid;
127 if( i>0 && strcmp(p->aFile[i-1].zName, zName)>=0 ){
128 goto manifest_syntax_error;
129 }
130 }else if( z[0]=='C' ){
131 md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
132 if( p->zComment!=0 ) goto manifest_syntax_error;
133 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
134 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
135 p->zComment = blob_terminate(&a1);
136 defossilize(p->zComment);
137 }else if( z[0]=='D' ){
138 char *zDate;
139 md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
140 if( p->rDate!=0.0 ) goto manifest_syntax_error;
141 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
142 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
143 zDate = blob_terminate(&a1);
144 p->rDate = db_double(0.0, "SELECT julianday(%Q)", zDate);
145 }else if( z[0]=='U' ){
146 md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
147 if( p->zUser!=0 ) goto manifest_syntax_error;
148 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
149 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
150 p->zUser = blob_terminate(&a1);
151 defossilize(p->zUser);
152 }else if( z[0]=='R' ){
153 md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
154 if( p->zRepoCksum!=0 ) goto manifest_syntax_error;
155 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
156 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
157 if( blob_size(&a1)!=32 ) goto manifest_syntax_error;
158 p->zRepoCksum = blob_terminate(&a1);
159 if( !validate16(p->zRepoCksum, 32) ) goto manifest_syntax_error;
160 }else if( z[0]=='P' ){
161 md5sum_step_text(blob_buffer(&line), blob_size(&line)+1);
162 while( blob_token(&line, &a1) ){
163 char *zUuid;
164 if( blob_size(&a1)!=UUID_SIZE ) goto manifest_syntax_error;
165 zUuid = blob_terminate(&a1);
166 if( !validate16(zUuid, UUID_SIZE) ) goto manifest_syntax_error;
167
--- src/manifest.c
+++ src/manifest.c
@@ -94,19 +94,19 @@
94 goto manifest_syntax_error;
95 }
96 if( seenHeader ){
97 break;
98 }
99 while( blob_line(pContent, &line)>2 ){}
100 if( blob_line(pContent, &line)==0 ) break;
101 z = blob_buffer(&line);
102 }
103 seenHeader = 1;
104 if( blob_token(&line, &token)!=1 ) goto manifest_syntax_error;
105 if( z[0]=='F' ){
106 char *zName, *zUuid;
107 md5sum_step_text(blob_buffer(&line), blob_size(&line));
108 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
109 if( blob_token(&line, &a2)==0 ) goto manifest_syntax_error;
110 if( blob_token(&line, &a3)!=0 ) goto manifest_syntax_error;
111 zName = blob_terminate(&a1);
112 zUuid = blob_terminate(&a2);
@@ -126,41 +126,41 @@
126 p->aFile[i].zUuid = zUuid;
127 if( i>0 && strcmp(p->aFile[i-1].zName, zName)>=0 ){
128 goto manifest_syntax_error;
129 }
130 }else if( z[0]=='C' ){
131 md5sum_step_text(blob_buffer(&line), blob_size(&line));
132 if( p->zComment!=0 ) goto manifest_syntax_error;
133 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
134 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
135 p->zComment = blob_terminate(&a1);
136 defossilize(p->zComment);
137 }else if( z[0]=='D' ){
138 char *zDate;
139 md5sum_step_text(blob_buffer(&line), blob_size(&line));
140 if( p->rDate!=0.0 ) goto manifest_syntax_error;
141 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
142 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
143 zDate = blob_terminate(&a1);
144 p->rDate = db_double(0.0, "SELECT julianday(%Q)", zDate);
145 }else if( z[0]=='U' ){
146 md5sum_step_text(blob_buffer(&line), blob_size(&line));
147 if( p->zUser!=0 ) goto manifest_syntax_error;
148 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
149 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
150 p->zUser = blob_terminate(&a1);
151 defossilize(p->zUser);
152 }else if( z[0]=='R' ){
153 md5sum_step_text(blob_buffer(&line), blob_size(&line));
154 if( p->zRepoCksum!=0 ) goto manifest_syntax_error;
155 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
156 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
157 if( blob_size(&a1)!=32 ) goto manifest_syntax_error;
158 p->zRepoCksum = blob_terminate(&a1);
159 if( !validate16(p->zRepoCksum, 32) ) goto manifest_syntax_error;
160 }else if( z[0]=='P' ){
161 md5sum_step_text(blob_buffer(&line), blob_size(&line));
162 while( blob_token(&line, &a1) ){
163 char *zUuid;
164 if( blob_size(&a1)!=UUID_SIZE ) goto manifest_syntax_error;
165 zUuid = blob_terminate(&a1);
166 if( !validate16(zUuid, UUID_SIZE) ) goto manifest_syntax_error;
167

Keyboard Shortcuts

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