Fossil SCM

Enhance the "whatis" command so that if given an ambiguous SHA1 hash prefix it shows "what is" all possible values for that hash prefix.

drh 2014-03-14 12:30 trunk
Commit 933904fe703a116c7b6775019fed5ee6cbbb0f12
1 file changed +85 -67
+85 -67
--- src/name.c
+++ src/name.c
@@ -433,10 +433,83 @@
433433
cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath);
434434
rid = 0;
435435
}
436436
return rid;
437437
}
438
+
439
+/*
440
+** Generate a description of artifact "rid"
441
+*/
442
+static void whatis_rid(int rid, int verboseFlag){
443
+ Stmt q;
444
+ db_prepare(&q,
445
+ "SELECT uuid, size, datetime(mtime%s), ipaddr,"
446
+ " (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref"
447
+ " WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid"
448
+ " AND tagxref.rid=blob.rid AND tagxref.tagtype>0)"
449
+ " FROM blob, rcvfrom"
450
+ " WHERE rid=%d"
451
+ " AND rcvfrom.rcvid=blob.rcvid",
452
+ timeline_utc(), rid);
453
+ if( db_step(&q)==SQLITE_ROW ){
454
+ const char *zTagList = db_column_text(&q, 4);
455
+ if( verboseFlag ){
456
+ fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
457
+ fossil_print("size: %d bytes\n", db_column_int(&q,1));
458
+ fossil_print("received: %s from %s\n",
459
+ db_column_text(&q, 2),
460
+ db_column_text(&q, 3));
461
+ }else{
462
+ fossil_print("artifact: %s\n", db_column_text(&q,0));
463
+ fossil_print("size: %d bytes\n", db_column_int(&q,1));
464
+ }
465
+ if( zTagList && zTagList[0] ){
466
+ fossil_print("tags: %s\n", zTagList);
467
+ }
468
+ }
469
+ db_finalize(&q);
470
+ db_prepare(&q,
471
+ "SELECT type, datetime(mtime%s),"
472
+ " coalesce(euser,user), coalesce(ecomment,comment)"
473
+ " FROM event WHERE objid=%d", timeline_utc(), rid);
474
+ if( db_step(&q)==SQLITE_ROW ){
475
+ const char *zType;
476
+ switch( db_column_text(&q,0)[0] ){
477
+ case 'c': zType = "Check-in"; break;
478
+ case 'w': zType = "Wiki-edit"; break;
479
+ case 'e': zType = "Event"; break;
480
+ case 't': zType = "Ticket-change"; break;
481
+ case 'g': zType = "Tag-change"; break;
482
+ default: zType = "Unknown"; break;
483
+ }
484
+ fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2),
485
+ db_column_text(&q, 1));
486
+ fossil_print("comment: ");
487
+ comment_print(db_column_text(&q,3), 10, 78);
488
+ }
489
+ db_finalize(&q);
490
+ db_prepare(&q,
491
+ "SELECT filename.name, blob.uuid, datetime(event.mtime%s),"
492
+ " coalesce(euser,user), coalesce(ecomment,comment)"
493
+ " FROM mlink, filename, blob, event"
494
+ " WHERE mlink.fid=%d"
495
+ " AND filename.fnid=mlink.fnid"
496
+ " AND event.objid=mlink.mid"
497
+ " AND blob.rid=mlink.mid"
498
+ " ORDER BY event.mtime DESC /*sort*/",
499
+ timeline_utc(), rid);
500
+ while( db_step(&q)==SQLITE_ROW ){
501
+ fossil_print("file: %s\n", db_column_text(&q,0));
502
+ fossil_print(" part of [%.10s] by %s on %s\n",
503
+ db_column_text(&q, 1),
504
+ db_column_text(&q, 3),
505
+ db_column_text(&q, 2));
506
+ fossil_print(" ");
507
+ comment_print(db_column_text(&q,4), 10, 78);
508
+ }
509
+ db_finalize(&q);
510
+}
438511
439512
/*
440513
** COMMAND: whatis*
441514
** Usage: %fossil whatis NAME
442515
**
@@ -452,78 +525,23 @@
452525
verboseFlag = find_option("verbose","v",0)!=0;
453526
if( g.argc!=3 ) usage("whatis NAME");
454527
zName = g.argv[2];
455528
rid = symbolic_name_to_rid(zName, 0);
456529
if( rid<0 ){
530
+ Stmt q;
531
+ int cnt = 0;
457532
fossil_print("Ambiguous artifact name prefix: %s\n", zName);
533
+ db_prepare(&q,
534
+ "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
535
+ zName, zName
536
+ );
537
+ while( db_step(&q)==SQLITE_ROW ){
538
+ if( cnt++ ) fossil_print("%.79c\n", '-');
539
+ whatis_rid(db_column_int(&q, 0), verboseFlag);
540
+ }
541
+ db_finalize(&q);
458542
}else if( rid==0 ){
459543
fossil_print("Unknown artifact: %s\n", zName);
460544
}else{
461
- Stmt q;
462
- db_prepare(&q,
463
- "SELECT uuid, size, datetime(mtime%s), ipaddr,"
464
- " (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref"
465
- " WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid"
466
- " AND tagxref.rid=blob.rid AND tagxref.tagtype>0)"
467
- " FROM blob, rcvfrom"
468
- " WHERE rid=%d"
469
- " AND rcvfrom.rcvid=blob.rcvid",
470
- timeline_utc(), rid);
471
- if( db_step(&q)==SQLITE_ROW ){
472
- const char *zTagList = db_column_text(&q, 4);
473
- if( verboseFlag ){
474
- fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
475
- fossil_print("size: %d bytes\n", db_column_int(&q,1));
476
- fossil_print("received: %s from %s\n",
477
- db_column_text(&q, 2),
478
- db_column_text(&q, 3));
479
- }else{
480
- fossil_print("artifact: %s\n", db_column_text(&q,0));
481
- fossil_print("size: %d bytes\n", db_column_int(&q,1));
482
- }
483
- if( zTagList && zTagList[0] ){
484
- fossil_print("tags: %s\n", zTagList);
485
- }
486
- }
487
- db_finalize(&q);
488
- db_prepare(&q,
489
- "SELECT type, datetime(mtime%s),"
490
- " coalesce(euser,user), coalesce(ecomment,comment)"
491
- " FROM event WHERE objid=%d", timeline_utc(), rid);
492
- if( db_step(&q)==SQLITE_ROW ){
493
- const char *zType;
494
- switch( db_column_text(&q,0)[0] ){
495
- case 'c': zType = "Check-in"; break;
496
- case 'w': zType = "Wiki-edit"; break;
497
- case 'e': zType = "Event"; break;
498
- case 't': zType = "Ticket-change"; break;
499
- case 'g': zType = "Tag-change"; break;
500
- default: zType = "Unknown"; break;
501
- }
502
- fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2),
503
- db_column_text(&q, 1));
504
- fossil_print("comment: ");
505
- comment_print(db_column_text(&q,3), 10, 78);
506
- }
507
- db_finalize(&q);
508
- db_prepare(&q,
509
- "SELECT filename.name, blob.uuid, datetime(event.mtime%s),"
510
- " coalesce(euser,user), coalesce(ecomment,comment)"
511
- " FROM mlink, filename, blob, event"
512
- " WHERE mlink.fid=%d"
513
- " AND filename.fnid=mlink.fnid"
514
- " AND event.objid=mlink.mid"
515
- " AND blob.rid=mlink.mid"
516
- " ORDER BY event.mtime DESC /*sort*/",
517
- timeline_utc(), rid);
518
- while( db_step(&q)==SQLITE_ROW ){
519
- fossil_print("file: %s\n", db_column_text(&q,0));
520
- fossil_print(" part of [%.10s] by %s on %s\n",
521
- db_column_text(&q, 1),
522
- db_column_text(&q, 3),
523
- db_column_text(&q, 2));
524
- fossil_print(" ");
525
- comment_print(db_column_text(&q,4), 10, 78);
526
- }
527
- db_finalize(&q);
545
+ whatis_rid(rid, verboseFlag);
528546
}
529547
}
530548
--- src/name.c
+++ src/name.c
@@ -433,10 +433,83 @@
433 cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath);
434 rid = 0;
435 }
436 return rid;
437 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
439 /*
440 ** COMMAND: whatis*
441 ** Usage: %fossil whatis NAME
442 **
@@ -452,78 +525,23 @@
452 verboseFlag = find_option("verbose","v",0)!=0;
453 if( g.argc!=3 ) usage("whatis NAME");
454 zName = g.argv[2];
455 rid = symbolic_name_to_rid(zName, 0);
456 if( rid<0 ){
 
 
457 fossil_print("Ambiguous artifact name prefix: %s\n", zName);
 
 
 
 
 
 
 
 
 
458 }else if( rid==0 ){
459 fossil_print("Unknown artifact: %s\n", zName);
460 }else{
461 Stmt q;
462 db_prepare(&q,
463 "SELECT uuid, size, datetime(mtime%s), ipaddr,"
464 " (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref"
465 " WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid"
466 " AND tagxref.rid=blob.rid AND tagxref.tagtype>0)"
467 " FROM blob, rcvfrom"
468 " WHERE rid=%d"
469 " AND rcvfrom.rcvid=blob.rcvid",
470 timeline_utc(), rid);
471 if( db_step(&q)==SQLITE_ROW ){
472 const char *zTagList = db_column_text(&q, 4);
473 if( verboseFlag ){
474 fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
475 fossil_print("size: %d bytes\n", db_column_int(&q,1));
476 fossil_print("received: %s from %s\n",
477 db_column_text(&q, 2),
478 db_column_text(&q, 3));
479 }else{
480 fossil_print("artifact: %s\n", db_column_text(&q,0));
481 fossil_print("size: %d bytes\n", db_column_int(&q,1));
482 }
483 if( zTagList && zTagList[0] ){
484 fossil_print("tags: %s\n", zTagList);
485 }
486 }
487 db_finalize(&q);
488 db_prepare(&q,
489 "SELECT type, datetime(mtime%s),"
490 " coalesce(euser,user), coalesce(ecomment,comment)"
491 " FROM event WHERE objid=%d", timeline_utc(), rid);
492 if( db_step(&q)==SQLITE_ROW ){
493 const char *zType;
494 switch( db_column_text(&q,0)[0] ){
495 case 'c': zType = "Check-in"; break;
496 case 'w': zType = "Wiki-edit"; break;
497 case 'e': zType = "Event"; break;
498 case 't': zType = "Ticket-change"; break;
499 case 'g': zType = "Tag-change"; break;
500 default: zType = "Unknown"; break;
501 }
502 fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2),
503 db_column_text(&q, 1));
504 fossil_print("comment: ");
505 comment_print(db_column_text(&q,3), 10, 78);
506 }
507 db_finalize(&q);
508 db_prepare(&q,
509 "SELECT filename.name, blob.uuid, datetime(event.mtime%s),"
510 " coalesce(euser,user), coalesce(ecomment,comment)"
511 " FROM mlink, filename, blob, event"
512 " WHERE mlink.fid=%d"
513 " AND filename.fnid=mlink.fnid"
514 " AND event.objid=mlink.mid"
515 " AND blob.rid=mlink.mid"
516 " ORDER BY event.mtime DESC /*sort*/",
517 timeline_utc(), rid);
518 while( db_step(&q)==SQLITE_ROW ){
519 fossil_print("file: %s\n", db_column_text(&q,0));
520 fossil_print(" part of [%.10s] by %s on %s\n",
521 db_column_text(&q, 1),
522 db_column_text(&q, 3),
523 db_column_text(&q, 2));
524 fossil_print(" ");
525 comment_print(db_column_text(&q,4), 10, 78);
526 }
527 db_finalize(&q);
528 }
529 }
530
--- src/name.c
+++ src/name.c
@@ -433,10 +433,83 @@
433 cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath);
434 rid = 0;
435 }
436 return rid;
437 }
438
439 /*
440 ** Generate a description of artifact "rid"
441 */
442 static void whatis_rid(int rid, int verboseFlag){
443 Stmt q;
444 db_prepare(&q,
445 "SELECT uuid, size, datetime(mtime%s), ipaddr,"
446 " (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref"
447 " WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid"
448 " AND tagxref.rid=blob.rid AND tagxref.tagtype>0)"
449 " FROM blob, rcvfrom"
450 " WHERE rid=%d"
451 " AND rcvfrom.rcvid=blob.rcvid",
452 timeline_utc(), rid);
453 if( db_step(&q)==SQLITE_ROW ){
454 const char *zTagList = db_column_text(&q, 4);
455 if( verboseFlag ){
456 fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
457 fossil_print("size: %d bytes\n", db_column_int(&q,1));
458 fossil_print("received: %s from %s\n",
459 db_column_text(&q, 2),
460 db_column_text(&q, 3));
461 }else{
462 fossil_print("artifact: %s\n", db_column_text(&q,0));
463 fossil_print("size: %d bytes\n", db_column_int(&q,1));
464 }
465 if( zTagList && zTagList[0] ){
466 fossil_print("tags: %s\n", zTagList);
467 }
468 }
469 db_finalize(&q);
470 db_prepare(&q,
471 "SELECT type, datetime(mtime%s),"
472 " coalesce(euser,user), coalesce(ecomment,comment)"
473 " FROM event WHERE objid=%d", timeline_utc(), rid);
474 if( db_step(&q)==SQLITE_ROW ){
475 const char *zType;
476 switch( db_column_text(&q,0)[0] ){
477 case 'c': zType = "Check-in"; break;
478 case 'w': zType = "Wiki-edit"; break;
479 case 'e': zType = "Event"; break;
480 case 't': zType = "Ticket-change"; break;
481 case 'g': zType = "Tag-change"; break;
482 default: zType = "Unknown"; break;
483 }
484 fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2),
485 db_column_text(&q, 1));
486 fossil_print("comment: ");
487 comment_print(db_column_text(&q,3), 10, 78);
488 }
489 db_finalize(&q);
490 db_prepare(&q,
491 "SELECT filename.name, blob.uuid, datetime(event.mtime%s),"
492 " coalesce(euser,user), coalesce(ecomment,comment)"
493 " FROM mlink, filename, blob, event"
494 " WHERE mlink.fid=%d"
495 " AND filename.fnid=mlink.fnid"
496 " AND event.objid=mlink.mid"
497 " AND blob.rid=mlink.mid"
498 " ORDER BY event.mtime DESC /*sort*/",
499 timeline_utc(), rid);
500 while( db_step(&q)==SQLITE_ROW ){
501 fossil_print("file: %s\n", db_column_text(&q,0));
502 fossil_print(" part of [%.10s] by %s on %s\n",
503 db_column_text(&q, 1),
504 db_column_text(&q, 3),
505 db_column_text(&q, 2));
506 fossil_print(" ");
507 comment_print(db_column_text(&q,4), 10, 78);
508 }
509 db_finalize(&q);
510 }
511
512 /*
513 ** COMMAND: whatis*
514 ** Usage: %fossil whatis NAME
515 **
@@ -452,78 +525,23 @@
525 verboseFlag = find_option("verbose","v",0)!=0;
526 if( g.argc!=3 ) usage("whatis NAME");
527 zName = g.argv[2];
528 rid = symbolic_name_to_rid(zName, 0);
529 if( rid<0 ){
530 Stmt q;
531 int cnt = 0;
532 fossil_print("Ambiguous artifact name prefix: %s\n", zName);
533 db_prepare(&q,
534 "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
535 zName, zName
536 );
537 while( db_step(&q)==SQLITE_ROW ){
538 if( cnt++ ) fossil_print("%.79c\n", '-');
539 whatis_rid(db_column_int(&q, 0), verboseFlag);
540 }
541 db_finalize(&q);
542 }else if( rid==0 ){
543 fossil_print("Unknown artifact: %s\n", zName);
544 }else{
545 whatis_rid(rid, verboseFlag);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546 }
547 }
548

Keyboard Shortcuts

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