Fossil SCM
Improve "whatis" output when in "filename" mode and parse supported whatis options when using "fossil all whatis".
Commit
e1e9da26f68fe963e203063852f8e19910d8ecf8ee4c6f8f1b030c830411aa5b
Parent
8d3b63e6e84d390…
2 files changed
+13
-9
+11
-7
+13
-9
| --- src/allrepo.c | ||
| +++ src/allrepo.c | ||
| @@ -31,12 +31,14 @@ | ||
| 31 | 31 | const char *z = find_option(zArg, zShort, 0); |
| 32 | 32 | if( z!=0 ){ |
| 33 | 33 | blob_appendf(pExtra, " %s", z); |
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | -static void collect_argument_value(Blob *pExtra, const char *zArg){ | |
| 37 | - const char *zValue = find_option(zArg, 0, 1); | |
| 36 | +static void collect_argument_value( | |
| 37 | + Blob *pExtra, const char *zArg, const char *zShort | |
| 38 | +){ | |
| 39 | + const char *zValue = find_option(zArg, zShort, 1); | |
| 38 | 40 | if( zValue ){ |
| 39 | 41 | if( zValue[0] ){ |
| 40 | 42 | blob_appendf(pExtra, " --%s %$", zArg, zValue); |
| 41 | 43 | }else{ |
| 42 | 44 | blob_appendf(pExtra, " --%s \"\"", zArg); |
| @@ -210,19 +212,19 @@ | ||
| 210 | 212 | } |
| 211 | 213 | blob_appendf(&extra, " %$", zDest); |
| 212 | 214 | }else if( fossil_strcmp(zCmd, "clean")==0 ){ |
| 213 | 215 | zCmd = "clean --chdir"; |
| 214 | 216 | collect_argument(&extra, "allckouts",0); |
| 215 | - collect_argument_value(&extra, "case-sensitive"); | |
| 216 | - collect_argument_value(&extra, "clean"); | |
| 217 | + collect_argument_value(&extra, "case-sensitive", 0); | |
| 218 | + collect_argument_value(&extra, "clean", 0); | |
| 217 | 219 | collect_argument(&extra, "dirsonly",0); |
| 218 | 220 | collect_argument(&extra, "disable-undo",0); |
| 219 | 221 | collect_argument(&extra, "dotfiles",0); |
| 220 | 222 | collect_argument(&extra, "emptydirs",0); |
| 221 | 223 | collect_argument(&extra, "force","f"); |
| 222 | - collect_argument_value(&extra, "ignore"); | |
| 223 | - collect_argument_value(&extra, "keep"); | |
| 224 | + collect_argument_value(&extra, "ignore", 0); | |
| 225 | + collect_argument_value(&extra, "keep", 0); | |
| 224 | 226 | collect_argument(&extra, "no-prompt",0); |
| 225 | 227 | collect_argument(&extra, "temp",0); |
| 226 | 228 | collect_argument(&extra, "verbose","v"); |
| 227 | 229 | collect_argument(&extra, "whatif",0); |
| 228 | 230 | useCheckouts = 1; |
| @@ -247,13 +249,13 @@ | ||
| 247 | 249 | zCmd = "extras --chdir"; |
| 248 | 250 | }else{ |
| 249 | 251 | zCmd = "extras --header --chdir"; |
| 250 | 252 | } |
| 251 | 253 | collect_argument(&extra, "abs-paths",0); |
| 252 | - collect_argument_value(&extra, "case-sensitive"); | |
| 254 | + collect_argument_value(&extra, "case-sensitive", 0); | |
| 253 | 255 | collect_argument(&extra, "dotfiles",0); |
| 254 | - collect_argument_value(&extra, "ignore"); | |
| 256 | + collect_argument_value(&extra, "ignore", 0); | |
| 255 | 257 | collect_argument(&extra, "rel-paths",0); |
| 256 | 258 | useCheckouts = 1; |
| 257 | 259 | stopOnError = 0; |
| 258 | 260 | quiet = 1; |
| 259 | 261 | }else if( fossil_strcmp(zCmd, "git")==0 ){ |
| @@ -280,11 +282,11 @@ | ||
| 280 | 282 | zCmd = "rebuild"; |
| 281 | 283 | collect_argument(&extra, "cluster",0); |
| 282 | 284 | collect_argument(&extra, "compress",0); |
| 283 | 285 | collect_argument(&extra, "compress-only",0); |
| 284 | 286 | collect_argument(&extra, "noverify",0); |
| 285 | - collect_argument_value(&extra, "pagesize"); | |
| 287 | + collect_argument_value(&extra, "pagesize", 0); | |
| 286 | 288 | collect_argument(&extra, "vacuum",0); |
| 287 | 289 | collect_argument(&extra, "deanalyze",0); |
| 288 | 290 | collect_argument(&extra, "analyze",0); |
| 289 | 291 | collect_argument(&extra, "wal",0); |
| 290 | 292 | collect_argument(&extra, "stats",0); |
| @@ -414,10 +416,12 @@ | ||
| 414 | 416 | showLabel = 1; |
| 415 | 417 | collect_argv(&extra, 3); |
| 416 | 418 | }else if( fossil_strcmp(zCmd, "whatis")==0 ){ |
| 417 | 419 | zCmd = "whatis -q -R"; |
| 418 | 420 | quiet = 1; |
| 421 | + collect_argument(&extra, "file", "f"); | |
| 422 | + collect_argument_value(&extra, "type", 0); | |
| 419 | 423 | collect_argv(&extra, 3); |
| 420 | 424 | }else{ |
| 421 | 425 | fossil_fatal("\"all\" subcommand should be one of: " |
| 422 | 426 | "add cache changes clean dbstat extras fts-config git ignore " |
| 423 | 427 | "info list ls pull push rebuild remote " |
| 424 | 428 |
| --- src/allrepo.c | |
| +++ src/allrepo.c | |
| @@ -31,12 +31,14 @@ | |
| 31 | const char *z = find_option(zArg, zShort, 0); |
| 32 | if( z!=0 ){ |
| 33 | blob_appendf(pExtra, " %s", z); |
| 34 | } |
| 35 | } |
| 36 | static void collect_argument_value(Blob *pExtra, const char *zArg){ |
| 37 | const char *zValue = find_option(zArg, 0, 1); |
| 38 | if( zValue ){ |
| 39 | if( zValue[0] ){ |
| 40 | blob_appendf(pExtra, " --%s %$", zArg, zValue); |
| 41 | }else{ |
| 42 | blob_appendf(pExtra, " --%s \"\"", zArg); |
| @@ -210,19 +212,19 @@ | |
| 210 | } |
| 211 | blob_appendf(&extra, " %$", zDest); |
| 212 | }else if( fossil_strcmp(zCmd, "clean")==0 ){ |
| 213 | zCmd = "clean --chdir"; |
| 214 | collect_argument(&extra, "allckouts",0); |
| 215 | collect_argument_value(&extra, "case-sensitive"); |
| 216 | collect_argument_value(&extra, "clean"); |
| 217 | collect_argument(&extra, "dirsonly",0); |
| 218 | collect_argument(&extra, "disable-undo",0); |
| 219 | collect_argument(&extra, "dotfiles",0); |
| 220 | collect_argument(&extra, "emptydirs",0); |
| 221 | collect_argument(&extra, "force","f"); |
| 222 | collect_argument_value(&extra, "ignore"); |
| 223 | collect_argument_value(&extra, "keep"); |
| 224 | collect_argument(&extra, "no-prompt",0); |
| 225 | collect_argument(&extra, "temp",0); |
| 226 | collect_argument(&extra, "verbose","v"); |
| 227 | collect_argument(&extra, "whatif",0); |
| 228 | useCheckouts = 1; |
| @@ -247,13 +249,13 @@ | |
| 247 | zCmd = "extras --chdir"; |
| 248 | }else{ |
| 249 | zCmd = "extras --header --chdir"; |
| 250 | } |
| 251 | collect_argument(&extra, "abs-paths",0); |
| 252 | collect_argument_value(&extra, "case-sensitive"); |
| 253 | collect_argument(&extra, "dotfiles",0); |
| 254 | collect_argument_value(&extra, "ignore"); |
| 255 | collect_argument(&extra, "rel-paths",0); |
| 256 | useCheckouts = 1; |
| 257 | stopOnError = 0; |
| 258 | quiet = 1; |
| 259 | }else if( fossil_strcmp(zCmd, "git")==0 ){ |
| @@ -280,11 +282,11 @@ | |
| 280 | zCmd = "rebuild"; |
| 281 | collect_argument(&extra, "cluster",0); |
| 282 | collect_argument(&extra, "compress",0); |
| 283 | collect_argument(&extra, "compress-only",0); |
| 284 | collect_argument(&extra, "noverify",0); |
| 285 | collect_argument_value(&extra, "pagesize"); |
| 286 | collect_argument(&extra, "vacuum",0); |
| 287 | collect_argument(&extra, "deanalyze",0); |
| 288 | collect_argument(&extra, "analyze",0); |
| 289 | collect_argument(&extra, "wal",0); |
| 290 | collect_argument(&extra, "stats",0); |
| @@ -414,10 +416,12 @@ | |
| 414 | showLabel = 1; |
| 415 | collect_argv(&extra, 3); |
| 416 | }else if( fossil_strcmp(zCmd, "whatis")==0 ){ |
| 417 | zCmd = "whatis -q -R"; |
| 418 | quiet = 1; |
| 419 | collect_argv(&extra, 3); |
| 420 | }else{ |
| 421 | fossil_fatal("\"all\" subcommand should be one of: " |
| 422 | "add cache changes clean dbstat extras fts-config git ignore " |
| 423 | "info list ls pull push rebuild remote " |
| 424 |
| --- src/allrepo.c | |
| +++ src/allrepo.c | |
| @@ -31,12 +31,14 @@ | |
| 31 | const char *z = find_option(zArg, zShort, 0); |
| 32 | if( z!=0 ){ |
| 33 | blob_appendf(pExtra, " %s", z); |
| 34 | } |
| 35 | } |
| 36 | static void collect_argument_value( |
| 37 | Blob *pExtra, const char *zArg, const char *zShort |
| 38 | ){ |
| 39 | const char *zValue = find_option(zArg, zShort, 1); |
| 40 | if( zValue ){ |
| 41 | if( zValue[0] ){ |
| 42 | blob_appendf(pExtra, " --%s %$", zArg, zValue); |
| 43 | }else{ |
| 44 | blob_appendf(pExtra, " --%s \"\"", zArg); |
| @@ -210,19 +212,19 @@ | |
| 212 | } |
| 213 | blob_appendf(&extra, " %$", zDest); |
| 214 | }else if( fossil_strcmp(zCmd, "clean")==0 ){ |
| 215 | zCmd = "clean --chdir"; |
| 216 | collect_argument(&extra, "allckouts",0); |
| 217 | collect_argument_value(&extra, "case-sensitive", 0); |
| 218 | collect_argument_value(&extra, "clean", 0); |
| 219 | collect_argument(&extra, "dirsonly",0); |
| 220 | collect_argument(&extra, "disable-undo",0); |
| 221 | collect_argument(&extra, "dotfiles",0); |
| 222 | collect_argument(&extra, "emptydirs",0); |
| 223 | collect_argument(&extra, "force","f"); |
| 224 | collect_argument_value(&extra, "ignore", 0); |
| 225 | collect_argument_value(&extra, "keep", 0); |
| 226 | collect_argument(&extra, "no-prompt",0); |
| 227 | collect_argument(&extra, "temp",0); |
| 228 | collect_argument(&extra, "verbose","v"); |
| 229 | collect_argument(&extra, "whatif",0); |
| 230 | useCheckouts = 1; |
| @@ -247,13 +249,13 @@ | |
| 249 | zCmd = "extras --chdir"; |
| 250 | }else{ |
| 251 | zCmd = "extras --header --chdir"; |
| 252 | } |
| 253 | collect_argument(&extra, "abs-paths",0); |
| 254 | collect_argument_value(&extra, "case-sensitive", 0); |
| 255 | collect_argument(&extra, "dotfiles",0); |
| 256 | collect_argument_value(&extra, "ignore", 0); |
| 257 | collect_argument(&extra, "rel-paths",0); |
| 258 | useCheckouts = 1; |
| 259 | stopOnError = 0; |
| 260 | quiet = 1; |
| 261 | }else if( fossil_strcmp(zCmd, "git")==0 ){ |
| @@ -280,11 +282,11 @@ | |
| 282 | zCmd = "rebuild"; |
| 283 | collect_argument(&extra, "cluster",0); |
| 284 | collect_argument(&extra, "compress",0); |
| 285 | collect_argument(&extra, "compress-only",0); |
| 286 | collect_argument(&extra, "noverify",0); |
| 287 | collect_argument_value(&extra, "pagesize", 0); |
| 288 | collect_argument(&extra, "vacuum",0); |
| 289 | collect_argument(&extra, "deanalyze",0); |
| 290 | collect_argument(&extra, "analyze",0); |
| 291 | collect_argument(&extra, "wal",0); |
| 292 | collect_argument(&extra, "stats",0); |
| @@ -414,10 +416,12 @@ | |
| 416 | showLabel = 1; |
| 417 | collect_argv(&extra, 3); |
| 418 | }else if( fossil_strcmp(zCmd, "whatis")==0 ){ |
| 419 | zCmd = "whatis -q -R"; |
| 420 | quiet = 1; |
| 421 | collect_argument(&extra, "file", "f"); |
| 422 | collect_argument_value(&extra, "type", 0); |
| 423 | collect_argv(&extra, 3); |
| 424 | }else{ |
| 425 | fossil_fatal("\"all\" subcommand should be one of: " |
| 426 | "add cache changes clean dbstat extras fts-config git ignore " |
| 427 | "info list ls pull push rebuild remote " |
| 428 |
+11
-7
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -1163,23 +1163,21 @@ | ||
| 1163 | 1163 | const char *zName, /* Symbolic name or full hash */ |
| 1164 | 1164 | const char *zFileName,/* Optional: original filename (in file mode) */ |
| 1165 | 1165 | const char *zType, /* Artifact type filter */ |
| 1166 | 1166 | int mFlags /* WHATIS_* flags */ |
| 1167 | 1167 | ){ |
| 1168 | - const char* zNameTitle = "name:"; | |
| 1169 | 1168 | int rid = symbolic_name_to_rid(zName, zType); |
| 1170 | - if( zFileName ){ | |
| 1171 | - fossil_print("%-12s%s\n", zNameTitle, zFileName); | |
| 1172 | - zNameTitle = "hash:"; | |
| 1173 | - } | |
| 1174 | 1169 | if( rid<0 ){ |
| 1175 | 1170 | Stmt q; |
| 1176 | 1171 | int cnt = 0; |
| 1177 | 1172 | if( mFlags & WHATIS_REPO ){ |
| 1178 | 1173 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1179 | 1174 | } |
| 1180 | - fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName); | |
| 1175 | + if( zFileName ){ | |
| 1176 | + fossil_print("%-12s%s\n", "name:", zFileName); | |
| 1177 | + } | |
| 1178 | + fossil_print("%-12s%s (ambiguous)\n", "hash:", zName); | |
| 1181 | 1179 | db_prepare(&q, |
| 1182 | 1180 | "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')", |
| 1183 | 1181 | zName, zName |
| 1184 | 1182 | ); |
| 1185 | 1183 | while( db_step(&q)==SQLITE_ROW ){ |
| @@ -1188,17 +1186,23 @@ | ||
| 1188 | 1186 | } |
| 1189 | 1187 | db_finalize(&q); |
| 1190 | 1188 | }else if( rid==0 ){ |
| 1191 | 1189 | if( (mFlags & WHATIS_OMIT_UNK)==0 ){ |
| 1192 | 1190 | /* 0123456789 12 */ |
| 1191 | + if( zFileName ){ | |
| 1192 | + fossil_print("%-12s%s\n", "name:", zFileName); | |
| 1193 | + } | |
| 1193 | 1194 | fossil_print("unknown: %s\n", zName); |
| 1194 | 1195 | } |
| 1195 | 1196 | }else{ |
| 1196 | 1197 | if( mFlags & WHATIS_REPO ){ |
| 1197 | 1198 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1198 | 1199 | } |
| 1199 | - fossil_print("%-12s%s\n", zNameTitle, zName); | |
| 1200 | + if( zFileName ){ | |
| 1201 | + zName = zFileName; | |
| 1202 | + } | |
| 1203 | + fossil_print("%-12s%s\n", "name:", zName); | |
| 1200 | 1204 | whatis_rid(rid, mFlags); |
| 1201 | 1205 | } |
| 1202 | 1206 | } |
| 1203 | 1207 | |
| 1204 | 1208 | /* |
| 1205 | 1209 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -1163,23 +1163,21 @@ | |
| 1163 | const char *zName, /* Symbolic name or full hash */ |
| 1164 | const char *zFileName,/* Optional: original filename (in file mode) */ |
| 1165 | const char *zType, /* Artifact type filter */ |
| 1166 | int mFlags /* WHATIS_* flags */ |
| 1167 | ){ |
| 1168 | const char* zNameTitle = "name:"; |
| 1169 | int rid = symbolic_name_to_rid(zName, zType); |
| 1170 | if( zFileName ){ |
| 1171 | fossil_print("%-12s%s\n", zNameTitle, zFileName); |
| 1172 | zNameTitle = "hash:"; |
| 1173 | } |
| 1174 | if( rid<0 ){ |
| 1175 | Stmt q; |
| 1176 | int cnt = 0; |
| 1177 | if( mFlags & WHATIS_REPO ){ |
| 1178 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1179 | } |
| 1180 | fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName); |
| 1181 | db_prepare(&q, |
| 1182 | "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')", |
| 1183 | zName, zName |
| 1184 | ); |
| 1185 | while( db_step(&q)==SQLITE_ROW ){ |
| @@ -1188,17 +1186,23 @@ | |
| 1188 | } |
| 1189 | db_finalize(&q); |
| 1190 | }else if( rid==0 ){ |
| 1191 | if( (mFlags & WHATIS_OMIT_UNK)==0 ){ |
| 1192 | /* 0123456789 12 */ |
| 1193 | fossil_print("unknown: %s\n", zName); |
| 1194 | } |
| 1195 | }else{ |
| 1196 | if( mFlags & WHATIS_REPO ){ |
| 1197 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1198 | } |
| 1199 | fossil_print("%-12s%s\n", zNameTitle, zName); |
| 1200 | whatis_rid(rid, mFlags); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | /* |
| 1205 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -1163,23 +1163,21 @@ | |
| 1163 | const char *zName, /* Symbolic name or full hash */ |
| 1164 | const char *zFileName,/* Optional: original filename (in file mode) */ |
| 1165 | const char *zType, /* Artifact type filter */ |
| 1166 | int mFlags /* WHATIS_* flags */ |
| 1167 | ){ |
| 1168 | int rid = symbolic_name_to_rid(zName, zType); |
| 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 | if( zFileName ){ |
| 1176 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1177 | } |
| 1178 | fossil_print("%-12s%s (ambiguous)\n", "hash:", zName); |
| 1179 | db_prepare(&q, |
| 1180 | "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')", |
| 1181 | zName, zName |
| 1182 | ); |
| 1183 | while( db_step(&q)==SQLITE_ROW ){ |
| @@ -1188,17 +1186,23 @@ | |
| 1186 | } |
| 1187 | db_finalize(&q); |
| 1188 | }else if( rid==0 ){ |
| 1189 | if( (mFlags & WHATIS_OMIT_UNK)==0 ){ |
| 1190 | /* 0123456789 12 */ |
| 1191 | if( zFileName ){ |
| 1192 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1193 | } |
| 1194 | fossil_print("unknown: %s\n", zName); |
| 1195 | } |
| 1196 | }else{ |
| 1197 | if( mFlags & WHATIS_REPO ){ |
| 1198 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1199 | } |
| 1200 | if( zFileName ){ |
| 1201 | zName = zFileName; |
| 1202 | } |
| 1203 | fossil_print("%-12s%s\n", "name:", zName); |
| 1204 | whatis_rid(rid, mFlags); |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | /* |
| 1209 |