Fossil SCM

Add the "fossil all whatis" command.

drh 2023-06-05 19:01 trunk
Commit 5484968158a915dc36941394dee809082ad6708d128cab54fadb8b859594fa57
2 files changed +7 -1 +27 -11
+7 -1
--- src/allrepo.c
+++ src/allrepo.c
@@ -131,10 +131,12 @@
131131
** ui Run the "ui" command on all repositories. Like "server"
132132
** but bind to the loopback TCP address only, enable
133133
** the --localauth option and automatically launch a
134134
** web-browser
135135
**
136
+** whatis XX Search for artifacts that have hash prefix XX
137
+**
136138
**
137139
** In addition, the following maintenance operations are supported:
138140
**
139141
** add Add all the repositories named to the set of repositories
140142
** tracked by Fossil. Normally Fossil is able to keep up with
@@ -408,15 +410,19 @@
408410
quiet = 1;
409411
}else if( fossil_strcmp(zCmd, "cache")==0 ){
410412
zCmd = "cache -R";
411413
showLabel = 1;
412414
collect_argv(&extra, 3);
415
+ }else if( fossil_strcmp(zCmd, "whatis")==0 ){
416
+ zCmd = "whatis -q -R";
417
+ quiet = 1;
418
+ collect_argv(&extra, 3);
413419
}else{
414420
fossil_fatal("\"all\" subcommand should be one of: "
415421
"add cache changes clean dbstat extras fts-config git ignore "
416422
"info list ls pull push rebuild remote "
417
- "server setting sync ui unset");
423
+ "server setting sync ui unset whatis");
418424
}
419425
verify_all_options();
420426
db_multi_exec("CREATE TEMP TABLE repolist(name,tag);");
421427
if( useCheckouts ){
422428
db_multi_exec(
423429
--- src/allrepo.c
+++ src/allrepo.c
@@ -131,10 +131,12 @@
131 ** ui Run the "ui" command on all repositories. Like "server"
132 ** but bind to the loopback TCP address only, enable
133 ** the --localauth option and automatically launch a
134 ** web-browser
135 **
 
 
136 **
137 ** In addition, the following maintenance operations are supported:
138 **
139 ** add Add all the repositories named to the set of repositories
140 ** tracked by Fossil. Normally Fossil is able to keep up with
@@ -408,15 +410,19 @@
408 quiet = 1;
409 }else if( fossil_strcmp(zCmd, "cache")==0 ){
410 zCmd = "cache -R";
411 showLabel = 1;
412 collect_argv(&extra, 3);
 
 
 
 
413 }else{
414 fossil_fatal("\"all\" subcommand should be one of: "
415 "add cache changes clean dbstat extras fts-config git ignore "
416 "info list ls pull push rebuild remote "
417 "server setting sync ui unset");
418 }
419 verify_all_options();
420 db_multi_exec("CREATE TEMP TABLE repolist(name,tag);");
421 if( useCheckouts ){
422 db_multi_exec(
423
--- src/allrepo.c
+++ src/allrepo.c
@@ -131,10 +131,12 @@
131 ** ui Run the "ui" command on all repositories. Like "server"
132 ** but bind to the loopback TCP address only, enable
133 ** the --localauth option and automatically launch a
134 ** web-browser
135 **
136 ** whatis XX Search for artifacts that have hash prefix XX
137 **
138 **
139 ** In addition, the following maintenance operations are supported:
140 **
141 ** add Add all the repositories named to the set of repositories
142 ** tracked by Fossil. Normally Fossil is able to keep up with
@@ -408,15 +410,19 @@
410 quiet = 1;
411 }else if( fossil_strcmp(zCmd, "cache")==0 ){
412 zCmd = "cache -R";
413 showLabel = 1;
414 collect_argv(&extra, 3);
415 }else if( fossil_strcmp(zCmd, "whatis")==0 ){
416 zCmd = "whatis -q -R";
417 quiet = 1;
418 collect_argv(&extra, 3);
419 }else{
420 fossil_fatal("\"all\" subcommand should be one of: "
421 "add cache changes clean dbstat extras fts-config git ignore "
422 "info list ls pull push rebuild remote "
423 "server setting sync ui unset whatis");
424 }
425 verify_all_options();
426 db_multi_exec("CREATE TEMP TABLE repolist(name,tag);");
427 if( useCheckouts ){
428 db_multi_exec(
429
+27 -11
--- src/name.c
+++ src/name.c
@@ -979,12 +979,14 @@
979979
980980
/*
981981
** Flag values for whatis_rid().
982982
*/
983983
#if INTERFACE
984
-#define WHATIS_VERBOSE 0x01 /* Extra output */
985
-#define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
984
+#define WHATIS_VERBOSE 0x01 /* Extra output */
985
+#define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
986
+#define WHATIS_REPO 0x04 /* Show repository name */
987
+#define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */
986988
#endif
987989
988990
/*
989991
** Generate a description of artifact "rid"
990992
*/
@@ -1154,11 +1156,11 @@
11541156
*/
11551157
void whatis_artifact(
11561158
const char *zName, /* Symbolic name or full hash */
11571159
const char *zFileName,/* Optional: original filename (in file mode) */
11581160
const char *zType, /* Artifact type filter */
1159
- int verboseFlag /* Verbosity flag */
1161
+ int mFlags /* WHATIS_* flags */
11601162
){
11611163
const char* zNameTitle = "name:";
11621164
int rid = symbolic_name_to_rid(zName, zType);
11631165
if( zFileName ){
11641166
fossil_print("%-12s%s\n", zNameTitle, zFileName);
@@ -1165,26 +1167,34 @@
11651167
zNameTitle = "hash:";
11661168
}
11671169
if( rid<0 ){
11681170
Stmt q;
11691171
int cnt = 0;
1172
+ if( mFlags & WHATIS_REPO ){
1173
+ fossil_print("\nrepository: %s\n", g.zRepositoryName);
1174
+ }
11701175
fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName);
11711176
db_prepare(&q,
11721177
"SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
11731178
zName, zName
11741179
);
11751180
while( db_step(&q)==SQLITE_ROW ){
11761181
if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
1177
- whatis_rid(db_column_int(&q, 0), verboseFlag);
1182
+ whatis_rid(db_column_int(&q, 0), mFlags);
11781183
}
11791184
db_finalize(&q);
11801185
}else if( rid==0 ){
1181
- /* 0123456789 12 */
1182
- fossil_print("unknown: %s\n", zName);
1186
+ if( (mFlags & WHATIS_OMIT_UNK)==0 ){
1187
+ /* 0123456789 12 */
1188
+ fossil_print("unknown: %s\n", zName);
1189
+ }
11831190
}else{
1191
+ if( mFlags & WHATIS_REPO ){
1192
+ fossil_print("\nrepository: %s\n", g.zRepositoryName);
1193
+ }
11841194
fossil_print("%-12s%s\n", zNameTitle, zName);
1185
- whatis_rid(rid, verboseFlag);
1195
+ whatis_rid(rid, mFlags);
11861196
}
11871197
}
11881198
11891199
/*
11901200
** COMMAND: whatis*
@@ -1196,21 +1206,27 @@
11961206
** plays.
11971207
**
11981208
** Options:
11991209
** -f|--file Find artifacts with the same hash as file NAME.
12001210
** If NAME is "-", read content from standard input.
1211
+** -q|--quiet Show nothing if NAME is not found
12011212
** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't',
12021213
** 'w', 'g', or 'e')
12031214
** -v|--verbose Provide extra information (such as the RID)
12041215
*/
12051216
void whatis_cmd(void){
1206
- int verboseFlag;
1217
+ int mFlags = 0;
12071218
int fileFlag;
12081219
int i;
12091220
const char *zType = 0;
12101221
db_find_and_open_repository(0,0);
1211
- verboseFlag = find_option("verbose","v",0)!=0;
1222
+ if( find_option("verbose","v",0)!=0 ){
1223
+ mFlags |= WHATIS_VERBOSE;
1224
+ }
1225
+ if( find_option("quiet","q",0)!=0 ){
1226
+ mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO;
1227
+ }
12121228
fileFlag = find_option("file","f",0)!=0;
12131229
zType = find_option("type",0,1);
12141230
12151231
/* We should be done with options.. */
12161232
verify_all_options();
@@ -1235,14 +1251,14 @@
12351251
** the primary hash name. */
12361252
blob_reset(&hash);
12371253
hname_hash(&in, 0, &hash);
12381254
zHash = (const char*)blob_str(&hash);
12391255
}
1240
- whatis_artifact(zHash, zName, zType, verboseFlag);
1256
+ whatis_artifact(zHash, zName, zType, mFlags);
12411257
blob_reset(&hash);
12421258
}else{
1243
- whatis_artifact(zName, 0, zType, verboseFlag);
1259
+ whatis_artifact(zName, 0, zType, mFlags);
12441260
}
12451261
}
12461262
}
12471263
12481264
/*
12491265
--- src/name.c
+++ src/name.c
@@ -979,12 +979,14 @@
979
980 /*
981 ** Flag values for whatis_rid().
982 */
983 #if INTERFACE
984 #define WHATIS_VERBOSE 0x01 /* Extra output */
985 #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
 
 
986 #endif
987
988 /*
989 ** Generate a description of artifact "rid"
990 */
@@ -1154,11 +1156,11 @@
1154 */
1155 void whatis_artifact(
1156 const char *zName, /* Symbolic name or full hash */
1157 const char *zFileName,/* Optional: original filename (in file mode) */
1158 const char *zType, /* Artifact type filter */
1159 int verboseFlag /* Verbosity flag */
1160 ){
1161 const char* zNameTitle = "name:";
1162 int rid = symbolic_name_to_rid(zName, zType);
1163 if( zFileName ){
1164 fossil_print("%-12s%s\n", zNameTitle, zFileName);
@@ -1165,26 +1167,34 @@
1165 zNameTitle = "hash:";
1166 }
1167 if( rid<0 ){
1168 Stmt q;
1169 int cnt = 0;
 
 
 
1170 fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName);
1171 db_prepare(&q,
1172 "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
1173 zName, zName
1174 );
1175 while( db_step(&q)==SQLITE_ROW ){
1176 if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
1177 whatis_rid(db_column_int(&q, 0), verboseFlag);
1178 }
1179 db_finalize(&q);
1180 }else if( rid==0 ){
1181 /* 0123456789 12 */
1182 fossil_print("unknown: %s\n", zName);
 
 
1183 }else{
 
 
 
1184 fossil_print("%-12s%s\n", zNameTitle, zName);
1185 whatis_rid(rid, verboseFlag);
1186 }
1187 }
1188
1189 /*
1190 ** COMMAND: whatis*
@@ -1196,21 +1206,27 @@
1196 ** plays.
1197 **
1198 ** Options:
1199 ** -f|--file Find artifacts with the same hash as file NAME.
1200 ** If NAME is "-", read content from standard input.
 
1201 ** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't',
1202 ** 'w', 'g', or 'e')
1203 ** -v|--verbose Provide extra information (such as the RID)
1204 */
1205 void whatis_cmd(void){
1206 int verboseFlag;
1207 int fileFlag;
1208 int i;
1209 const char *zType = 0;
1210 db_find_and_open_repository(0,0);
1211 verboseFlag = find_option("verbose","v",0)!=0;
 
 
 
 
 
1212 fileFlag = find_option("file","f",0)!=0;
1213 zType = find_option("type",0,1);
1214
1215 /* We should be done with options.. */
1216 verify_all_options();
@@ -1235,14 +1251,14 @@
1235 ** the primary hash name. */
1236 blob_reset(&hash);
1237 hname_hash(&in, 0, &hash);
1238 zHash = (const char*)blob_str(&hash);
1239 }
1240 whatis_artifact(zHash, zName, zType, verboseFlag);
1241 blob_reset(&hash);
1242 }else{
1243 whatis_artifact(zName, 0, zType, verboseFlag);
1244 }
1245 }
1246 }
1247
1248 /*
1249
--- src/name.c
+++ src/name.c
@@ -979,12 +979,14 @@
979
980 /*
981 ** Flag values for whatis_rid().
982 */
983 #if INTERFACE
984 #define WHATIS_VERBOSE 0x01 /* Extra output */
985 #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
986 #define WHATIS_REPO 0x04 /* Show repository name */
987 #define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */
988 #endif
989
990 /*
991 ** Generate a description of artifact "rid"
992 */
@@ -1154,11 +1156,11 @@
1156 */
1157 void whatis_artifact(
1158 const char *zName, /* Symbolic name or full hash */
1159 const char *zFileName,/* Optional: original filename (in file mode) */
1160 const char *zType, /* Artifact type filter */
1161 int mFlags /* WHATIS_* flags */
1162 ){
1163 const char* zNameTitle = "name:";
1164 int rid = symbolic_name_to_rid(zName, zType);
1165 if( zFileName ){
1166 fossil_print("%-12s%s\n", zNameTitle, zFileName);
@@ -1165,26 +1167,34 @@
1167 zNameTitle = "hash:";
1168 }
1169 if( rid<0 ){
1170 Stmt q;
1171 int cnt = 0;
1172 if( mFlags & WHATIS_REPO ){
1173 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1174 }
1175 fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName);
1176 db_prepare(&q,
1177 "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
1178 zName, zName
1179 );
1180 while( db_step(&q)==SQLITE_ROW ){
1181 if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
1182 whatis_rid(db_column_int(&q, 0), mFlags);
1183 }
1184 db_finalize(&q);
1185 }else if( rid==0 ){
1186 if( (mFlags & WHATIS_OMIT_UNK)==0 ){
1187 /* 0123456789 12 */
1188 fossil_print("unknown: %s\n", zName);
1189 }
1190 }else{
1191 if( mFlags & WHATIS_REPO ){
1192 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1193 }
1194 fossil_print("%-12s%s\n", zNameTitle, zName);
1195 whatis_rid(rid, mFlags);
1196 }
1197 }
1198
1199 /*
1200 ** COMMAND: whatis*
@@ -1196,21 +1206,27 @@
1206 ** plays.
1207 **
1208 ** Options:
1209 ** -f|--file Find artifacts with the same hash as file NAME.
1210 ** If NAME is "-", read content from standard input.
1211 ** -q|--quiet Show nothing if NAME is not found
1212 ** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't',
1213 ** 'w', 'g', or 'e')
1214 ** -v|--verbose Provide extra information (such as the RID)
1215 */
1216 void whatis_cmd(void){
1217 int mFlags = 0;
1218 int fileFlag;
1219 int i;
1220 const char *zType = 0;
1221 db_find_and_open_repository(0,0);
1222 if( find_option("verbose","v",0)!=0 ){
1223 mFlags |= WHATIS_VERBOSE;
1224 }
1225 if( find_option("quiet","q",0)!=0 ){
1226 mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO;
1227 }
1228 fileFlag = find_option("file","f",0)!=0;
1229 zType = find_option("type",0,1);
1230
1231 /* We should be done with options.. */
1232 verify_all_options();
@@ -1235,14 +1251,14 @@
1251 ** the primary hash name. */
1252 blob_reset(&hash);
1253 hname_hash(&in, 0, &hash);
1254 zHash = (const char*)blob_str(&hash);
1255 }
1256 whatis_artifact(zHash, zName, zType, mFlags);
1257 blob_reset(&hash);
1258 }else{
1259 whatis_artifact(zName, 0, zType, mFlags);
1260 }
1261 }
1262 }
1263
1264 /*
1265

Keyboard Shortcuts

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