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.

drh 2020-09-11 15:40 trunk
Commit 2777682b632030db27990aa8b1f7ede64c0b6f17faabc84c45283218771be70f
+1 -1
--- src/checkout.c
+++ src/checkout.c
@@ -180,11 +180,11 @@
180180
flg = db_get_manifest_setting();
181181
182182
if( flg & MFESTFLG_RAW ){
183183
blob_zero(&manifest);
184184
content_get(vid, &manifest);
185
- sterilize_manifest(&manifest);
185
+ sterilize_manifest(&manifest, CFTYPE_MANIFEST);
186186
zManFile = mprintf("%smanifest", g.zLocalRoot);
187187
blob_write_to_file(&manifest, zManFile);
188188
free(zManFile);
189189
}else{
190190
if( !db_exists("SELECT 1 FROM vfile WHERE pathname='manifest'") ){
191191
--- 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
--- src/import.c
+++ src/import.c
@@ -202,10 +202,13 @@
202202
** to the BLOB table.
203203
*/
204204
static void finish_blob(void){
205205
Blob content;
206206
blob_init(&content, gg.aData, gg.nData);
207
+ if( manifest_is_well_formed(gg.aData, gg.nData) ){
208
+ sterilize_manifest(&content, -1);
209
+ }
207210
fast_insert_content(&content, gg.zMark, 0, 0);
208211
blob_reset(&content);
209212
import_reset(0);
210213
}
211214
212215
--- 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 @@
21382138
**
21392139
** Normally it is sufficient to simply append the extra line of text.
21402140
** However, if the manifest is PGP signed then the extra line has to be
21412141
** inserted before the PGP signature (thus invalidating the signature).
21422142
*/
2143
-void sterilize_manifest(Blob *p){
2143
+void sterilize_manifest(Blob *p, int eType){
21442144
char *z, *zOrig;
21452145
int n, nOrig;
21462146
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";
21482149
21492150
z = zOrig = blob_materialize(p);
21502151
n = nOrig = blob_size(p);
21512152
remove_pgp_signature((const char **)&z, &n);
21522153
if( z==zOrig ){
2153
- blob_append(p, zExtraLine, -1);
2154
+ blob_appendf(p, zExtraLine/*works-like:"%s"*/, zType);
21542155
}else{
21552156
int iEnd;
21562157
Blob copy;
21572158
memcpy(&copy, p, sizeof(copy));
21582159
blob_init(p, 0, 0);
21592160
iEnd = (int)(&z[n] - zOrig);
21602161
blob_append(p, zOrig, iEnd);
2161
- blob_append(p, zExtraLine, -1);
2162
+ blob_appendf(p, zExtraLine/*works-like:"%s"*/, zType);
21622163
blob_append(p, &zOrig[iEnd], -1);
21632164
blob_zero(&copy);
21642165
}
21652166
}
21662167
21672168
--- 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(&copy, 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(&copy);
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(&copy, 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(&copy);
2165 }
2166 }
2167
2168
+1 -1
--- src/tar.c
+++ src/tar.c
@@ -527,11 +527,11 @@
527527
if( eflg & MFESTFLG_RAW ){
528528
blob_append(&filename, "manifest", -1);
529529
zName = blob_str(&filename);
530530
}
531531
if( eflg & MFESTFLG_RAW ) {
532
- sterilize_manifest(&mfile);
532
+ sterilize_manifest(&mfile, CFTYPE_MANIFEST);
533533
tar_add_file(zName, &mfile, 0, mTime);
534534
}
535535
}
536536
blob_reset(&mfile);
537537
if( eflg & MFESTFLG_UUID ){
538538
--- 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 @@
679679
680680
if( eflg & MFESTFLG_RAW ){
681681
blob_append(&filename, "manifest", -1);
682682
zName = blob_str(&filename);
683683
zip_add_folders(&sArchive, zName);
684
- sterilize_manifest(&mfile);
684
+ sterilize_manifest(&mfile, CFTYPE_MANIFEST);
685685
zip_add_file(&sArchive, zName, &mfile, 0);
686686
}
687687
if( eflg & MFESTFLG_UUID ){
688688
blob_append(&hash, "\n", 1);
689689
blob_resize(&filename, nPrefix);
690690
--- 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

Keyboard Shortcuts

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