Fossil SCM
Add the "whatis" command.
Commit
9c3ce9f6e28755955b596c982001d7f1e5744757
Parent
dde919a4639e1bc…
1 file changed
+83
+83
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -375,5 +375,88 @@ | ||
| 375 | 375 | cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath); |
| 376 | 376 | rid = 0; |
| 377 | 377 | } |
| 378 | 378 | return rid; |
| 379 | 379 | } |
| 380 | + | |
| 381 | +/* | |
| 382 | +** COMMAND: whatis* | |
| 383 | +** Usage: %fossil whatis NAME | |
| 384 | +** | |
| 385 | +** Resolve the symbol NAME into its canonical 40-character SHA1-hash | |
| 386 | +** artifact name and provide a description of what role that artifact | |
| 387 | +** plays. | |
| 388 | +*/ | |
| 389 | +void whatis_cmd(void){ | |
| 390 | + int rid; | |
| 391 | + const char *zName; | |
| 392 | + int fExtra; | |
| 393 | + db_find_and_open_repository(0,0); | |
| 394 | + fExtra = find_option("verbose","v",0)!=0; | |
| 395 | + if( g.argc!=3 ) usage("whatis NAME"); | |
| 396 | + zName = g.argv[2]; | |
| 397 | + rid = symbolic_name_to_rid(zName, 0); | |
| 398 | + if( rid<0 ){ | |
| 399 | + fossil_print("Ambiguous artifact name prefix: %s\n", zName); | |
| 400 | + }else if( rid==0 ){ | |
| 401 | + fossil_print("Unknown artifact: %s\n", zName); | |
| 402 | + }else{ | |
| 403 | + Stmt q; | |
| 404 | + db_prepare(&q, "SELECT uuid, size, datetime(mtime, 'localtime'), ipaddr" | |
| 405 | + " FROM blob, rcvfrom" | |
| 406 | + " WHERE rid=%d" | |
| 407 | + " AND rcvfrom.rcvid=blob.rcvid", | |
| 408 | + rid); | |
| 409 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 410 | + if( fExtra ){ | |
| 411 | + fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid); | |
| 412 | + fossil_print("size: %d bytes\n", db_column_int(&q,1)); | |
| 413 | + fossil_print("received: %s from %s\n", | |
| 414 | + db_column_text(&q, 2), | |
| 415 | + db_column_text(&q, 3)); | |
| 416 | + }else{ | |
| 417 | + fossil_print("artifact: %s\n", db_column_text(&q,0)); | |
| 418 | + fossil_print("size: %d bytes\n", db_column_int(&q,1)); | |
| 419 | + } | |
| 420 | + } | |
| 421 | + db_finalize(&q); | |
| 422 | + db_prepare(&q, | |
| 423 | + "SELECT type, datetime(mtime,'localtime')," | |
| 424 | + " coalesce(euser,user), coalesce(ecomment,comment)" | |
| 425 | + " FROM event WHERE objid=%d", rid); | |
| 426 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 427 | + const char *zType; | |
| 428 | + switch( db_column_text(&q,0)[0] ){ | |
| 429 | + case 'c': zType = "Check-in"; break; | |
| 430 | + case 'w': zType = "Wiki-edit"; break; | |
| 431 | + case 'e': zType = "Event"; break; | |
| 432 | + case 't': zType = "Ticket-change"; break; | |
| 433 | + case 'g': zType = "Tag-change"; break; | |
| 434 | + } | |
| 435 | + fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2), | |
| 436 | + db_column_text(&q, 1)); | |
| 437 | + fossil_print("comment: "); | |
| 438 | + comment_print(db_column_text(&q,3), 10, 78); | |
| 439 | + } | |
| 440 | + db_finalize(&q); | |
| 441 | + db_prepare(&q, | |
| 442 | + "SELECT filename.name, blob.uuid, datetime(event.mtime,'localtime')," | |
| 443 | + " coalesce(euser,user), coalesce(ecomment,comment)" | |
| 444 | + " FROM mlink, filename, blob, event" | |
| 445 | + " WHERE mlink.fid=%d" | |
| 446 | + " AND filename.fnid=mlink.fnid" | |
| 447 | + " AND event.objid=mlink.mid" | |
| 448 | + " AND blob.rid=mlink.mid" | |
| 449 | + " ORDER BY event.mtime DESC /*sort*/", | |
| 450 | + rid); | |
| 451 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 452 | + fossil_print("file: %s\n", db_column_text(&q,0)); | |
| 453 | + fossil_print(" part of [%.10s] by %s on %s\n", | |
| 454 | + db_column_text(&q, 1), | |
| 455 | + db_column_text(&q, 3), | |
| 456 | + db_column_text(&q, 2)); | |
| 457 | + fossil_print(" "); | |
| 458 | + comment_print(db_column_text(&q,4), 10, 78); | |
| 459 | + } | |
| 460 | + db_finalize(&q); | |
| 461 | + } | |
| 462 | +} | |
| 380 | 463 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -375,5 +375,88 @@ | |
| 375 | cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath); |
| 376 | rid = 0; |
| 377 | } |
| 378 | return rid; |
| 379 | } |
| 380 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -375,5 +375,88 @@ | |
| 375 | cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath); |
| 376 | rid = 0; |
| 377 | } |
| 378 | return rid; |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | ** COMMAND: whatis* |
| 383 | ** Usage: %fossil whatis NAME |
| 384 | ** |
| 385 | ** Resolve the symbol NAME into its canonical 40-character SHA1-hash |
| 386 | ** artifact name and provide a description of what role that artifact |
| 387 | ** plays. |
| 388 | */ |
| 389 | void whatis_cmd(void){ |
| 390 | int rid; |
| 391 | const char *zName; |
| 392 | int fExtra; |
| 393 | db_find_and_open_repository(0,0); |
| 394 | fExtra = find_option("verbose","v",0)!=0; |
| 395 | if( g.argc!=3 ) usage("whatis NAME"); |
| 396 | zName = g.argv[2]; |
| 397 | rid = symbolic_name_to_rid(zName, 0); |
| 398 | if( rid<0 ){ |
| 399 | fossil_print("Ambiguous artifact name prefix: %s\n", zName); |
| 400 | }else if( rid==0 ){ |
| 401 | fossil_print("Unknown artifact: %s\n", zName); |
| 402 | }else{ |
| 403 | Stmt q; |
| 404 | db_prepare(&q, "SELECT uuid, size, datetime(mtime, 'localtime'), ipaddr" |
| 405 | " FROM blob, rcvfrom" |
| 406 | " WHERE rid=%d" |
| 407 | " AND rcvfrom.rcvid=blob.rcvid", |
| 408 | rid); |
| 409 | if( db_step(&q)==SQLITE_ROW ){ |
| 410 | if( fExtra ){ |
| 411 | fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid); |
| 412 | fossil_print("size: %d bytes\n", db_column_int(&q,1)); |
| 413 | fossil_print("received: %s from %s\n", |
| 414 | db_column_text(&q, 2), |
| 415 | db_column_text(&q, 3)); |
| 416 | }else{ |
| 417 | fossil_print("artifact: %s\n", db_column_text(&q,0)); |
| 418 | fossil_print("size: %d bytes\n", db_column_int(&q,1)); |
| 419 | } |
| 420 | } |
| 421 | db_finalize(&q); |
| 422 | db_prepare(&q, |
| 423 | "SELECT type, datetime(mtime,'localtime')," |
| 424 | " coalesce(euser,user), coalesce(ecomment,comment)" |
| 425 | " FROM event WHERE objid=%d", rid); |
| 426 | if( db_step(&q)==SQLITE_ROW ){ |
| 427 | const char *zType; |
| 428 | switch( db_column_text(&q,0)[0] ){ |
| 429 | case 'c': zType = "Check-in"; break; |
| 430 | case 'w': zType = "Wiki-edit"; break; |
| 431 | case 'e': zType = "Event"; break; |
| 432 | case 't': zType = "Ticket-change"; break; |
| 433 | case 'g': zType = "Tag-change"; break; |
| 434 | } |
| 435 | fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2), |
| 436 | db_column_text(&q, 1)); |
| 437 | fossil_print("comment: "); |
| 438 | comment_print(db_column_text(&q,3), 10, 78); |
| 439 | } |
| 440 | db_finalize(&q); |
| 441 | db_prepare(&q, |
| 442 | "SELECT filename.name, blob.uuid, datetime(event.mtime,'localtime')," |
| 443 | " coalesce(euser,user), coalesce(ecomment,comment)" |
| 444 | " FROM mlink, filename, blob, event" |
| 445 | " WHERE mlink.fid=%d" |
| 446 | " AND filename.fnid=mlink.fnid" |
| 447 | " AND event.objid=mlink.mid" |
| 448 | " AND blob.rid=mlink.mid" |
| 449 | " ORDER BY event.mtime DESC /*sort*/", |
| 450 | rid); |
| 451 | while( db_step(&q)==SQLITE_ROW ){ |
| 452 | fossil_print("file: %s\n", db_column_text(&q,0)); |
| 453 | fossil_print(" part of [%.10s] by %s on %s\n", |
| 454 | db_column_text(&q, 1), |
| 455 | db_column_text(&q, 3), |
| 456 | db_column_text(&q, 2)); |
| 457 | fossil_print(" "); |
| 458 | comment_print(db_column_text(&q,4), 10, 78); |
| 459 | } |
| 460 | db_finalize(&q); |
| 461 | } |
| 462 | } |
| 463 |