Fossil SCM
Add an "annotate" command to the command-line to suppliment the "annotate" web page.
Commit
73b7faa58b4b457b2c4179863dea9ebfbdac17df
Parent
76f169fca6c0404…
1 file changed
+43
-2
+43
-2
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -710,11 +710,11 @@ | ||
| 710 | 710 | while( db_step(&q)==SQLITE_ROW ){ |
| 711 | 711 | int pid = db_column_int(&q, 0); |
| 712 | 712 | const char *zUuid = db_column_text(&q, 1); |
| 713 | 713 | const char *zDate = db_column_text(&q, 2); |
| 714 | 714 | const char *zUser = db_column_text(&q, 3); |
| 715 | - if( g.okHistory ){ | |
| 715 | + if( webLabel ){ | |
| 716 | 716 | zLabel = mprintf("<a href='%s/info/%s'>%.10s</a> %s %9.9s", |
| 717 | 717 | g.zBaseURL, zUuid, zUuid, zDate, zUser); |
| 718 | 718 | }else{ |
| 719 | 719 | zLabel = mprintf("%.10s %s %9.9s", zUuid, zDate, zUser); |
| 720 | 720 | } |
| @@ -744,14 +744,55 @@ | ||
| 744 | 744 | if( mid==0 || fnid==0 ){ fossil_redirect_home(); } |
| 745 | 745 | if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){ |
| 746 | 746 | fossil_redirect_home(); |
| 747 | 747 | } |
| 748 | 748 | style_header("File Annotation"); |
| 749 | - annotate_file(&ann, fnid, mid, 1); | |
| 749 | + annotate_file(&ann, fnid, mid, g.okHistory); | |
| 750 | 750 | @ <pre> |
| 751 | 751 | for(i=0; i<ann.nOrig; i++){ |
| 752 | 752 | ((char*)ann.aOrig[i].z)[ann.aOrig[i].n] = 0; |
| 753 | 753 | @ %s(ann.aOrig[i].zSrc): %h(ann.aOrig[i].z) |
| 754 | 754 | } |
| 755 | 755 | @ </pre> |
| 756 | 756 | style_footer(); |
| 757 | 757 | } |
| 758 | + | |
| 759 | +/* | |
| 760 | +** COMMAND: annotate | |
| 761 | +** | |
| 762 | +** %fossil annotate FILENAME | |
| 763 | +** | |
| 764 | +** Output the text of a file with markings to show when each line of | |
| 765 | +** the file was introduced. | |
| 766 | +*/ | |
| 767 | +void annotate_cmd(void){ | |
| 768 | + int fnid; /* Filename ID */ | |
| 769 | + int fid; /* File instance ID */ | |
| 770 | + int mid; /* Manifest where file was checked in */ | |
| 771 | + Blob treename; /* FILENAME translated to canonical form */ | |
| 772 | + char *zFilename; /* Cannonical filename */ | |
| 773 | + Annotator ann; /* The annotation of the file */ | |
| 774 | + int i; /* Loop counter */ | |
| 775 | + | |
| 776 | + db_must_be_within_tree(); | |
| 777 | + if (g.argc<3) { | |
| 778 | + usage("FILENAME"); | |
| 779 | + } | |
| 780 | + file_tree_name(g.argv[2], &treename, 1); | |
| 781 | + zFilename = blob_str(&treename); | |
| 782 | + fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q", zFilename); | |
| 783 | + if( fnid==0 ){ | |
| 784 | + fossil_fatal("no such file: %s", zFilename); | |
| 785 | + } | |
| 786 | + fid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFilename); | |
| 787 | + if( fid==0 ){ | |
| 788 | + fossil_fatal("not part of current checkout: %s", zFilename); | |
| 789 | + } | |
| 790 | + mid = db_int(0, "SELECT mid FROM mlink WHERE fid=%d AND fnid=%d", fid, fnid); | |
| 791 | + if( mid==0 ){ | |
| 792 | + fossil_panic("unable to find manifest"); | |
| 793 | + } | |
| 794 | + annotate_file(&ann, fnid, mid, 0); | |
| 795 | + for(i=0; i<ann.nOrig; i++){ | |
| 796 | + printf("%s: %.*s\n", ann.aOrig[i].zSrc, ann.aOrig[i].n, ann.aOrig[i].z); | |
| 797 | + } | |
| 798 | +} | |
| 758 | 799 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -710,11 +710,11 @@ | |
| 710 | while( db_step(&q)==SQLITE_ROW ){ |
| 711 | int pid = db_column_int(&q, 0); |
| 712 | const char *zUuid = db_column_text(&q, 1); |
| 713 | const char *zDate = db_column_text(&q, 2); |
| 714 | const char *zUser = db_column_text(&q, 3); |
| 715 | if( g.okHistory ){ |
| 716 | zLabel = mprintf("<a href='%s/info/%s'>%.10s</a> %s %9.9s", |
| 717 | g.zBaseURL, zUuid, zUuid, zDate, zUser); |
| 718 | }else{ |
| 719 | zLabel = mprintf("%.10s %s %9.9s", zUuid, zDate, zUser); |
| 720 | } |
| @@ -744,14 +744,55 @@ | |
| 744 | if( mid==0 || fnid==0 ){ fossil_redirect_home(); } |
| 745 | if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){ |
| 746 | fossil_redirect_home(); |
| 747 | } |
| 748 | style_header("File Annotation"); |
| 749 | annotate_file(&ann, fnid, mid, 1); |
| 750 | @ <pre> |
| 751 | for(i=0; i<ann.nOrig; i++){ |
| 752 | ((char*)ann.aOrig[i].z)[ann.aOrig[i].n] = 0; |
| 753 | @ %s(ann.aOrig[i].zSrc): %h(ann.aOrig[i].z) |
| 754 | } |
| 755 | @ </pre> |
| 756 | style_footer(); |
| 757 | } |
| 758 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -710,11 +710,11 @@ | |
| 710 | while( db_step(&q)==SQLITE_ROW ){ |
| 711 | int pid = db_column_int(&q, 0); |
| 712 | const char *zUuid = db_column_text(&q, 1); |
| 713 | const char *zDate = db_column_text(&q, 2); |
| 714 | const char *zUser = db_column_text(&q, 3); |
| 715 | if( webLabel ){ |
| 716 | zLabel = mprintf("<a href='%s/info/%s'>%.10s</a> %s %9.9s", |
| 717 | g.zBaseURL, zUuid, zUuid, zDate, zUser); |
| 718 | }else{ |
| 719 | zLabel = mprintf("%.10s %s %9.9s", zUuid, zDate, zUser); |
| 720 | } |
| @@ -744,14 +744,55 @@ | |
| 744 | if( mid==0 || fnid==0 ){ fossil_redirect_home(); } |
| 745 | if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){ |
| 746 | fossil_redirect_home(); |
| 747 | } |
| 748 | style_header("File Annotation"); |
| 749 | annotate_file(&ann, fnid, mid, g.okHistory); |
| 750 | @ <pre> |
| 751 | for(i=0; i<ann.nOrig; i++){ |
| 752 | ((char*)ann.aOrig[i].z)[ann.aOrig[i].n] = 0; |
| 753 | @ %s(ann.aOrig[i].zSrc): %h(ann.aOrig[i].z) |
| 754 | } |
| 755 | @ </pre> |
| 756 | style_footer(); |
| 757 | } |
| 758 | |
| 759 | /* |
| 760 | ** COMMAND: annotate |
| 761 | ** |
| 762 | ** %fossil annotate FILENAME |
| 763 | ** |
| 764 | ** Output the text of a file with markings to show when each line of |
| 765 | ** the file was introduced. |
| 766 | */ |
| 767 | void annotate_cmd(void){ |
| 768 | int fnid; /* Filename ID */ |
| 769 | int fid; /* File instance ID */ |
| 770 | int mid; /* Manifest where file was checked in */ |
| 771 | Blob treename; /* FILENAME translated to canonical form */ |
| 772 | char *zFilename; /* Cannonical filename */ |
| 773 | Annotator ann; /* The annotation of the file */ |
| 774 | int i; /* Loop counter */ |
| 775 | |
| 776 | db_must_be_within_tree(); |
| 777 | if (g.argc<3) { |
| 778 | usage("FILENAME"); |
| 779 | } |
| 780 | file_tree_name(g.argv[2], &treename, 1); |
| 781 | zFilename = blob_str(&treename); |
| 782 | fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q", zFilename); |
| 783 | if( fnid==0 ){ |
| 784 | fossil_fatal("no such file: %s", zFilename); |
| 785 | } |
| 786 | fid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFilename); |
| 787 | if( fid==0 ){ |
| 788 | fossil_fatal("not part of current checkout: %s", zFilename); |
| 789 | } |
| 790 | mid = db_int(0, "SELECT mid FROM mlink WHERE fid=%d AND fnid=%d", fid, fnid); |
| 791 | if( mid==0 ){ |
| 792 | fossil_panic("unable to find manifest"); |
| 793 | } |
| 794 | annotate_file(&ann, fnid, mid, 0); |
| 795 | for(i=0; i<ann.nOrig; i++){ |
| 796 | printf("%s: %.*s\n", ann.aOrig[i].zSrc, ann.aOrig[i].n, ann.aOrig[i].z); |
| 797 | } |
| 798 | } |
| 799 |