Fossil SCM
Make "fossil purge undo" put each artifact back under its original record number when that number is free, and leave in place the parent links that kept check-ins hold to a purged one, so that the file and parent links of other artifacts are whole again after an undo.
Commit
436b00c00be3d0aac52a7ab70fdefac218f327ecf6ff6f9d0adb8b577dc418b9
Parent
2aee44af8e2b7fe…
1 file changed
+21
-5
+21
-5
| --- src/purge.c | ||
| +++ src/purge.c | ||
| @@ -78,12 +78,12 @@ | ||
| 78 | 78 | ** (4) Create new purgeitem entries for each purged artifact |
| 79 | 79 | ** (5) Remove purged artifacts from the BLOB table |
| 80 | 80 | ** (6) Remove references to purged artifacts in the following tables: |
| 81 | 81 | ** (a) EVENT |
| 82 | 82 | ** (b) PRIVATE |
| 83 | -** (c) MLINK | |
| 84 | -** (d) PLINK | |
| 83 | +** (c) MLINK, the file links that purged check-ins hold | |
| 84 | +** (d) PLINK, the parent links that purged check-ins hold | |
| 85 | 85 | ** (e) LEAF |
| 86 | 86 | ** (f) UNCLUSTERED |
| 87 | 87 | ** (g) UNSENT |
| 88 | 88 | ** (h) BACKLINK |
| 89 | 89 | ** (i) ATTACHMENT |
| @@ -181,11 +181,10 @@ | ||
| 181 | 181 | db_multi_exec("DELETE FROM delta WHERE rid IN \"%w\"", zTab); |
| 182 | 182 | db_multi_exec("DELETE FROM delta WHERE srcid IN \"%w\"", zTab); |
| 183 | 183 | db_multi_exec("DELETE FROM event WHERE objid IN \"%w\"", zTab); |
| 184 | 184 | db_multi_exec("DELETE FROM private WHERE rid IN \"%w\"", zTab); |
| 185 | 185 | db_multi_exec("DELETE FROM mlink WHERE mid IN \"%w\"", zTab); |
| 186 | - db_multi_exec("DELETE FROM plink WHERE pid IN \"%w\"", zTab); | |
| 187 | 186 | db_multi_exec("DELETE FROM plink WHERE cid IN \"%w\"", zTab); |
| 188 | 187 | db_multi_exec("DELETE FROM leaf WHERE rid IN \"%w\"", zTab); |
| 189 | 188 | db_multi_exec("DELETE FROM phantom WHERE rid IN \"%w\"", zTab); |
| 190 | 189 | db_multi_exec("DELETE FROM unclustered WHERE rid IN \"%w\"", zTab); |
| 191 | 190 | db_multi_exec("DELETE FROM unsent WHERE rid IN \"%w\"", zTab); |
| @@ -401,19 +400,19 @@ | ||
| 401 | 400 | fossil_fatal("delta loop while uncompressing purged artifacts"); |
| 402 | 401 | } |
| 403 | 402 | bag_insert(&busy, iSrc); |
| 404 | 403 | } |
| 405 | 404 | db_prepare(&q, |
| 406 | - "SELECT uuid, data, isPrivate, ix.piid" | |
| 405 | + "SELECT uuid, data, isPrivate, ix.piid, orid" | |
| 407 | 406 | " FROM ix, purgeitem" |
| 408 | 407 | " WHERE ix.srcid=%d" |
| 409 | 408 | " AND ix.piid=purgeitem.piid;", |
| 410 | 409 | iSrc |
| 411 | 410 | ); |
| 412 | 411 | while( db_step(&q)==SQLITE_ROW ){ |
| 413 | 412 | Blob h1, c1, c2; |
| 414 | - int isPriv, rid; | |
| 413 | + int isPriv, rid, orid; | |
| 415 | 414 | blob_zero(&h1); |
| 416 | 415 | db_column_blob(&q, 0, &h1); |
| 417 | 416 | blob_zero(&c1); |
| 418 | 417 | db_column_blob(&q, 1, &c1); |
| 419 | 418 | blob_uncompress(&c1, &c1); |
| @@ -426,10 +425,27 @@ | ||
| 426 | 425 | } |
| 427 | 426 | if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){ |
| 428 | 427 | fossil_fatal("incorrect hash on %b", &h1); |
| 429 | 428 | } |
| 430 | 429 | isPriv = db_column_int(&q, 2); |
| 430 | + orid = db_column_int(&q, 4); | |
| 431 | + if( orid>0 | |
| 432 | + && !db_exists("SELECT 1 FROM blob WHERE rid=%d OR uuid=%Q", | |
| 433 | + orid, blob_str(&h1)) | |
| 434 | + ){ | |
| 435 | + /* Store the artifact under its original record number, so that the | |
| 436 | + ** links that other artifacts still hold to it are whole again. */ | |
| 437 | + db_multi_exec( | |
| 438 | + "INSERT INTO blob(rid,rcvid,size,uuid,content)" | |
| 439 | + " VALUES(%d,0,-1,%Q,NULL);" | |
| 440 | + "INSERT INTO phantom VALUES(%d);", | |
| 441 | + orid, blob_str(&h1), orid | |
| 442 | + ); | |
| 443 | + if( !isPriv ){ | |
| 444 | + db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d)", orid); | |
| 445 | + } | |
| 446 | + } | |
| 431 | 447 | rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv); |
| 432 | 448 | if( rid==0 ){ |
| 433 | 449 | fossil_fatal("%s", g.zErrMsg); |
| 434 | 450 | }else{ |
| 435 | 451 | if( !isPriv ) content_make_public(rid); |
| 436 | 452 |
| --- src/purge.c | |
| +++ src/purge.c | |
| @@ -78,12 +78,12 @@ | |
| 78 | ** (4) Create new purgeitem entries for each purged artifact |
| 79 | ** (5) Remove purged artifacts from the BLOB table |
| 80 | ** (6) Remove references to purged artifacts in the following tables: |
| 81 | ** (a) EVENT |
| 82 | ** (b) PRIVATE |
| 83 | ** (c) MLINK |
| 84 | ** (d) PLINK |
| 85 | ** (e) LEAF |
| 86 | ** (f) UNCLUSTERED |
| 87 | ** (g) UNSENT |
| 88 | ** (h) BACKLINK |
| 89 | ** (i) ATTACHMENT |
| @@ -181,11 +181,10 @@ | |
| 181 | db_multi_exec("DELETE FROM delta WHERE rid IN \"%w\"", zTab); |
| 182 | db_multi_exec("DELETE FROM delta WHERE srcid IN \"%w\"", zTab); |
| 183 | db_multi_exec("DELETE FROM event WHERE objid IN \"%w\"", zTab); |
| 184 | db_multi_exec("DELETE FROM private WHERE rid IN \"%w\"", zTab); |
| 185 | db_multi_exec("DELETE FROM mlink WHERE mid IN \"%w\"", zTab); |
| 186 | db_multi_exec("DELETE FROM plink WHERE pid IN \"%w\"", zTab); |
| 187 | db_multi_exec("DELETE FROM plink WHERE cid IN \"%w\"", zTab); |
| 188 | db_multi_exec("DELETE FROM leaf WHERE rid IN \"%w\"", zTab); |
| 189 | db_multi_exec("DELETE FROM phantom WHERE rid IN \"%w\"", zTab); |
| 190 | db_multi_exec("DELETE FROM unclustered WHERE rid IN \"%w\"", zTab); |
| 191 | db_multi_exec("DELETE FROM unsent WHERE rid IN \"%w\"", zTab); |
| @@ -401,19 +400,19 @@ | |
| 401 | fossil_fatal("delta loop while uncompressing purged artifacts"); |
| 402 | } |
| 403 | bag_insert(&busy, iSrc); |
| 404 | } |
| 405 | db_prepare(&q, |
| 406 | "SELECT uuid, data, isPrivate, ix.piid" |
| 407 | " FROM ix, purgeitem" |
| 408 | " WHERE ix.srcid=%d" |
| 409 | " AND ix.piid=purgeitem.piid;", |
| 410 | iSrc |
| 411 | ); |
| 412 | while( db_step(&q)==SQLITE_ROW ){ |
| 413 | Blob h1, c1, c2; |
| 414 | int isPriv, rid; |
| 415 | blob_zero(&h1); |
| 416 | db_column_blob(&q, 0, &h1); |
| 417 | blob_zero(&c1); |
| 418 | db_column_blob(&q, 1, &c1); |
| 419 | blob_uncompress(&c1, &c1); |
| @@ -426,10 +425,27 @@ | |
| 426 | } |
| 427 | if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){ |
| 428 | fossil_fatal("incorrect hash on %b", &h1); |
| 429 | } |
| 430 | isPriv = db_column_int(&q, 2); |
| 431 | rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv); |
| 432 | if( rid==0 ){ |
| 433 | fossil_fatal("%s", g.zErrMsg); |
| 434 | }else{ |
| 435 | if( !isPriv ) content_make_public(rid); |
| 436 |
| --- src/purge.c | |
| +++ src/purge.c | |
| @@ -78,12 +78,12 @@ | |
| 78 | ** (4) Create new purgeitem entries for each purged artifact |
| 79 | ** (5) Remove purged artifacts from the BLOB table |
| 80 | ** (6) Remove references to purged artifacts in the following tables: |
| 81 | ** (a) EVENT |
| 82 | ** (b) PRIVATE |
| 83 | ** (c) MLINK, the file links that purged check-ins hold |
| 84 | ** (d) PLINK, the parent links that purged check-ins hold |
| 85 | ** (e) LEAF |
| 86 | ** (f) UNCLUSTERED |
| 87 | ** (g) UNSENT |
| 88 | ** (h) BACKLINK |
| 89 | ** (i) ATTACHMENT |
| @@ -181,11 +181,10 @@ | |
| 181 | db_multi_exec("DELETE FROM delta WHERE rid IN \"%w\"", zTab); |
| 182 | db_multi_exec("DELETE FROM delta WHERE srcid IN \"%w\"", zTab); |
| 183 | db_multi_exec("DELETE FROM event WHERE objid IN \"%w\"", zTab); |
| 184 | db_multi_exec("DELETE FROM private WHERE rid IN \"%w\"", zTab); |
| 185 | db_multi_exec("DELETE FROM mlink WHERE mid IN \"%w\"", zTab); |
| 186 | db_multi_exec("DELETE FROM plink WHERE cid IN \"%w\"", zTab); |
| 187 | db_multi_exec("DELETE FROM leaf WHERE rid IN \"%w\"", zTab); |
| 188 | db_multi_exec("DELETE FROM phantom WHERE rid IN \"%w\"", zTab); |
| 189 | db_multi_exec("DELETE FROM unclustered WHERE rid IN \"%w\"", zTab); |
| 190 | db_multi_exec("DELETE FROM unsent WHERE rid IN \"%w\"", zTab); |
| @@ -401,19 +400,19 @@ | |
| 400 | fossil_fatal("delta loop while uncompressing purged artifacts"); |
| 401 | } |
| 402 | bag_insert(&busy, iSrc); |
| 403 | } |
| 404 | db_prepare(&q, |
| 405 | "SELECT uuid, data, isPrivate, ix.piid, orid" |
| 406 | " FROM ix, purgeitem" |
| 407 | " WHERE ix.srcid=%d" |
| 408 | " AND ix.piid=purgeitem.piid;", |
| 409 | iSrc |
| 410 | ); |
| 411 | while( db_step(&q)==SQLITE_ROW ){ |
| 412 | Blob h1, c1, c2; |
| 413 | int isPriv, rid, orid; |
| 414 | blob_zero(&h1); |
| 415 | db_column_blob(&q, 0, &h1); |
| 416 | blob_zero(&c1); |
| 417 | db_column_blob(&q, 1, &c1); |
| 418 | blob_uncompress(&c1, &c1); |
| @@ -426,10 +425,27 @@ | |
| 425 | } |
| 426 | if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){ |
| 427 | fossil_fatal("incorrect hash on %b", &h1); |
| 428 | } |
| 429 | isPriv = db_column_int(&q, 2); |
| 430 | orid = db_column_int(&q, 4); |
| 431 | if( orid>0 |
| 432 | && !db_exists("SELECT 1 FROM blob WHERE rid=%d OR uuid=%Q", |
| 433 | orid, blob_str(&h1)) |
| 434 | ){ |
| 435 | /* Store the artifact under its original record number, so that the |
| 436 | ** links that other artifacts still hold to it are whole again. */ |
| 437 | db_multi_exec( |
| 438 | "INSERT INTO blob(rid,rcvid,size,uuid,content)" |
| 439 | " VALUES(%d,0,-1,%Q,NULL);" |
| 440 | "INSERT INTO phantom VALUES(%d);", |
| 441 | orid, blob_str(&h1), orid |
| 442 | ); |
| 443 | if( !isPriv ){ |
| 444 | db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d)", orid); |
| 445 | } |
| 446 | } |
| 447 | rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv); |
| 448 | if( rid==0 ){ |
| 449 | fossil_fatal("%s", g.zErrMsg); |
| 450 | }else{ |
| 451 | if( !isPriv ) content_make_public(rid); |
| 452 |