Fossil SCM

Enhance the "whatis" command to report on attachments and to include raw tags so that cluster artifacts are identified. Add the "test-whatis-all" command to run "whatis" on every artifact in the repository.

drh 2014-03-14 13:57 trunk
Commit 5cdc39dc2d532b4d5b308bb0a1ff191f2c5b098d
2 files changed +1 +107 -19
--- src/comformat.c
+++ src/comformat.c
@@ -36,10 +36,11 @@
3636
int doIndent = 0;
3737
char *zBuf;
3838
char zBuffer[400];
3939
int lineCnt = 0;
4040
41
+ if( zText==0 ) zText = "(NULL)";
4142
if( tlen<=0 ){
4243
tlen = strlen(zText);
4344
}
4445
if( tlen >= (sizeof(zBuffer)) ){
4546
zBuf = fossil_malloc(tlen+1);
4647
--- src/comformat.c
+++ src/comformat.c
@@ -36,10 +36,11 @@
36 int doIndent = 0;
37 char *zBuf;
38 char zBuffer[400];
39 int lineCnt = 0;
40
 
41 if( tlen<=0 ){
42 tlen = strlen(zText);
43 }
44 if( tlen >= (sizeof(zBuffer)) ){
45 zBuf = fossil_malloc(tlen+1);
46
--- src/comformat.c
+++ src/comformat.c
@@ -36,10 +36,11 @@
36 int doIndent = 0;
37 char *zBuf;
38 char zBuffer[400];
39 int lineCnt = 0;
40
41 if( zText==0 ) zText = "(NULL)";
42 if( tlen<=0 ){
43 tlen = strlen(zText);
44 }
45 if( tlen >= (sizeof(zBuffer)) ){
46 zBuf = fossil_malloc(tlen+1);
47
+107 -19
--- src/name.c
+++ src/name.c
@@ -439,36 +439,69 @@
439439
/*
440440
** Generate a description of artifact "rid"
441441
*/
442442
static void whatis_rid(int rid, int verboseFlag){
443443
Stmt q;
444
+ int cnt;
445
+
446
+ /* Basic information about the object. */
444447
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)"
448
+ "SELECT uuid, size, datetime(mtime%s), ipaddr"
449449
" FROM blob, rcvfrom"
450450
" WHERE rid=%d"
451451
" AND rcvfrom.rcvid=blob.rcvid",
452452
timeline_utc(), rid);
453453
if( db_step(&q)==SQLITE_ROW ){
454454
const char *zTagList = db_column_text(&q, 4);
455455
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",
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",
459459
db_column_text(&q, 2),
460460
db_column_text(&q, 3));
461461
}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);
462
+ fossil_print("artifact: %s\n", db_column_text(&q,0));
463
+ fossil_print("size: %d bytes\n", db_column_int(&q,1));
467464
}
468465
}
469466
db_finalize(&q);
467
+
468
+ /* Report any symbolic tags on this artifact */
469
+ db_prepare(&q,
470
+ "SELECT substr(tagname,5)"
471
+ " FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
472
+ " WHERE tagxref.rid=%d"
473
+ " AND tagname GLOB 'sym-*'"
474
+ " ORDER BY 1",
475
+ rid
476
+ );
477
+ cnt = 0;
478
+ while( db_step(&q)==SQLITE_ROW ){
479
+ const char *zPrefix = cnt++ ? ", " : "tags: ";
480
+ fossil_print("%s%s", zPrefix, db_column_text(&q,0));
481
+ }
482
+ if( cnt ) fossil_print("\n");
483
+ db_finalize(&q);
484
+
485
+ /* Report any HIDDEN, PRIVATE, CLUSTER, or CLOSED tags on this artifact */
486
+ db_prepare(&q,
487
+ "SELECT tagname"
488
+ " FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
489
+ " WHERE tagxref.rid=%d"
490
+ " AND tag.tagid IN (5,6,7,9)"
491
+ " ORDER BY 1",
492
+ rid, rid
493
+ );
494
+ cnt = 0;
495
+ while( db_step(&q)==SQLITE_ROW ){
496
+ const char *zPrefix = cnt++ ? ", " : "raw-tags: ";
497
+ fossil_print("%s%s", zPrefix, db_column_text(&q,0));
498
+ }
499
+ if( cnt ) fossil_print("\n");
500
+ db_finalize(&q);
501
+
502
+ /* Check for entries on the timeline that reference this object */
470503
db_prepare(&q,
471504
"SELECT type, datetime(mtime%s),"
472505
" coalesce(euser,user), coalesce(ecomment,comment)"
473506
" FROM event WHERE objid=%d", timeline_utc(), rid);
474507
if( db_step(&q)==SQLITE_ROW ){
@@ -479,16 +512,18 @@
479512
case 'e': zType = "Event"; break;
480513
case 't': zType = "Ticket-change"; break;
481514
case 'g': zType = "Tag-change"; break;
482515
default: zType = "Unknown"; break;
483516
}
484
- fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2),
517
+ fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2),
485518
db_column_text(&q, 1));
486
- fossil_print("comment: ");
487
- comment_print(db_column_text(&q,3), 10, 78);
519
+ fossil_print("comment: ");
520
+ comment_print(db_column_text(&q,3), 12, 78);
488521
}
489522
db_finalize(&q);
523
+
524
+ /* Check to see if this object is used as a file in a check-in */
490525
db_prepare(&q,
491526
"SELECT filename.name, blob.uuid, datetime(event.mtime%s),"
492527
" coalesce(euser,user), coalesce(ecomment,comment)"
493528
" FROM mlink, filename, blob, event"
494529
" WHERE mlink.fid=%d"
@@ -496,17 +531,52 @@
496531
" AND event.objid=mlink.mid"
497532
" AND blob.rid=mlink.mid"
498533
" ORDER BY event.mtime DESC /*sort*/",
499534
timeline_utc(), rid);
500535
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",
536
+ fossil_print("file: %s\n", db_column_text(&q,0));
537
+ fossil_print(" part of [%.10s] by %s on %s\n",
503538
db_column_text(&q, 1),
504539
db_column_text(&q, 3),
505540
db_column_text(&q, 2));
506
- fossil_print(" ");
507
- comment_print(db_column_text(&q,4), 10, 78);
541
+ fossil_print(" ");
542
+ comment_print(db_column_text(&q,4), 12, 78);
543
+ }
544
+ db_finalize(&q);
545
+
546
+ /* Check to see if this object is used as an attachment */
547
+ db_prepare(&q,
548
+ "SELECT attachment.filename,"
549
+ " attachment.comment,"
550
+ " attachment.user,"
551
+ " datetime(attachment.mtime%s),"
552
+ " attachment.target,"
553
+ " CASE WHEN EXISTS(SELECT 1 FROM tag WHERE tagname=('tkt-'||target))"
554
+ " THEN 'ticket'"
555
+ " WHEN EXISTS(SELECT 1 FROM tag WHERE tagname=('wiki-'||target))"
556
+ " THEN 'wiki' END,"
557
+ " attachment.attachid,"
558
+ " (SELECT uuid FROM blob WHERE rid=attachid)"
559
+ " FROM attachment JOIN blob ON attachment.src=blob.uuid"
560
+ " WHERE blob.rid=%d",
561
+ timeline_utc(), rid
562
+ );
563
+ while( db_step(&q)==SQLITE_ROW ){
564
+ fossil_print("attachment: %s\n", db_column_text(&q,0));
565
+ fossil_print(" attached to %s %s\n",
566
+ db_column_text(&q,5), db_column_text(&q,4));
567
+ if( verboseFlag ){
568
+ fossil_print(" via %s (%d)\n",
569
+ db_column_text(&q,7), db_column_int(&q,6));
570
+ }else{
571
+ fossil_print(" via %s\n",
572
+ db_column_text(&q,7));
573
+ }
574
+ fossil_print(" by user %s on %s\n",
575
+ db_column_text(&q,2), db_column_text(&q,3));
576
+ fossil_print(" ");
577
+ comment_print(db_column_text(&q,1), 12, 78);
508578
}
509579
db_finalize(&q);
510580
}
511581
512582
/*
@@ -543,5 +613,23 @@
543613
fossil_print("Unknown artifact: %s\n", zName);
544614
}else{
545615
whatis_rid(rid, verboseFlag);
546616
}
547617
}
618
+
619
+/*
620
+** COMMAND: test-whatis-all
621
+** Usage: %fossil test-whatis-all
622
+**
623
+** Show "whatis" information about every artifact in the repository
624
+*/
625
+void test_whatis_all_cmd(void){
626
+ Stmt q;
627
+ int cnt = 0;
628
+ db_find_and_open_repository(0,0);
629
+ db_prepare(&q, "SELECT rid FROM blob ORDER BY rid");
630
+ while( db_step(&q)==SQLITE_ROW ){
631
+ if( cnt++ ) fossil_print("%.79c\n", '-');
632
+ whatis_rid(db_column_int(&q,0), 1);
633
+ }
634
+ db_finalize(&q);
635
+}
548636
--- src/name.c
+++ src/name.c
@@ -439,36 +439,69 @@
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 ){
@@ -479,16 +512,18 @@
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"
@@ -496,17 +531,52 @@
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 /*
@@ -543,5 +613,23 @@
543 fossil_print("Unknown artifact: %s\n", zName);
544 }else{
545 whatis_rid(rid, verboseFlag);
546 }
547 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
548
--- src/name.c
+++ src/name.c
@@ -439,36 +439,69 @@
439 /*
440 ** Generate a description of artifact "rid"
441 */
442 static void whatis_rid(int rid, int verboseFlag){
443 Stmt q;
444 int cnt;
445
446 /* Basic information about the object. */
447 db_prepare(&q,
448 "SELECT uuid, size, datetime(mtime%s), ipaddr"
 
 
 
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 }
466 db_finalize(&q);
467
468 /* Report any symbolic tags on this artifact */
469 db_prepare(&q,
470 "SELECT substr(tagname,5)"
471 " FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
472 " WHERE tagxref.rid=%d"
473 " AND tagname GLOB 'sym-*'"
474 " ORDER BY 1",
475 rid
476 );
477 cnt = 0;
478 while( db_step(&q)==SQLITE_ROW ){
479 const char *zPrefix = cnt++ ? ", " : "tags: ";
480 fossil_print("%s%s", zPrefix, db_column_text(&q,0));
481 }
482 if( cnt ) fossil_print("\n");
483 db_finalize(&q);
484
485 /* Report any HIDDEN, PRIVATE, CLUSTER, or CLOSED tags on this artifact */
486 db_prepare(&q,
487 "SELECT tagname"
488 " FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
489 " WHERE tagxref.rid=%d"
490 " AND tag.tagid IN (5,6,7,9)"
491 " ORDER BY 1",
492 rid, rid
493 );
494 cnt = 0;
495 while( db_step(&q)==SQLITE_ROW ){
496 const char *zPrefix = cnt++ ? ", " : "raw-tags: ";
497 fossil_print("%s%s", zPrefix, db_column_text(&q,0));
498 }
499 if( cnt ) fossil_print("\n");
500 db_finalize(&q);
501
502 /* Check for entries on the timeline that reference this object */
503 db_prepare(&q,
504 "SELECT type, datetime(mtime%s),"
505 " coalesce(euser,user), coalesce(ecomment,comment)"
506 " FROM event WHERE objid=%d", timeline_utc(), rid);
507 if( db_step(&q)==SQLITE_ROW ){
@@ -479,16 +512,18 @@
512 case 'e': zType = "Event"; break;
513 case 't': zType = "Ticket-change"; break;
514 case 'g': zType = "Tag-change"; break;
515 default: zType = "Unknown"; break;
516 }
517 fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2),
518 db_column_text(&q, 1));
519 fossil_print("comment: ");
520 comment_print(db_column_text(&q,3), 12, 78);
521 }
522 db_finalize(&q);
523
524 /* Check to see if this object is used as a file in a check-in */
525 db_prepare(&q,
526 "SELECT filename.name, blob.uuid, datetime(event.mtime%s),"
527 " coalesce(euser,user), coalesce(ecomment,comment)"
528 " FROM mlink, filename, blob, event"
529 " WHERE mlink.fid=%d"
@@ -496,17 +531,52 @@
531 " AND event.objid=mlink.mid"
532 " AND blob.rid=mlink.mid"
533 " ORDER BY event.mtime DESC /*sort*/",
534 timeline_utc(), rid);
535 while( db_step(&q)==SQLITE_ROW ){
536 fossil_print("file: %s\n", db_column_text(&q,0));
537 fossil_print(" part of [%.10s] by %s on %s\n",
538 db_column_text(&q, 1),
539 db_column_text(&q, 3),
540 db_column_text(&q, 2));
541 fossil_print(" ");
542 comment_print(db_column_text(&q,4), 12, 78);
543 }
544 db_finalize(&q);
545
546 /* Check to see if this object is used as an attachment */
547 db_prepare(&q,
548 "SELECT attachment.filename,"
549 " attachment.comment,"
550 " attachment.user,"
551 " datetime(attachment.mtime%s),"
552 " attachment.target,"
553 " CASE WHEN EXISTS(SELECT 1 FROM tag WHERE tagname=('tkt-'||target))"
554 " THEN 'ticket'"
555 " WHEN EXISTS(SELECT 1 FROM tag WHERE tagname=('wiki-'||target))"
556 " THEN 'wiki' END,"
557 " attachment.attachid,"
558 " (SELECT uuid FROM blob WHERE rid=attachid)"
559 " FROM attachment JOIN blob ON attachment.src=blob.uuid"
560 " WHERE blob.rid=%d",
561 timeline_utc(), rid
562 );
563 while( db_step(&q)==SQLITE_ROW ){
564 fossil_print("attachment: %s\n", db_column_text(&q,0));
565 fossil_print(" attached to %s %s\n",
566 db_column_text(&q,5), db_column_text(&q,4));
567 if( verboseFlag ){
568 fossil_print(" via %s (%d)\n",
569 db_column_text(&q,7), db_column_int(&q,6));
570 }else{
571 fossil_print(" via %s\n",
572 db_column_text(&q,7));
573 }
574 fossil_print(" by user %s on %s\n",
575 db_column_text(&q,2), db_column_text(&q,3));
576 fossil_print(" ");
577 comment_print(db_column_text(&q,1), 12, 78);
578 }
579 db_finalize(&q);
580 }
581
582 /*
@@ -543,5 +613,23 @@
613 fossil_print("Unknown artifact: %s\n", zName);
614 }else{
615 whatis_rid(rid, verboseFlag);
616 }
617 }
618
619 /*
620 ** COMMAND: test-whatis-all
621 ** Usage: %fossil test-whatis-all
622 **
623 ** Show "whatis" information about every artifact in the repository
624 */
625 void test_whatis_all_cmd(void){
626 Stmt q;
627 int cnt = 0;
628 db_find_and_open_repository(0,0);
629 db_prepare(&q, "SELECT rid FROM blob ORDER BY rid");
630 while( db_step(&q)==SQLITE_ROW ){
631 if( cnt++ ) fossil_print("%.79c\n", '-');
632 whatis_rid(db_column_int(&q,0), 1);
633 }
634 db_finalize(&q);
635 }
636

Keyboard Shortcuts

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