Fossil SCM
Add the test-ambiguous command for finding ambiguous SHA1-hash abbreviations.
Commit
2aaae64a592d4fd36b3f561cda4acf71515abccc
Parent
49467d2a494aae8…
1 file changed
+49
+49
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -698,5 +698,54 @@ | ||
| 698 | 698 | if( cnt++ ) fossil_print("%.79c\n", '-'); |
| 699 | 699 | whatis_rid(db_column_int(&q,0), 1); |
| 700 | 700 | } |
| 701 | 701 | db_finalize(&q); |
| 702 | 702 | } |
| 703 | + | |
| 704 | + | |
| 705 | +/* | |
| 706 | +** COMMAND: test-ambiguous | |
| 707 | +** Usage: %fossil test-ambiguous [--minsize N] | |
| 708 | +** | |
| 709 | +** Show a list of ambiguous SHA1-hash abbreviations of N characters or | |
| 710 | +** more where N defaults to 4. Change N to a different value using | |
| 711 | +** the "--minsize N" command-line option. | |
| 712 | +*/ | |
| 713 | +void test_ambiguous_cmd(void){ | |
| 714 | + Stmt q, ins; | |
| 715 | + int i; | |
| 716 | + int minSize = 4; | |
| 717 | + const char *zMinsize; | |
| 718 | + char zPrev[100]; | |
| 719 | + db_find_and_open_repository(0,0); | |
| 720 | + zMinsize = find_option("minsize",0,1); | |
| 721 | + if( zMinsize && atoi(zMinsize)>0 ) minSize = atoi(zMinsize); | |
| 722 | + db_multi_exec("CREATE TEMP TABLE dups(uuid, cnt)"); | |
| 723 | + db_prepare(&ins,"INSERT INTO dups(uuid) VALUES(substr(:uuid,1,:cnt))"); | |
| 724 | + db_prepare(&q, | |
| 725 | + "SELECT uuid FROM blob " | |
| 726 | + "UNION " | |
| 727 | + "SELECT substr(tagname,7) FROM tag WHERE tagname GLOB 'event-*' " | |
| 728 | + "UNION " | |
| 729 | + "SELECT tkt_uuid FROM ticket " | |
| 730 | + "ORDER BY 1" | |
| 731 | + ); | |
| 732 | + zPrev[0] = 0; | |
| 733 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 734 | + const char *zUuid = db_column_text(&q, 0); | |
| 735 | + for(i=0; zUuid[i]==zPrev[i] && zUuid[i]!=0; i++){} | |
| 736 | + if( i>=minSize ){ | |
| 737 | + db_bind_int(&ins, ":cnt", i); | |
| 738 | + db_bind_text(&ins, ":uuid", zUuid); | |
| 739 | + db_step(&ins); | |
| 740 | + db_reset(&ins); | |
| 741 | + } | |
| 742 | + strcpy(zPrev, zUuid); | |
| 743 | + } | |
| 744 | + db_finalize(&ins); | |
| 745 | + db_finalize(&q); | |
| 746 | + db_prepare(&q, "SELECT uuid FROM dups ORDER BY length(uuid) DESC, uuid"); | |
| 747 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 748 | + fossil_print("%s\n", db_column_text(&q, 0)); | |
| 749 | + } | |
| 750 | + db_finalize(&q); | |
| 751 | +} | |
| 703 | 752 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -698,5 +698,54 @@ | |
| 698 | if( cnt++ ) fossil_print("%.79c\n", '-'); |
| 699 | whatis_rid(db_column_int(&q,0), 1); |
| 700 | } |
| 701 | db_finalize(&q); |
| 702 | } |
| 703 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -698,5 +698,54 @@ | |
| 698 | if( cnt++ ) fossil_print("%.79c\n", '-'); |
| 699 | whatis_rid(db_column_int(&q,0), 1); |
| 700 | } |
| 701 | db_finalize(&q); |
| 702 | } |
| 703 | |
| 704 | |
| 705 | /* |
| 706 | ** COMMAND: test-ambiguous |
| 707 | ** Usage: %fossil test-ambiguous [--minsize N] |
| 708 | ** |
| 709 | ** Show a list of ambiguous SHA1-hash abbreviations of N characters or |
| 710 | ** more where N defaults to 4. Change N to a different value using |
| 711 | ** the "--minsize N" command-line option. |
| 712 | */ |
| 713 | void test_ambiguous_cmd(void){ |
| 714 | Stmt q, ins; |
| 715 | int i; |
| 716 | int minSize = 4; |
| 717 | const char *zMinsize; |
| 718 | char zPrev[100]; |
| 719 | db_find_and_open_repository(0,0); |
| 720 | zMinsize = find_option("minsize",0,1); |
| 721 | if( zMinsize && atoi(zMinsize)>0 ) minSize = atoi(zMinsize); |
| 722 | db_multi_exec("CREATE TEMP TABLE dups(uuid, cnt)"); |
| 723 | db_prepare(&ins,"INSERT INTO dups(uuid) VALUES(substr(:uuid,1,:cnt))"); |
| 724 | db_prepare(&q, |
| 725 | "SELECT uuid FROM blob " |
| 726 | "UNION " |
| 727 | "SELECT substr(tagname,7) FROM tag WHERE tagname GLOB 'event-*' " |
| 728 | "UNION " |
| 729 | "SELECT tkt_uuid FROM ticket " |
| 730 | "ORDER BY 1" |
| 731 | ); |
| 732 | zPrev[0] = 0; |
| 733 | while( db_step(&q)==SQLITE_ROW ){ |
| 734 | const char *zUuid = db_column_text(&q, 0); |
| 735 | for(i=0; zUuid[i]==zPrev[i] && zUuid[i]!=0; i++){} |
| 736 | if( i>=minSize ){ |
| 737 | db_bind_int(&ins, ":cnt", i); |
| 738 | db_bind_text(&ins, ":uuid", zUuid); |
| 739 | db_step(&ins); |
| 740 | db_reset(&ins); |
| 741 | } |
| 742 | strcpy(zPrev, zUuid); |
| 743 | } |
| 744 | db_finalize(&ins); |
| 745 | db_finalize(&q); |
| 746 | db_prepare(&q, "SELECT uuid FROM dups ORDER BY length(uuid) DESC, uuid"); |
| 747 | while( db_step(&q)==SQLITE_ROW ){ |
| 748 | fossil_print("%s\n", db_column_text(&q, 0)); |
| 749 | } |
| 750 | db_finalize(&q); |
| 751 | } |
| 752 |