Fossil SCM

Add a prototype "test-orphans" command. Does not yet work exactly right.

drh 2012-10-15 14:31 trunk
Commit 1ec715ae3493e09d8735c713972f42eaa7b4809b
1 file changed +32
--- src/content.c
+++ src/content.c
@@ -894,5 +894,37 @@
894894
}
895895
db_finalize(&q);
896896
fossil_print("%d non-phantom blobs (out of %d total) checked: %d errors\n",
897897
n2, n1, nErr);
898898
}
899
+
900
+/*
901
+** COMMAND: test-orphans
902
+**
903
+** Search the repository for orphaned artifacts
904
+*/
905
+void test_orphans(void){
906
+ Stmt q;
907
+ int cnt = 0;
908
+
909
+ db_find_and_open_repository(0, 0);
910
+ db_multi_exec(
911
+ "CREATE TEMP TABLE used(id INTEGER PRIMARY KEY ON CONFLICT IGNORE);"
912
+ "INSERT INTO used SELECT mid FROM mlink;" /* Manifests */
913
+ "INSERT INTO used SELECT fid FROM mlink;" /* Files */
914
+ "INSERT INTO used SELECT srcid FROM tagxref WHERE srcid>0;" /* Tags */
915
+ "INSERT INTO used SELECT rid FROM tagxref;" /* Wiki & tickets */
916
+ "INSERT INTO used SELECT rid FROM attachment JOIN blob ON src=uuid;"
917
+ "INSERT INTO used SELECT attachid FROM attachment;"
918
+ "INSERT INTO used SELECT objid FROM event;"
919
+ );
920
+ db_prepare(&q, "SELECT rid, uuid, size FROM blob WHERE rid NOT IN used");
921
+ while( db_step(&q)==SQLITE_ROW ){
922
+ fossil_print("%7d %s size: %d\n",
923
+ db_column_int(&q, 0),
924
+ db_column_text(&q, 1),
925
+ db_column_int(&q,2));
926
+ cnt++;
927
+ }
928
+ db_finalize(&q);
929
+ fossil_print("%d orphans\n", cnt);
930
+}
899931
--- src/content.c
+++ src/content.c
@@ -894,5 +894,37 @@
894 }
895 db_finalize(&q);
896 fossil_print("%d non-phantom blobs (out of %d total) checked: %d errors\n",
897 n2, n1, nErr);
898 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
899
--- src/content.c
+++ src/content.c
@@ -894,5 +894,37 @@
894 }
895 db_finalize(&q);
896 fossil_print("%d non-phantom blobs (out of %d total) checked: %d errors\n",
897 n2, n1, nErr);
898 }
899
900 /*
901 ** COMMAND: test-orphans
902 **
903 ** Search the repository for orphaned artifacts
904 */
905 void test_orphans(void){
906 Stmt q;
907 int cnt = 0;
908
909 db_find_and_open_repository(0, 0);
910 db_multi_exec(
911 "CREATE TEMP TABLE used(id INTEGER PRIMARY KEY ON CONFLICT IGNORE);"
912 "INSERT INTO used SELECT mid FROM mlink;" /* Manifests */
913 "INSERT INTO used SELECT fid FROM mlink;" /* Files */
914 "INSERT INTO used SELECT srcid FROM tagxref WHERE srcid>0;" /* Tags */
915 "INSERT INTO used SELECT rid FROM tagxref;" /* Wiki & tickets */
916 "INSERT INTO used SELECT rid FROM attachment JOIN blob ON src=uuid;"
917 "INSERT INTO used SELECT attachid FROM attachment;"
918 "INSERT INTO used SELECT objid FROM event;"
919 );
920 db_prepare(&q, "SELECT rid, uuid, size FROM blob WHERE rid NOT IN used");
921 while( db_step(&q)==SQLITE_ROW ){
922 fossil_print("%7d %s size: %d\n",
923 db_column_int(&q, 0),
924 db_column_text(&q, 1),
925 db_column_int(&q,2));
926 cnt++;
927 }
928 db_finalize(&q);
929 fossil_print("%d orphans\n", cnt);
930 }
931

Keyboard Shortcuts

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