Fossil SCM
If the "fossil import --git" command encounters a file that looks like a well-formed Fossil artifact, append a line to the end of that file so that it is no longer a well-formed artifact before importing it. This prevents "manifest" files that found their way into Git from being reinterpreted by Fossil when the repository is reimported back into Fossil.
Commit
2777682b632030db27990aa8b1f7ede64c0b6f17faabc84c45283218771be70f
Parent
761696443aca574…
5 files changed
+1
-1
+3
+5
-4
+1
-1
+1
-1
+1
-1
| --- src/checkout.c | ||
| +++ src/checkout.c | ||
| @@ -180,11 +180,11 @@ | ||
| 180 | 180 | flg = db_get_manifest_setting(); |
| 181 | 181 | |
| 182 | 182 | if( flg & MFESTFLG_RAW ){ |
| 183 | 183 | blob_zero(&manifest); |
| 184 | 184 | content_get(vid, &manifest); |
| 185 | - sterilize_manifest(&manifest); | |
| 185 | + sterilize_manifest(&manifest, CFTYPE_MANIFEST); | |
| 186 | 186 | zManFile = mprintf("%smanifest", g.zLocalRoot); |
| 187 | 187 | blob_write_to_file(&manifest, zManFile); |
| 188 | 188 | free(zManFile); |
| 189 | 189 | }else{ |
| 190 | 190 | if( !db_exists("SELECT 1 FROM vfile WHERE pathname='manifest'") ){ |
| 191 | 191 |
| --- src/checkout.c | |
| +++ src/checkout.c | |
| @@ -180,11 +180,11 @@ | |
| 180 | flg = db_get_manifest_setting(); |
| 181 | |
| 182 | if( flg & MFESTFLG_RAW ){ |
| 183 | blob_zero(&manifest); |
| 184 | content_get(vid, &manifest); |
| 185 | sterilize_manifest(&manifest); |
| 186 | zManFile = mprintf("%smanifest", g.zLocalRoot); |
| 187 | blob_write_to_file(&manifest, zManFile); |
| 188 | free(zManFile); |
| 189 | }else{ |
| 190 | if( !db_exists("SELECT 1 FROM vfile WHERE pathname='manifest'") ){ |
| 191 |
| --- src/checkout.c | |
| +++ src/checkout.c | |
| @@ -180,11 +180,11 @@ | |
| 180 | flg = db_get_manifest_setting(); |
| 181 | |
| 182 | if( flg & MFESTFLG_RAW ){ |
| 183 | blob_zero(&manifest); |
| 184 | content_get(vid, &manifest); |
| 185 | sterilize_manifest(&manifest, CFTYPE_MANIFEST); |
| 186 | zManFile = mprintf("%smanifest", g.zLocalRoot); |
| 187 | blob_write_to_file(&manifest, zManFile); |
| 188 | free(zManFile); |
| 189 | }else{ |
| 190 | if( !db_exists("SELECT 1 FROM vfile WHERE pathname='manifest'") ){ |
| 191 |
+3
| --- src/import.c | ||
| +++ src/import.c | ||
| @@ -202,10 +202,13 @@ | ||
| 202 | 202 | ** to the BLOB table. |
| 203 | 203 | */ |
| 204 | 204 | static void finish_blob(void){ |
| 205 | 205 | Blob content; |
| 206 | 206 | blob_init(&content, gg.aData, gg.nData); |
| 207 | + if( manifest_is_well_formed(gg.aData, gg.nData) ){ | |
| 208 | + sterilize_manifest(&content, -1); | |
| 209 | + } | |
| 207 | 210 | fast_insert_content(&content, gg.zMark, 0, 0); |
| 208 | 211 | blob_reset(&content); |
| 209 | 212 | import_reset(0); |
| 210 | 213 | } |
| 211 | 214 | |
| 212 | 215 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -202,10 +202,13 @@ | |
| 202 | ** to the BLOB table. |
| 203 | */ |
| 204 | static void finish_blob(void){ |
| 205 | Blob content; |
| 206 | blob_init(&content, gg.aData, gg.nData); |
| 207 | fast_insert_content(&content, gg.zMark, 0, 0); |
| 208 | blob_reset(&content); |
| 209 | import_reset(0); |
| 210 | } |
| 211 | |
| 212 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -202,10 +202,13 @@ | |
| 202 | ** to the BLOB table. |
| 203 | */ |
| 204 | static void finish_blob(void){ |
| 205 | Blob content; |
| 206 | blob_init(&content, gg.aData, gg.nData); |
| 207 | if( manifest_is_well_formed(gg.aData, gg.nData) ){ |
| 208 | sterilize_manifest(&content, -1); |
| 209 | } |
| 210 | fast_insert_content(&content, gg.zMark, 0, 0); |
| 211 | blob_reset(&content); |
| 212 | import_reset(0); |
| 213 | } |
| 214 | |
| 215 |
+5
-4
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -2138,29 +2138,30 @@ | ||
| 2138 | 2138 | ** |
| 2139 | 2139 | ** Normally it is sufficient to simply append the extra line of text. |
| 2140 | 2140 | ** However, if the manifest is PGP signed then the extra line has to be |
| 2141 | 2141 | ** inserted before the PGP signature (thus invalidating the signature). |
| 2142 | 2142 | */ |
| 2143 | -void sterilize_manifest(Blob *p){ | |
| 2143 | +void sterilize_manifest(Blob *p, int eType){ | |
| 2144 | 2144 | char *z, *zOrig; |
| 2145 | 2145 | int n, nOrig; |
| 2146 | 2146 | static const char zExtraLine[] = |
| 2147 | - "# Remove this line to create a well-formed manifest.\n"; | |
| 2147 | + "# Remove this line to create a well-formed Fossil %s.\n"; | |
| 2148 | + const char *zType = eType==CFTYPE_MANIFEST ? "manifest" : "control artifact"; | |
| 2148 | 2149 | |
| 2149 | 2150 | z = zOrig = blob_materialize(p); |
| 2150 | 2151 | n = nOrig = blob_size(p); |
| 2151 | 2152 | remove_pgp_signature((const char **)&z, &n); |
| 2152 | 2153 | if( z==zOrig ){ |
| 2153 | - blob_append(p, zExtraLine, -1); | |
| 2154 | + blob_appendf(p, zExtraLine/*works-like:"%s"*/, zType); | |
| 2154 | 2155 | }else{ |
| 2155 | 2156 | int iEnd; |
| 2156 | 2157 | Blob copy; |
| 2157 | 2158 | memcpy(©, p, sizeof(copy)); |
| 2158 | 2159 | blob_init(p, 0, 0); |
| 2159 | 2160 | iEnd = (int)(&z[n] - zOrig); |
| 2160 | 2161 | blob_append(p, zOrig, iEnd); |
| 2161 | - blob_append(p, zExtraLine, -1); | |
| 2162 | + blob_appendf(p, zExtraLine/*works-like:"%s"*/, zType); | |
| 2162 | 2163 | blob_append(p, &zOrig[iEnd], -1); |
| 2163 | 2164 | blob_zero(©); |
| 2164 | 2165 | } |
| 2165 | 2166 | } |
| 2166 | 2167 | |
| 2167 | 2168 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -2138,29 +2138,30 @@ | |
| 2138 | ** |
| 2139 | ** Normally it is sufficient to simply append the extra line of text. |
| 2140 | ** However, if the manifest is PGP signed then the extra line has to be |
| 2141 | ** inserted before the PGP signature (thus invalidating the signature). |
| 2142 | */ |
| 2143 | void sterilize_manifest(Blob *p){ |
| 2144 | char *z, *zOrig; |
| 2145 | int n, nOrig; |
| 2146 | static const char zExtraLine[] = |
| 2147 | "# Remove this line to create a well-formed manifest.\n"; |
| 2148 | |
| 2149 | z = zOrig = blob_materialize(p); |
| 2150 | n = nOrig = blob_size(p); |
| 2151 | remove_pgp_signature((const char **)&z, &n); |
| 2152 | if( z==zOrig ){ |
| 2153 | blob_append(p, zExtraLine, -1); |
| 2154 | }else{ |
| 2155 | int iEnd; |
| 2156 | Blob copy; |
| 2157 | memcpy(©, p, sizeof(copy)); |
| 2158 | blob_init(p, 0, 0); |
| 2159 | iEnd = (int)(&z[n] - zOrig); |
| 2160 | blob_append(p, zOrig, iEnd); |
| 2161 | blob_append(p, zExtraLine, -1); |
| 2162 | blob_append(p, &zOrig[iEnd], -1); |
| 2163 | blob_zero(©); |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -2138,29 +2138,30 @@ | |
| 2138 | ** |
| 2139 | ** Normally it is sufficient to simply append the extra line of text. |
| 2140 | ** However, if the manifest is PGP signed then the extra line has to be |
| 2141 | ** inserted before the PGP signature (thus invalidating the signature). |
| 2142 | */ |
| 2143 | void sterilize_manifest(Blob *p, int eType){ |
| 2144 | char *z, *zOrig; |
| 2145 | int n, nOrig; |
| 2146 | static const char zExtraLine[] = |
| 2147 | "# Remove this line to create a well-formed Fossil %s.\n"; |
| 2148 | const char *zType = eType==CFTYPE_MANIFEST ? "manifest" : "control artifact"; |
| 2149 | |
| 2150 | z = zOrig = blob_materialize(p); |
| 2151 | n = nOrig = blob_size(p); |
| 2152 | remove_pgp_signature((const char **)&z, &n); |
| 2153 | if( z==zOrig ){ |
| 2154 | blob_appendf(p, zExtraLine/*works-like:"%s"*/, zType); |
| 2155 | }else{ |
| 2156 | int iEnd; |
| 2157 | Blob copy; |
| 2158 | memcpy(©, p, sizeof(copy)); |
| 2159 | blob_init(p, 0, 0); |
| 2160 | iEnd = (int)(&z[n] - zOrig); |
| 2161 | blob_append(p, zOrig, iEnd); |
| 2162 | blob_appendf(p, zExtraLine/*works-like:"%s"*/, zType); |
| 2163 | blob_append(p, &zOrig[iEnd], -1); |
| 2164 | blob_zero(©); |
| 2165 | } |
| 2166 | } |
| 2167 | |
| 2168 |
+1
-1
| --- src/tar.c | ||
| +++ src/tar.c | ||
| @@ -527,11 +527,11 @@ | ||
| 527 | 527 | if( eflg & MFESTFLG_RAW ){ |
| 528 | 528 | blob_append(&filename, "manifest", -1); |
| 529 | 529 | zName = blob_str(&filename); |
| 530 | 530 | } |
| 531 | 531 | if( eflg & MFESTFLG_RAW ) { |
| 532 | - sterilize_manifest(&mfile); | |
| 532 | + sterilize_manifest(&mfile, CFTYPE_MANIFEST); | |
| 533 | 533 | tar_add_file(zName, &mfile, 0, mTime); |
| 534 | 534 | } |
| 535 | 535 | } |
| 536 | 536 | blob_reset(&mfile); |
| 537 | 537 | if( eflg & MFESTFLG_UUID ){ |
| 538 | 538 |
| --- src/tar.c | |
| +++ src/tar.c | |
| @@ -527,11 +527,11 @@ | |
| 527 | if( eflg & MFESTFLG_RAW ){ |
| 528 | blob_append(&filename, "manifest", -1); |
| 529 | zName = blob_str(&filename); |
| 530 | } |
| 531 | if( eflg & MFESTFLG_RAW ) { |
| 532 | sterilize_manifest(&mfile); |
| 533 | tar_add_file(zName, &mfile, 0, mTime); |
| 534 | } |
| 535 | } |
| 536 | blob_reset(&mfile); |
| 537 | if( eflg & MFESTFLG_UUID ){ |
| 538 |
| --- src/tar.c | |
| +++ src/tar.c | |
| @@ -527,11 +527,11 @@ | |
| 527 | if( eflg & MFESTFLG_RAW ){ |
| 528 | blob_append(&filename, "manifest", -1); |
| 529 | zName = blob_str(&filename); |
| 530 | } |
| 531 | if( eflg & MFESTFLG_RAW ) { |
| 532 | sterilize_manifest(&mfile, CFTYPE_MANIFEST); |
| 533 | tar_add_file(zName, &mfile, 0, mTime); |
| 534 | } |
| 535 | } |
| 536 | blob_reset(&mfile); |
| 537 | if( eflg & MFESTFLG_UUID ){ |
| 538 |
+1
-1
| --- src/zip.c | ||
| +++ src/zip.c | ||
| @@ -679,11 +679,11 @@ | ||
| 679 | 679 | |
| 680 | 680 | if( eflg & MFESTFLG_RAW ){ |
| 681 | 681 | blob_append(&filename, "manifest", -1); |
| 682 | 682 | zName = blob_str(&filename); |
| 683 | 683 | zip_add_folders(&sArchive, zName); |
| 684 | - sterilize_manifest(&mfile); | |
| 684 | + sterilize_manifest(&mfile, CFTYPE_MANIFEST); | |
| 685 | 685 | zip_add_file(&sArchive, zName, &mfile, 0); |
| 686 | 686 | } |
| 687 | 687 | if( eflg & MFESTFLG_UUID ){ |
| 688 | 688 | blob_append(&hash, "\n", 1); |
| 689 | 689 | blob_resize(&filename, nPrefix); |
| 690 | 690 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -679,11 +679,11 @@ | |
| 679 | |
| 680 | if( eflg & MFESTFLG_RAW ){ |
| 681 | blob_append(&filename, "manifest", -1); |
| 682 | zName = blob_str(&filename); |
| 683 | zip_add_folders(&sArchive, zName); |
| 684 | sterilize_manifest(&mfile); |
| 685 | zip_add_file(&sArchive, zName, &mfile, 0); |
| 686 | } |
| 687 | if( eflg & MFESTFLG_UUID ){ |
| 688 | blob_append(&hash, "\n", 1); |
| 689 | blob_resize(&filename, nPrefix); |
| 690 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -679,11 +679,11 @@ | |
| 679 | |
| 680 | if( eflg & MFESTFLG_RAW ){ |
| 681 | blob_append(&filename, "manifest", -1); |
| 682 | zName = blob_str(&filename); |
| 683 | zip_add_folders(&sArchive, zName); |
| 684 | sterilize_manifest(&mfile, CFTYPE_MANIFEST); |
| 685 | zip_add_file(&sArchive, zName, &mfile, 0); |
| 686 | } |
| 687 | if( eflg & MFESTFLG_UUID ){ |
| 688 | blob_append(&hash, "\n", 1); |
| 689 | blob_resize(&filename, nPrefix); |
| 690 |