Fossil SCM

Add the blob_strlen() interface and use it for more robust git-export text.

drh 2021-01-06 15:10 trunk
Commit 7e961919a0b059782ae4557b7654e944f8f865588903283abee1ef59a846ec81
2 files changed +11 +4 -3
+11
--- src/blob.c
+++ src/blob.c
@@ -365,10 +365,21 @@
365365
}else{
366366
blob_materialize(p);
367367
}
368368
return p->aData;
369369
}
370
+
371
+/*
372
+** Compute the string length of a Blob. If there are embedded
373
+** nul characters, truncate the to blob at the first nul.
374
+*/
375
+int blob_strlen(Blob *p){
376
+ char *z = blob_str(p);
377
+ if( z==0 ) return 0;
378
+ p->nUsed = (int)strlen(p->aData);
379
+ return p->nUsed;
380
+}
370381
371382
/*
372383
** Return a pointer to a null-terminated string for a blob that has
373384
** been created using blob_append_sql() and not blob_appendf(). If
374385
** text was ever added using blob_appendf() then throw an error.
375386
--- src/blob.c
+++ src/blob.c
@@ -365,10 +365,21 @@
365 }else{
366 blob_materialize(p);
367 }
368 return p->aData;
369 }
 
 
 
 
 
 
 
 
 
 
 
370
371 /*
372 ** Return a pointer to a null-terminated string for a blob that has
373 ** been created using blob_append_sql() and not blob_appendf(). If
374 ** text was ever added using blob_appendf() then throw an error.
375
--- src/blob.c
+++ src/blob.c
@@ -365,10 +365,21 @@
365 }else{
366 blob_materialize(p);
367 }
368 return p->aData;
369 }
370
371 /*
372 ** Compute the string length of a Blob. If there are embedded
373 ** nul characters, truncate the to blob at the first nul.
374 */
375 int blob_strlen(Blob *p){
376 char *z = blob_str(p);
377 if( z==0 ) return 0;
378 p->nUsed = (int)strlen(p->aData);
379 return p->nUsed;
380 }
381
382 /*
383 ** Return a pointer to a null-terminated string for a blob that has
384 ** been created using blob_append_sql() and not blob_appendf(). If
385 ** text was ever added using blob_appendf() then throw an error.
386
+4 -3
--- src/export.c
+++ src/export.c
@@ -1195,18 +1195,19 @@
11951195
++zTmp;
11961196
char *zTmpEnd = strchr(zTmp, '>');
11971197
*(zTmpEnd) = '\0';
11981198
zEmail = fossil_strdup(zTmp);
11991199
}
1200
+ fprintf(xCmd, "# rid=%d\n", rid);
12001201
fprintf(xCmd, "committer %s <%s> %s +0000\n", pMan->zUser, zEmail, buf);
12011202
fossil_free(zEmail);
12021203
blob_init(&comment, pMan->zComment, -1);
12031204
if( blob_size(&comment)==0 ){
12041205
blob_append(&comment, "(no comment)", -1);
12051206
}
12061207
blob_appendf(&comment, "\n\nFossilOrigin-Name: %s", zUuid);
1207
- fprintf(xCmd, "data %d\n%s\n", blob_size(&comment), blob_str(&comment));
1208
+ fprintf(xCmd, "data %d\n%s\n", blob_strlen(&comment), blob_str(&comment));
12081209
blob_reset(&comment);
12091210
iParent = -1; /* Which ancestor is the primary parent */
12101211
for(i=0; i<pMan->nParent; i++){
12111212
char *zOther = gitmirror_find_mark(pMan->azParent[i],0,0);
12121213
if( zOther==0 ) continue;
@@ -1266,11 +1267,11 @@
12661267
/* Include Fossil-generated auxiliary files in the check-in */
12671268
if( fManifest & MFESTFLG_RAW ){
12681269
Blob manifest;
12691270
content_get(rid, &manifest);
12701271
fprintf(xCmd,"M 100644 inline manifest\ndata %d\n%s\n",
1271
- blob_size(&manifest), blob_str(&manifest));
1272
+ blob_strlen(&manifest), blob_str(&manifest));
12721273
blob_reset(&manifest);
12731274
}
12741275
if( fManifest & MFESTFLG_UUID ){
12751276
int n = (int)strlen(zUuid);
12761277
fprintf(xCmd,"M 100644 inline manifest.uuid\ndata %d\n%s\n", n, zUuid);
@@ -1278,11 +1279,11 @@
12781279
if( fManifest & MFESTFLG_TAGS ){
12791280
Blob tagslist;
12801281
blob_init(&tagslist, 0, 0);
12811282
get_checkin_taglist(rid, &tagslist);
12821283
fprintf(xCmd,"M 100644 inline manifest.tags\ndata %d\n%s\n",
1283
- blob_size(&tagslist), blob_str(&tagslist));
1284
+ blob_strlen(&tagslist), blob_str(&tagslist));
12841285
blob_reset(&tagslist);
12851286
}
12861287
12871288
/* The check-in is finished, so decrement the counter */
12881289
(*pnLimit)--;
12891290
--- src/export.c
+++ src/export.c
@@ -1195,18 +1195,19 @@
1195 ++zTmp;
1196 char *zTmpEnd = strchr(zTmp, '>');
1197 *(zTmpEnd) = '\0';
1198 zEmail = fossil_strdup(zTmp);
1199 }
 
1200 fprintf(xCmd, "committer %s <%s> %s +0000\n", pMan->zUser, zEmail, buf);
1201 fossil_free(zEmail);
1202 blob_init(&comment, pMan->zComment, -1);
1203 if( blob_size(&comment)==0 ){
1204 blob_append(&comment, "(no comment)", -1);
1205 }
1206 blob_appendf(&comment, "\n\nFossilOrigin-Name: %s", zUuid);
1207 fprintf(xCmd, "data %d\n%s\n", blob_size(&comment), blob_str(&comment));
1208 blob_reset(&comment);
1209 iParent = -1; /* Which ancestor is the primary parent */
1210 for(i=0; i<pMan->nParent; i++){
1211 char *zOther = gitmirror_find_mark(pMan->azParent[i],0,0);
1212 if( zOther==0 ) continue;
@@ -1266,11 +1267,11 @@
1266 /* Include Fossil-generated auxiliary files in the check-in */
1267 if( fManifest & MFESTFLG_RAW ){
1268 Blob manifest;
1269 content_get(rid, &manifest);
1270 fprintf(xCmd,"M 100644 inline manifest\ndata %d\n%s\n",
1271 blob_size(&manifest), blob_str(&manifest));
1272 blob_reset(&manifest);
1273 }
1274 if( fManifest & MFESTFLG_UUID ){
1275 int n = (int)strlen(zUuid);
1276 fprintf(xCmd,"M 100644 inline manifest.uuid\ndata %d\n%s\n", n, zUuid);
@@ -1278,11 +1279,11 @@
1278 if( fManifest & MFESTFLG_TAGS ){
1279 Blob tagslist;
1280 blob_init(&tagslist, 0, 0);
1281 get_checkin_taglist(rid, &tagslist);
1282 fprintf(xCmd,"M 100644 inline manifest.tags\ndata %d\n%s\n",
1283 blob_size(&tagslist), blob_str(&tagslist));
1284 blob_reset(&tagslist);
1285 }
1286
1287 /* The check-in is finished, so decrement the counter */
1288 (*pnLimit)--;
1289
--- src/export.c
+++ src/export.c
@@ -1195,18 +1195,19 @@
1195 ++zTmp;
1196 char *zTmpEnd = strchr(zTmp, '>');
1197 *(zTmpEnd) = '\0';
1198 zEmail = fossil_strdup(zTmp);
1199 }
1200 fprintf(xCmd, "# rid=%d\n", rid);
1201 fprintf(xCmd, "committer %s <%s> %s +0000\n", pMan->zUser, zEmail, buf);
1202 fossil_free(zEmail);
1203 blob_init(&comment, pMan->zComment, -1);
1204 if( blob_size(&comment)==0 ){
1205 blob_append(&comment, "(no comment)", -1);
1206 }
1207 blob_appendf(&comment, "\n\nFossilOrigin-Name: %s", zUuid);
1208 fprintf(xCmd, "data %d\n%s\n", blob_strlen(&comment), blob_str(&comment));
1209 blob_reset(&comment);
1210 iParent = -1; /* Which ancestor is the primary parent */
1211 for(i=0; i<pMan->nParent; i++){
1212 char *zOther = gitmirror_find_mark(pMan->azParent[i],0,0);
1213 if( zOther==0 ) continue;
@@ -1266,11 +1267,11 @@
1267 /* Include Fossil-generated auxiliary files in the check-in */
1268 if( fManifest & MFESTFLG_RAW ){
1269 Blob manifest;
1270 content_get(rid, &manifest);
1271 fprintf(xCmd,"M 100644 inline manifest\ndata %d\n%s\n",
1272 blob_strlen(&manifest), blob_str(&manifest));
1273 blob_reset(&manifest);
1274 }
1275 if( fManifest & MFESTFLG_UUID ){
1276 int n = (int)strlen(zUuid);
1277 fprintf(xCmd,"M 100644 inline manifest.uuid\ndata %d\n%s\n", n, zUuid);
@@ -1278,11 +1279,11 @@
1279 if( fManifest & MFESTFLG_TAGS ){
1280 Blob tagslist;
1281 blob_init(&tagslist, 0, 0);
1282 get_checkin_taglist(rid, &tagslist);
1283 fprintf(xCmd,"M 100644 inline manifest.tags\ndata %d\n%s\n",
1284 blob_strlen(&tagslist), blob_str(&tagslist));
1285 blob_reset(&tagslist);
1286 }
1287
1288 /* The check-in is finished, so decrement the counter */
1289 (*pnLimit)--;
1290

Keyboard Shortcuts

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