Fossil SCM
Add the blob_strlen() interface and use it for more robust git-export text.
Commit
7e961919a0b059782ae4557b7654e944f8f865588903283abee1ef59a846ec81
Parent
df5be59e5da4646…
2 files changed
+11
+4
-3
+11
| --- src/blob.c | ||
| +++ src/blob.c | ||
| @@ -365,10 +365,21 @@ | ||
| 365 | 365 | }else{ |
| 366 | 366 | blob_materialize(p); |
| 367 | 367 | } |
| 368 | 368 | return p->aData; |
| 369 | 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 | +} | |
| 370 | 381 | |
| 371 | 382 | /* |
| 372 | 383 | ** Return a pointer to a null-terminated string for a blob that has |
| 373 | 384 | ** been created using blob_append_sql() and not blob_appendf(). If |
| 374 | 385 | ** text was ever added using blob_appendf() then throw an error. |
| 375 | 386 |
| --- 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 @@ | ||
| 1195 | 1195 | ++zTmp; |
| 1196 | 1196 | char *zTmpEnd = strchr(zTmp, '>'); |
| 1197 | 1197 | *(zTmpEnd) = '\0'; |
| 1198 | 1198 | zEmail = fossil_strdup(zTmp); |
| 1199 | 1199 | } |
| 1200 | + fprintf(xCmd, "# rid=%d\n", rid); | |
| 1200 | 1201 | fprintf(xCmd, "committer %s <%s> %s +0000\n", pMan->zUser, zEmail, buf); |
| 1201 | 1202 | fossil_free(zEmail); |
| 1202 | 1203 | blob_init(&comment, pMan->zComment, -1); |
| 1203 | 1204 | if( blob_size(&comment)==0 ){ |
| 1204 | 1205 | blob_append(&comment, "(no comment)", -1); |
| 1205 | 1206 | } |
| 1206 | 1207 | 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)); | |
| 1208 | 1209 | blob_reset(&comment); |
| 1209 | 1210 | iParent = -1; /* Which ancestor is the primary parent */ |
| 1210 | 1211 | for(i=0; i<pMan->nParent; i++){ |
| 1211 | 1212 | char *zOther = gitmirror_find_mark(pMan->azParent[i],0,0); |
| 1212 | 1213 | if( zOther==0 ) continue; |
| @@ -1266,11 +1267,11 @@ | ||
| 1266 | 1267 | /* Include Fossil-generated auxiliary files in the check-in */ |
| 1267 | 1268 | if( fManifest & MFESTFLG_RAW ){ |
| 1268 | 1269 | Blob manifest; |
| 1269 | 1270 | content_get(rid, &manifest); |
| 1270 | 1271 | 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)); | |
| 1272 | 1273 | blob_reset(&manifest); |
| 1273 | 1274 | } |
| 1274 | 1275 | if( fManifest & MFESTFLG_UUID ){ |
| 1275 | 1276 | int n = (int)strlen(zUuid); |
| 1276 | 1277 | fprintf(xCmd,"M 100644 inline manifest.uuid\ndata %d\n%s\n", n, zUuid); |
| @@ -1278,11 +1279,11 @@ | ||
| 1278 | 1279 | if( fManifest & MFESTFLG_TAGS ){ |
| 1279 | 1280 | Blob tagslist; |
| 1280 | 1281 | blob_init(&tagslist, 0, 0); |
| 1281 | 1282 | get_checkin_taglist(rid, &tagslist); |
| 1282 | 1283 | 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)); | |
| 1284 | 1285 | blob_reset(&tagslist); |
| 1285 | 1286 | } |
| 1286 | 1287 | |
| 1287 | 1288 | /* The check-in is finished, so decrement the counter */ |
| 1288 | 1289 | (*pnLimit)--; |
| 1289 | 1290 |
| --- 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 |