Check-in [73b7faa58b]
Not logged in
Overview

SHA1 Hash:73b7faa58b4b457b2c4179863dea9ebfbdac17df
Date: 2009-12-18 20:15:45
User: drh
Comment:Add an "annotate" command to the command-line to suppliment the "annotate" web page.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/diff.c from [423e7bd7db] to [189451b157].

@@ -710,11 +710,11 @@
   while( db_step(&q)==SQLITE_ROW ){
     int pid = db_column_int(&q, 0);
     const char *zUuid = db_column_text(&q, 1);
     const char *zDate = db_column_text(&q, 2);
     const char *zUser = db_column_text(&q, 3);
-    if( g.okHistory ){
+    if( webLabel ){
       zLabel = mprintf("<a href='%s/info/%s'>%.10s</a> %s %9.9s",
                        g.zBaseURL, zUuid, zUuid, zDate, zUser);
     }else{
       zLabel = mprintf("%.10s %s %9.9s", zUuid, zDate, zUser);
     }
@@ -744,14 +744,55 @@
   if( mid==0 || fnid==0 ){ fossil_redirect_home(); }
   if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){
     fossil_redirect_home();
   }
   style_header("File Annotation");
-  annotate_file(&ann, fnid, mid, 1);
+  annotate_file(&ann, fnid, mid, g.okHistory);
   @ <pre>
   for(i=0; i<ann.nOrig; i++){
     ((char*)ann.aOrig[i].z)[ann.aOrig[i].n] = 0;
     @ %s(ann.aOrig[i].zSrc): %h(ann.aOrig[i].z)
   }
   @ </pre>
   style_footer();
+}
+
+/*
+** COMMAND: annotate
+**
+** %fossil annotate FILENAME
+**
+** Output the text of a file with markings to show when each line of
+** the file was introduced.
+*/
+void annotate_cmd(void){
+  int fnid;         /* Filename ID */
+  int fid;          /* File instance ID */
+  int mid;          /* Manifest where file was checked in */
+  Blob treename;    /* FILENAME translated to canonical form */
+  char *zFilename;  /* Cannonical filename */
+  Annotator ann;    /* The annotation of the file */
+  int i;            /* Loop counter */
+
+  db_must_be_within_tree();
+  if (g.argc<3) {
+    usage("FILENAME");
+  }
+  file_tree_name(g.argv[2], &treename, 1);
+  zFilename = blob_str(&treename);
+  fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q", zFilename);
+  if( fnid==0 ){
+    fossil_fatal("no such file: %s", zFilename);
+  }
+  fid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFilename);
+  if( fid==0 ){
+    fossil_fatal("not part of current checkout: %s", zFilename);
+  }
+  mid = db_int(0, "SELECT mid FROM mlink WHERE fid=%d AND fnid=%d", fid, fnid);
+  if( mid==0 ){
+    fossil_panic("unable to find manifest");
+  }
+  annotate_file(&ann, fnid, mid, 0);
+  for(i=0; i<ann.nOrig; i++){
+    printf("%s: %.*s\n", ann.aOrig[i].zSrc, ann.aOrig[i].n, ann.aOrig[i].z);
+  }
 }