Fossil SCM

Add an "annotate" command to the command-line to suppliment the "annotate" web page.

drh 2009-12-18 20:15 trunk
Commit 73b7faa58b4b457b2c4179863dea9ebfbdac17df
1 file changed +43 -2
+43 -2
--- src/diff.c
+++ src/diff.c
@@ -710,11 +710,11 @@
710710
while( db_step(&q)==SQLITE_ROW ){
711711
int pid = db_column_int(&q, 0);
712712
const char *zUuid = db_column_text(&q, 1);
713713
const char *zDate = db_column_text(&q, 2);
714714
const char *zUser = db_column_text(&q, 3);
715
- if( g.okHistory ){
715
+ if( webLabel ){
716716
zLabel = mprintf("<a href='%s/info/%s'>%.10s</a> %s %9.9s",
717717
g.zBaseURL, zUuid, zUuid, zDate, zUser);
718718
}else{
719719
zLabel = mprintf("%.10s %s %9.9s", zUuid, zDate, zUser);
720720
}
@@ -744,14 +744,55 @@
744744
if( mid==0 || fnid==0 ){ fossil_redirect_home(); }
745745
if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){
746746
fossil_redirect_home();
747747
}
748748
style_header("File Annotation");
749
- annotate_file(&ann, fnid, mid, 1);
749
+ annotate_file(&ann, fnid, mid, g.okHistory);
750750
@ <pre>
751751
for(i=0; i<ann.nOrig; i++){
752752
((char*)ann.aOrig[i].z)[ann.aOrig[i].n] = 0;
753753
@ %s(ann.aOrig[i].zSrc): %h(ann.aOrig[i].z)
754754
}
755755
@ </pre>
756756
style_footer();
757757
}
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
+}
758799
--- 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

Keyboard Shortcuts

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