Fossil SCM
Add the "fossil all whatis" command.
Commit
5484968158a915dc36941394dee809082ad6708d128cab54fadb8b859594fa57
Parent
f25da6ec97ff4de…
2 files changed
+7
-1
+27
-11
+7
-1
| --- src/allrepo.c | ||
| +++ src/allrepo.c | ||
| @@ -131,10 +131,12 @@ | ||
| 131 | 131 | ** ui Run the "ui" command on all repositories. Like "server" |
| 132 | 132 | ** but bind to the loopback TCP address only, enable |
| 133 | 133 | ** the --localauth option and automatically launch a |
| 134 | 134 | ** web-browser |
| 135 | 135 | ** |
| 136 | +** whatis XX Search for artifacts that have hash prefix XX | |
| 137 | +** | |
| 136 | 138 | ** |
| 137 | 139 | ** In addition, the following maintenance operations are supported: |
| 138 | 140 | ** |
| 139 | 141 | ** add Add all the repositories named to the set of repositories |
| 140 | 142 | ** tracked by Fossil. Normally Fossil is able to keep up with |
| @@ -408,15 +410,19 @@ | ||
| 408 | 410 | quiet = 1; |
| 409 | 411 | }else if( fossil_strcmp(zCmd, "cache")==0 ){ |
| 410 | 412 | zCmd = "cache -R"; |
| 411 | 413 | showLabel = 1; |
| 412 | 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); | |
| 413 | 419 | }else{ |
| 414 | 420 | fossil_fatal("\"all\" subcommand should be one of: " |
| 415 | 421 | "add cache changes clean dbstat extras fts-config git ignore " |
| 416 | 422 | "info list ls pull push rebuild remote " |
| 417 | - "server setting sync ui unset"); | |
| 423 | + "server setting sync ui unset whatis"); | |
| 418 | 424 | } |
| 419 | 425 | verify_all_options(); |
| 420 | 426 | db_multi_exec("CREATE TEMP TABLE repolist(name,tag);"); |
| 421 | 427 | if( useCheckouts ){ |
| 422 | 428 | db_multi_exec( |
| 423 | 429 |
| --- 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 @@ | ||
| 979 | 979 | |
| 980 | 980 | /* |
| 981 | 981 | ** Flag values for whatis_rid(). |
| 982 | 982 | */ |
| 983 | 983 | #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 */ | |
| 986 | 988 | #endif |
| 987 | 989 | |
| 988 | 990 | /* |
| 989 | 991 | ** Generate a description of artifact "rid" |
| 990 | 992 | */ |
| @@ -1154,11 +1156,11 @@ | ||
| 1154 | 1156 | */ |
| 1155 | 1157 | void whatis_artifact( |
| 1156 | 1158 | const char *zName, /* Symbolic name or full hash */ |
| 1157 | 1159 | const char *zFileName,/* Optional: original filename (in file mode) */ |
| 1158 | 1160 | const char *zType, /* Artifact type filter */ |
| 1159 | - int verboseFlag /* Verbosity flag */ | |
| 1161 | + int mFlags /* WHATIS_* flags */ | |
| 1160 | 1162 | ){ |
| 1161 | 1163 | const char* zNameTitle = "name:"; |
| 1162 | 1164 | int rid = symbolic_name_to_rid(zName, zType); |
| 1163 | 1165 | if( zFileName ){ |
| 1164 | 1166 | fossil_print("%-12s%s\n", zNameTitle, zFileName); |
| @@ -1165,26 +1167,34 @@ | ||
| 1165 | 1167 | zNameTitle = "hash:"; |
| 1166 | 1168 | } |
| 1167 | 1169 | if( rid<0 ){ |
| 1168 | 1170 | Stmt q; |
| 1169 | 1171 | int cnt = 0; |
| 1172 | + if( mFlags & WHATIS_REPO ){ | |
| 1173 | + fossil_print("\nrepository: %s\n", g.zRepositoryName); | |
| 1174 | + } | |
| 1170 | 1175 | fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName); |
| 1171 | 1176 | db_prepare(&q, |
| 1172 | 1177 | "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')", |
| 1173 | 1178 | zName, zName |
| 1174 | 1179 | ); |
| 1175 | 1180 | while( db_step(&q)==SQLITE_ROW ){ |
| 1176 | 1181 | 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); | |
| 1178 | 1183 | } |
| 1179 | 1184 | db_finalize(&q); |
| 1180 | 1185 | }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 | + } | |
| 1183 | 1190 | }else{ |
| 1191 | + if( mFlags & WHATIS_REPO ){ | |
| 1192 | + fossil_print("\nrepository: %s\n", g.zRepositoryName); | |
| 1193 | + } | |
| 1184 | 1194 | fossil_print("%-12s%s\n", zNameTitle, zName); |
| 1185 | - whatis_rid(rid, verboseFlag); | |
| 1195 | + whatis_rid(rid, mFlags); | |
| 1186 | 1196 | } |
| 1187 | 1197 | } |
| 1188 | 1198 | |
| 1189 | 1199 | /* |
| 1190 | 1200 | ** COMMAND: whatis* |
| @@ -1196,21 +1206,27 @@ | ||
| 1196 | 1206 | ** plays. |
| 1197 | 1207 | ** |
| 1198 | 1208 | ** Options: |
| 1199 | 1209 | ** -f|--file Find artifacts with the same hash as file NAME. |
| 1200 | 1210 | ** If NAME is "-", read content from standard input. |
| 1211 | +** -q|--quiet Show nothing if NAME is not found | |
| 1201 | 1212 | ** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't', |
| 1202 | 1213 | ** 'w', 'g', or 'e') |
| 1203 | 1214 | ** -v|--verbose Provide extra information (such as the RID) |
| 1204 | 1215 | */ |
| 1205 | 1216 | void whatis_cmd(void){ |
| 1206 | - int verboseFlag; | |
| 1217 | + int mFlags = 0; | |
| 1207 | 1218 | int fileFlag; |
| 1208 | 1219 | int i; |
| 1209 | 1220 | const char *zType = 0; |
| 1210 | 1221 | 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 | + } | |
| 1212 | 1228 | fileFlag = find_option("file","f",0)!=0; |
| 1213 | 1229 | zType = find_option("type",0,1); |
| 1214 | 1230 | |
| 1215 | 1231 | /* We should be done with options.. */ |
| 1216 | 1232 | verify_all_options(); |
| @@ -1235,14 +1251,14 @@ | ||
| 1235 | 1251 | ** the primary hash name. */ |
| 1236 | 1252 | blob_reset(&hash); |
| 1237 | 1253 | hname_hash(&in, 0, &hash); |
| 1238 | 1254 | zHash = (const char*)blob_str(&hash); |
| 1239 | 1255 | } |
| 1240 | - whatis_artifact(zHash, zName, zType, verboseFlag); | |
| 1256 | + whatis_artifact(zHash, zName, zType, mFlags); | |
| 1241 | 1257 | blob_reset(&hash); |
| 1242 | 1258 | }else{ |
| 1243 | - whatis_artifact(zName, 0, zType, verboseFlag); | |
| 1259 | + whatis_artifact(zName, 0, zType, mFlags); | |
| 1244 | 1260 | } |
| 1245 | 1261 | } |
| 1246 | 1262 | } |
| 1247 | 1263 | |
| 1248 | 1264 | /* |
| 1249 | 1265 |
| --- 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 |