Fossil SCM
Add the --randomize parameter to the rebuild command. Used for testing.
Commit
ce1c1a2907e9aa10c0426a1a9bb148e43242ae89
Parent
2bc0e2c565c93f7…
2 files changed
+1
-1
+13
-4
+1
-1
| --- src/construct.c | ||
| +++ src/construct.c | ||
| @@ -154,11 +154,11 @@ | ||
| 154 | 154 | |
| 155 | 155 | printf("imported: %d %s\n", fileCnt, fileCnt == 1 ? |
| 156 | 156 | "file" : "files"); |
| 157 | 157 | |
| 158 | 158 | /* Finalize the repository, rebuild the derived tables */ |
| 159 | - errCnt = rebuild_db (); | |
| 159 | + errCnt = rebuild_db(0); | |
| 160 | 160 | |
| 161 | 161 | if( errCnt ){ |
| 162 | 162 | printf("%d %s. Rolling back changes.\n", errCnt, errCnt == 1 ? |
| 163 | 163 | "error" : "errors"); |
| 164 | 164 | db_end_transaction(1); |
| 165 | 165 |
| --- src/construct.c | |
| +++ src/construct.c | |
| @@ -154,11 +154,11 @@ | |
| 154 | |
| 155 | printf("imported: %d %s\n", fileCnt, fileCnt == 1 ? |
| 156 | "file" : "files"); |
| 157 | |
| 158 | /* Finalize the repository, rebuild the derived tables */ |
| 159 | errCnt = rebuild_db (); |
| 160 | |
| 161 | if( errCnt ){ |
| 162 | printf("%d %s. Rolling back changes.\n", errCnt, errCnt == 1 ? |
| 163 | "error" : "errors"); |
| 164 | db_end_transaction(1); |
| 165 |
| --- src/construct.c | |
| +++ src/construct.c | |
| @@ -154,11 +154,11 @@ | |
| 154 | |
| 155 | printf("imported: %d %s\n", fileCnt, fileCnt == 1 ? |
| 156 | "file" : "files"); |
| 157 | |
| 158 | /* Finalize the repository, rebuild the derived tables */ |
| 159 | errCnt = rebuild_db(0); |
| 160 | |
| 161 | if( errCnt ){ |
| 162 | printf("%d %s. Rolling back changes.\n", errCnt, errCnt == 1 ? |
| 163 | "error" : "errors"); |
| 164 | db_end_transaction(1); |
| 165 |
+13
-4
| --- src/rebuild.c | ||
| +++ src/rebuild.c | ||
| @@ -31,13 +31,17 @@ | ||
| 31 | 31 | ** Core function to rebuild the infomration in the derived tables of a |
| 32 | 32 | ** fossil repository from the blobs. This function is shared between |
| 33 | 33 | ** 'rebuild_database' ('rebuild') and 'reconstruct_cmd' |
| 34 | 34 | ** ('reconstruct'), both of which have to regenerate this information |
| 35 | 35 | ** from scratch. |
| 36 | +** | |
| 37 | +** If the randomize parameter is true, then the BLOBs are deliberately | |
| 38 | +** extracted in a random order. This feature is used to test the | |
| 39 | +** ability of fossil to accept records in any order and still | |
| 40 | +** construct a sane repository. | |
| 36 | 41 | */ |
| 37 | - | |
| 38 | -int rebuild_db(void){ | |
| 42 | +int rebuild_db(int randomize){ | |
| 39 | 43 | Stmt s; |
| 40 | 44 | int errCnt = 0; |
| 41 | 45 | char *zTable; |
| 42 | 46 | |
| 43 | 47 | db_multi_exec( |
| @@ -56,11 +60,14 @@ | ||
| 56 | 60 | |
| 57 | 61 | db_multi_exec("INSERT INTO unclustered SELECT rid FROM blob"); |
| 58 | 62 | db_multi_exec( |
| 59 | 63 | "DELETE FROM config WHERE name IN ('remote-code', 'remote-maxid')" |
| 60 | 64 | ); |
| 61 | - db_prepare(&s, "SELECT rid, size FROM blob"); | |
| 65 | + db_prepare(&s, | |
| 66 | + "SELECT rid, size FROM blob %s", | |
| 67 | + randomize ? "ORDER BY random()" : "" | |
| 68 | + ); | |
| 62 | 69 | while( db_step(&s)==SQLITE_ROW ){ |
| 63 | 70 | int rid = db_column_int(&s, 0); |
| 64 | 71 | int size = db_column_int(&s, 1); |
| 65 | 72 | if( size>=0 ){ |
| 66 | 73 | Blob content; |
| @@ -83,22 +90,24 @@ | ||
| 83 | 90 | ** records. Run this command after updating the fossil |
| 84 | 91 | ** executable in a way that changes the database schema. |
| 85 | 92 | */ |
| 86 | 93 | void rebuild_database(void){ |
| 87 | 94 | int forceFlag; |
| 95 | + int randomizeFlag; | |
| 88 | 96 | int errCnt; |
| 89 | 97 | |
| 90 | 98 | forceFlag = find_option("force","f",0)!=0; |
| 99 | + randomizeFlag = find_option("randomize", 0, 0)!=0; | |
| 91 | 100 | if( g.argc!=3 ){ |
| 92 | 101 | usage("REPOSITORY-FILENAME"); |
| 93 | 102 | } |
| 94 | 103 | db_open_repository(g.argv[2]); |
| 95 | 104 | db_begin_transaction(); |
| 96 | - errCnt = rebuild_db(); | |
| 105 | + errCnt = rebuild_db(randomizeFlag); | |
| 97 | 106 | if( errCnt && !forceFlag ){ |
| 98 | 107 | printf("%d errors. Rolling back changes. Use --force to force a commit.\n", |
| 99 | 108 | errCnt); |
| 100 | 109 | db_end_transaction(1); |
| 101 | 110 | }else{ |
| 102 | 111 | db_end_transaction(0); |
| 103 | 112 | } |
| 104 | 113 | } |
| 105 | 114 |
| --- src/rebuild.c | |
| +++ src/rebuild.c | |
| @@ -31,13 +31,17 @@ | |
| 31 | ** Core function to rebuild the infomration in the derived tables of a |
| 32 | ** fossil repository from the blobs. This function is shared between |
| 33 | ** 'rebuild_database' ('rebuild') and 'reconstruct_cmd' |
| 34 | ** ('reconstruct'), both of which have to regenerate this information |
| 35 | ** from scratch. |
| 36 | */ |
| 37 | |
| 38 | int rebuild_db(void){ |
| 39 | Stmt s; |
| 40 | int errCnt = 0; |
| 41 | char *zTable; |
| 42 | |
| 43 | db_multi_exec( |
| @@ -56,11 +60,14 @@ | |
| 56 | |
| 57 | db_multi_exec("INSERT INTO unclustered SELECT rid FROM blob"); |
| 58 | db_multi_exec( |
| 59 | "DELETE FROM config WHERE name IN ('remote-code', 'remote-maxid')" |
| 60 | ); |
| 61 | db_prepare(&s, "SELECT rid, size FROM blob"); |
| 62 | while( db_step(&s)==SQLITE_ROW ){ |
| 63 | int rid = db_column_int(&s, 0); |
| 64 | int size = db_column_int(&s, 1); |
| 65 | if( size>=0 ){ |
| 66 | Blob content; |
| @@ -83,22 +90,24 @@ | |
| 83 | ** records. Run this command after updating the fossil |
| 84 | ** executable in a way that changes the database schema. |
| 85 | */ |
| 86 | void rebuild_database(void){ |
| 87 | int forceFlag; |
| 88 | int errCnt; |
| 89 | |
| 90 | forceFlag = find_option("force","f",0)!=0; |
| 91 | if( g.argc!=3 ){ |
| 92 | usage("REPOSITORY-FILENAME"); |
| 93 | } |
| 94 | db_open_repository(g.argv[2]); |
| 95 | db_begin_transaction(); |
| 96 | errCnt = rebuild_db(); |
| 97 | if( errCnt && !forceFlag ){ |
| 98 | printf("%d errors. Rolling back changes. Use --force to force a commit.\n", |
| 99 | errCnt); |
| 100 | db_end_transaction(1); |
| 101 | }else{ |
| 102 | db_end_transaction(0); |
| 103 | } |
| 104 | } |
| 105 |
| --- src/rebuild.c | |
| +++ src/rebuild.c | |
| @@ -31,13 +31,17 @@ | |
| 31 | ** Core function to rebuild the infomration in the derived tables of a |
| 32 | ** fossil repository from the blobs. This function is shared between |
| 33 | ** 'rebuild_database' ('rebuild') and 'reconstruct_cmd' |
| 34 | ** ('reconstruct'), both of which have to regenerate this information |
| 35 | ** from scratch. |
| 36 | ** |
| 37 | ** If the randomize parameter is true, then the BLOBs are deliberately |
| 38 | ** extracted in a random order. This feature is used to test the |
| 39 | ** ability of fossil to accept records in any order and still |
| 40 | ** construct a sane repository. |
| 41 | */ |
| 42 | int rebuild_db(int randomize){ |
| 43 | Stmt s; |
| 44 | int errCnt = 0; |
| 45 | char *zTable; |
| 46 | |
| 47 | db_multi_exec( |
| @@ -56,11 +60,14 @@ | |
| 60 | |
| 61 | db_multi_exec("INSERT INTO unclustered SELECT rid FROM blob"); |
| 62 | db_multi_exec( |
| 63 | "DELETE FROM config WHERE name IN ('remote-code', 'remote-maxid')" |
| 64 | ); |
| 65 | db_prepare(&s, |
| 66 | "SELECT rid, size FROM blob %s", |
| 67 | randomize ? "ORDER BY random()" : "" |
| 68 | ); |
| 69 | while( db_step(&s)==SQLITE_ROW ){ |
| 70 | int rid = db_column_int(&s, 0); |
| 71 | int size = db_column_int(&s, 1); |
| 72 | if( size>=0 ){ |
| 73 | Blob content; |
| @@ -83,22 +90,24 @@ | |
| 90 | ** records. Run this command after updating the fossil |
| 91 | ** executable in a way that changes the database schema. |
| 92 | */ |
| 93 | void rebuild_database(void){ |
| 94 | int forceFlag; |
| 95 | int randomizeFlag; |
| 96 | int errCnt; |
| 97 | |
| 98 | forceFlag = find_option("force","f",0)!=0; |
| 99 | randomizeFlag = find_option("randomize", 0, 0)!=0; |
| 100 | if( g.argc!=3 ){ |
| 101 | usage("REPOSITORY-FILENAME"); |
| 102 | } |
| 103 | db_open_repository(g.argv[2]); |
| 104 | db_begin_transaction(); |
| 105 | errCnt = rebuild_db(randomizeFlag); |
| 106 | if( errCnt && !forceFlag ){ |
| 107 | printf("%d errors. Rolling back changes. Use --force to force a commit.\n", |
| 108 | errCnt); |
| 109 | db_end_transaction(1); |
| 110 | }else{ |
| 111 | db_end_transaction(0); |
| 112 | } |
| 113 | } |
| 114 |