Fossil SCM

Make "fossil test-integrity" and "fossil test-missing" exit with status 1 when they report an error, so that scripts can rely on them. With --parse, an artifact recorded as a check-in, wiki page, ticket, cluster or the like that fails to parse is an error.

dmestas 2026-11-12 04:04 UTC small-fixes
Commit ee8a2237f3ff041bb7f69d73063d7344dbdf5c02d3c99228fa8f903281a85170
1 file changed +16 -3
+16 -3
--- src/content.c
+++ src/content.c
@@ -989,10 +989,12 @@
989989
**
990990
** Verify that all content can be extracted from the BLOB table correctly.
991991
** If the BLOB table is correct, then the repository can always be
992992
** successfully reconstructed using "fossil rebuild".
993993
**
994
+** The exit status is 1 if any error is found.
995
+**
994996
** Options:
995997
** -d|--db-only Run "PRAGMA integrity_check" on the database only.
996998
** No other validation is performed.
997999
** --parse Parse all manifests, wikis, tickets, events, and
9981000
** so forth, reporting any errors found.
@@ -1010,14 +1012,14 @@
10101012
int nPhantom = 0;
10111013
int anCA[10];
10121014
int bParse = find_option("parse",0,0)!=0;
10131015
int bDbOnly = find_option("db-only","d",0)!=0;
10141016
int bQuick = find_option("quick",0,0)!=0;
1017
+ char *zRes;
10151018
db_find_and_open_repository(OPEN_ANY_SCHEMA, 2);
10161019
if( bDbOnly || bQuick ){
10171020
const char *zType = bQuick ? "quick" : "integrity";
1018
- char *zRes;
10191021
zRes = db_text(0,"PRAGMA repository.%s_check", zType/*safe-for-%s*/);
10201022
if( fossil_strcmp(zRes,"ok")!=0 ){
10211023
fossil_print("%s_check failed!\n", zType);
10221024
exit(1);
10231025
}else{
@@ -1089,10 +1091,17 @@
10891091
zFirstLine[i] = 0;
10901092
p = manifest_parse(&content, 0, &err);
10911093
if( p==0 ){
10921094
fossil_print("manifest_parse failed for %s:\n%s\n",
10931095
zUuid, blob_str(&err));
1096
+ /* An ordinary file can look like a control artifact and fail to
1097
+ ** parse. That is an error only if the repository has it down
1098
+ ** as a check-in, wiki page, ticket or the like, or as a cluster. */
1099
+ if( db_exists("SELECT 1 FROM event WHERE objid=%d"
1100
+ " UNION ALL"
1101
+ " SELECT 1 FROM tagxref WHERE rid=%d AND tagid=%d",
1102
+ rid, rid, TAG_CLUSTER) ) nErr++;
10941103
if( strncmp(blob_str(&err), "line 1:", 7)==0 ){
10951104
fossil_print("\"%s\"\n", zFirstLine);
10961105
}
10971106
}else{
10981107
anCA[p->type]++;
@@ -1120,11 +1129,14 @@
11201129
for(i=1; i<count(azType); i++){
11211130
if( anCA[i] ) fossil_print(" %d %ss\n", anCA[i], azType[i]);
11221131
}
11231132
}
11241133
fossil_print("low-level database integrity-check: ");
1125
- fossil_print("%s\n", db_text(0, "PRAGMA integrity_check(10)"));
1134
+ zRes = db_text(0, "PRAGMA repository.integrity_check(10)");
1135
+ fossil_print("%s\n", zRes);
1136
+ if( fossil_strcmp(zRes,"ok")!=0 ) nErr++;
1137
+ if( nErr ) fossil_exit(1);
11261138
}
11271139
11281140
/*
11291141
** COMMAND: test-orphans
11301142
**
@@ -1231,11 +1243,11 @@
12311243
**
12321244
** Usage: %fossil test-missing
12331245
**
12341246
** Look at every artifact in the repository and verify that
12351247
** all references are satisfied. Report any referenced artifacts
1236
-** that are missing or shunned.
1248
+** that are missing or shunned. The exit status is 1 if any are found.
12371249
**
12381250
** Options:
12391251
** --notshunned Do not report shunned artifacts
12401252
** -q|--quiet Only show output if there are errors
12411253
*/
@@ -1291,10 +1303,11 @@
12911303
db_finalize(&q);
12921304
if( nErr>0 || quietFlag==0 ){
12931305
fossil_print("%d missing or shunned references in %d control artifacts\n",
12941306
nErr, nArtifact);
12951307
}
1308
+ if( nErr ) fossil_exit(1);
12961309
}
12971310
12981311
/*
12991312
** COMMAND: test-content-erase
13001313
**
13011314
--- src/content.c
+++ src/content.c
@@ -989,10 +989,12 @@
989 **
990 ** Verify that all content can be extracted from the BLOB table correctly.
991 ** If the BLOB table is correct, then the repository can always be
992 ** successfully reconstructed using "fossil rebuild".
993 **
 
 
994 ** Options:
995 ** -d|--db-only Run "PRAGMA integrity_check" on the database only.
996 ** No other validation is performed.
997 ** --parse Parse all manifests, wikis, tickets, events, and
998 ** so forth, reporting any errors found.
@@ -1010,14 +1012,14 @@
1010 int nPhantom = 0;
1011 int anCA[10];
1012 int bParse = find_option("parse",0,0)!=0;
1013 int bDbOnly = find_option("db-only","d",0)!=0;
1014 int bQuick = find_option("quick",0,0)!=0;
 
1015 db_find_and_open_repository(OPEN_ANY_SCHEMA, 2);
1016 if( bDbOnly || bQuick ){
1017 const char *zType = bQuick ? "quick" : "integrity";
1018 char *zRes;
1019 zRes = db_text(0,"PRAGMA repository.%s_check", zType/*safe-for-%s*/);
1020 if( fossil_strcmp(zRes,"ok")!=0 ){
1021 fossil_print("%s_check failed!\n", zType);
1022 exit(1);
1023 }else{
@@ -1089,10 +1091,17 @@
1089 zFirstLine[i] = 0;
1090 p = manifest_parse(&content, 0, &err);
1091 if( p==0 ){
1092 fossil_print("manifest_parse failed for %s:\n%s\n",
1093 zUuid, blob_str(&err));
 
 
 
 
 
 
 
1094 if( strncmp(blob_str(&err), "line 1:", 7)==0 ){
1095 fossil_print("\"%s\"\n", zFirstLine);
1096 }
1097 }else{
1098 anCA[p->type]++;
@@ -1120,11 +1129,14 @@
1120 for(i=1; i<count(azType); i++){
1121 if( anCA[i] ) fossil_print(" %d %ss\n", anCA[i], azType[i]);
1122 }
1123 }
1124 fossil_print("low-level database integrity-check: ");
1125 fossil_print("%s\n", db_text(0, "PRAGMA integrity_check(10)"));
 
 
 
1126 }
1127
1128 /*
1129 ** COMMAND: test-orphans
1130 **
@@ -1231,11 +1243,11 @@
1231 **
1232 ** Usage: %fossil test-missing
1233 **
1234 ** Look at every artifact in the repository and verify that
1235 ** all references are satisfied. Report any referenced artifacts
1236 ** that are missing or shunned.
1237 **
1238 ** Options:
1239 ** --notshunned Do not report shunned artifacts
1240 ** -q|--quiet Only show output if there are errors
1241 */
@@ -1291,10 +1303,11 @@
1291 db_finalize(&q);
1292 if( nErr>0 || quietFlag==0 ){
1293 fossil_print("%d missing or shunned references in %d control artifacts\n",
1294 nErr, nArtifact);
1295 }
 
1296 }
1297
1298 /*
1299 ** COMMAND: test-content-erase
1300 **
1301
--- src/content.c
+++ src/content.c
@@ -989,10 +989,12 @@
989 **
990 ** Verify that all content can be extracted from the BLOB table correctly.
991 ** If the BLOB table is correct, then the repository can always be
992 ** successfully reconstructed using "fossil rebuild".
993 **
994 ** The exit status is 1 if any error is found.
995 **
996 ** Options:
997 ** -d|--db-only Run "PRAGMA integrity_check" on the database only.
998 ** No other validation is performed.
999 ** --parse Parse all manifests, wikis, tickets, events, and
1000 ** so forth, reporting any errors found.
@@ -1010,14 +1012,14 @@
1012 int nPhantom = 0;
1013 int anCA[10];
1014 int bParse = find_option("parse",0,0)!=0;
1015 int bDbOnly = find_option("db-only","d",0)!=0;
1016 int bQuick = find_option("quick",0,0)!=0;
1017 char *zRes;
1018 db_find_and_open_repository(OPEN_ANY_SCHEMA, 2);
1019 if( bDbOnly || bQuick ){
1020 const char *zType = bQuick ? "quick" : "integrity";
 
1021 zRes = db_text(0,"PRAGMA repository.%s_check", zType/*safe-for-%s*/);
1022 if( fossil_strcmp(zRes,"ok")!=0 ){
1023 fossil_print("%s_check failed!\n", zType);
1024 exit(1);
1025 }else{
@@ -1089,10 +1091,17 @@
1091 zFirstLine[i] = 0;
1092 p = manifest_parse(&content, 0, &err);
1093 if( p==0 ){
1094 fossil_print("manifest_parse failed for %s:\n%s\n",
1095 zUuid, blob_str(&err));
1096 /* An ordinary file can look like a control artifact and fail to
1097 ** parse. That is an error only if the repository has it down
1098 ** as a check-in, wiki page, ticket or the like, or as a cluster. */
1099 if( db_exists("SELECT 1 FROM event WHERE objid=%d"
1100 " UNION ALL"
1101 " SELECT 1 FROM tagxref WHERE rid=%d AND tagid=%d",
1102 rid, rid, TAG_CLUSTER) ) nErr++;
1103 if( strncmp(blob_str(&err), "line 1:", 7)==0 ){
1104 fossil_print("\"%s\"\n", zFirstLine);
1105 }
1106 }else{
1107 anCA[p->type]++;
@@ -1120,11 +1129,14 @@
1129 for(i=1; i<count(azType); i++){
1130 if( anCA[i] ) fossil_print(" %d %ss\n", anCA[i], azType[i]);
1131 }
1132 }
1133 fossil_print("low-level database integrity-check: ");
1134 zRes = db_text(0, "PRAGMA repository.integrity_check(10)");
1135 fossil_print("%s\n", zRes);
1136 if( fossil_strcmp(zRes,"ok")!=0 ) nErr++;
1137 if( nErr ) fossil_exit(1);
1138 }
1139
1140 /*
1141 ** COMMAND: test-orphans
1142 **
@@ -1231,11 +1243,11 @@
1243 **
1244 ** Usage: %fossil test-missing
1245 **
1246 ** Look at every artifact in the repository and verify that
1247 ** all references are satisfied. Report any referenced artifacts
1248 ** that are missing or shunned. The exit status is 1 if any are found.
1249 **
1250 ** Options:
1251 ** --notshunned Do not report shunned artifacts
1252 ** -q|--quiet Only show output if there are errors
1253 */
@@ -1291,10 +1303,11 @@
1303 db_finalize(&q);
1304 if( nErr>0 || quietFlag==0 ){
1305 fossil_print("%d missing or shunned references in %d control artifacts\n",
1306 nErr, nArtifact);
1307 }
1308 if( nErr ) fossil_exit(1);
1309 }
1310
1311 /*
1312 ** COMMAND: test-content-erase
1313 **
1314

Keyboard Shortcuts

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