Check-in [8c8f8616a6]
Not logged in
Overview

SHA1 Hash:8c8f8616a64ad4868e93e07c4d230f72a3965bcd
Date: 2009-10-31 15:07:45
User: drh
Comment:Add an "finfo" command to give file history.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Added src/finfo.c version [8f0bef2b64]

@@ -1,1 +1,177 @@
+/*
+** Copyright (c) 2009 D. Richard Hipp
+**
+** This program is free software; you can redistribute it and/or
+** modify it under the terms of the GNU General Public
+** License version 2 as published by the Free Software Foundation.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+** General Public License for more details.
+**
+** You should have received a copy of the GNU General Public
+** License along with this library; if not, write to the
+** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+** Boston, MA  02111-1307, USA.
+**
+** Author contact information:
+**   drh@hwaci.com
+**   http://www.hwaci.com/drh/
+**
+*******************************************************************************
+**
+** This file contains code to implement the "finfo" command.
+*/
+#include "config.h"
+#include "finfo.h"
+
+/*
+** COMMAND: finfo
+**
+** Usage: %fossil finfo FILENAME
+**
+** Print the change history for a single file.
+**
+** The "--limit N" and "--offset P" options limits the output to the first
+** N changes after skipping P changes.
+*/
+void finfo_cmd(void){
+  Stmt q;
+  int vid;
+  Blob dest;
+  const char *zFilename;
+  const char *zLimit;
+  const char *zOffset;
+  int iLimit, iOffset;
+
+  db_must_be_within_tree();
+  vid = db_lget_int("checkout", 0);
+  if( vid==0 ){
+    fossil_panic("no checkout to finfo files in");
+  }
+  zLimit = find_option("limit",0,1);
+  iLimit = zLimit ? atoi(zLimit) : -1;
+  zOffset = find_option("offset",0,1);
+  iOffset = zOffset ? atoi(zOffset) : 0;
+  if (g.argc<3) {
+    usage("FILENAME");
+  }
+  file_tree_name(g.argv[2], &dest, 1);
+  zFilename = blob_str(&dest);
+  db_prepare(&q,
+    "SELECT b.uuid, ci.uuid, date(event.mtime,'localtime'),"
+    "       coalesce(event.ecomment, event.comment),"
+    "       coalesce(event.euser, event.user)"
+    "  FROM mlink, blob b, event, blob ci"
+    " WHERE mlink.fnid=(SELECT fnid FROM filename WHERE name=%Q)"
+    "   AND b.rid=mlink.fid"
+    "   AND event.objid=mlink.mid"
+    "   AND event.objid=ci.rid"
+    " ORDER BY event.mtime DESC LIMIT %d OFFSET %d",
+    zFilename, iLimit, iOffset
+  );
+
+  printf("History of %s\n", zFilename);
+  while( db_step(&q)==SQLITE_ROW ){
+    const char *zFileUuid = db_column_text(&q, 0);
+    const char *zCiUuid = db_column_text(&q, 1);
+    const char *zDate = db_column_text(&q, 2);
+    const char *zCom = db_column_text(&q, 3);
+    const char *zUser = db_column_text(&q, 4);
+    char *zOut;
+    printf("%s ", zDate);
+    zOut = sqlite3_mprintf("[%.10s] %s (user: %s, artifact: [%.10s])",
+                            zCiUuid, zCom, zUser, zFileUuid);
+    comment_print(zOut, 11, 79);
+    sqlite3_free(zOut);
+  }
+  db_finalize(&q);
+  blob_reset(&dest);
+}
+
+
+/*
+** WEBPAGE: finfo
+** URL: /finfo?name=FILENAME
+**
+** Show the complete change history for a single file.
+*/
+void finfo_page(void){
+  Stmt q;
+  const char *zFilename;
+  char zPrevDate[20];
+  Blob title;
+
+  login_check_credentials();
+  if( !g.okRead ){ login_needed(); return; }
+  style_header("File History");
+  login_anonymous_available();
 
+  zPrevDate[0] = 0;
+  zFilename = PD("name","");
+  db_prepare(&q,
+    "SELECT substr(b.uuid,1,10), datetime(event.mtime,'localtime'),"
+    "       coalesce(event.ecomment, event.comment),"
+    "       coalesce(event.euser, event.user),"
+    "       mlink.pid, mlink.fid, mlink.mid, mlink.fnid, ci.uuid"
+    "  FROM mlink, blob b, event, blob ci"
+    " WHERE mlink.fnid=(SELECT fnid FROM filename WHERE name=%Q)"
+    "   AND b.rid=mlink.fid"
+    "   AND event.objid=mlink.mid"
+    "   AND event.objid=ci.rid"
+    " ORDER BY event.mtime DESC",
+    zFilename
+  );
+  blob_zero(&title);
+  blob_appendf(&title, "History of ");
+  hyperlinked_path(zFilename, &title);
+  @ <h2>%b(&title)</h2>
+  blob_reset(&title);
+  @ <table cellspacing=0 border=0 cellpadding=0>
+  while( db_step(&q)==SQLITE_ROW ){
+    const char *zUuid = db_column_text(&q, 0);
+    const char *zDate = db_column_text(&q, 1);
+    const char *zCom = db_column_text(&q, 2);
+    const char *zUser = db_column_text(&q, 3);
+    int fpid = db_column_int(&q, 4);
+    int frid = db_column_int(&q, 5);
+    int mid = db_column_int(&q, 6);
+    int fnid = db_column_int(&q, 7);
+    const char *zCkin = db_column_text(&q,8);
+    char zShort[20];
+    char zShortCkin[20];
+    if( memcmp(zDate, zPrevDate, 10) ){
+      sprintf(zPrevDate, "%.10s", zDate);
+      @ <tr><td colspan=3>
+      @   <div class="divider">%s(zPrevDate)</div>
+      @ </td></tr>
+    }
+    @ <tr><td valign="top">%s(&zDate[11])</td>
+    @ <td width="20"></td>
+    @ <td valign="top" align="left">
+    sqlite3_snprintf(sizeof(zShort), zShort, "%.10s", zUuid);
+    sqlite3_snprintf(sizeof(zShortCkin), zShortCkin, "%.10s", zCkin);
+    if( g.okHistory ){
+      @ <a href="%s(g.zTop)/artifact/%s(zUuid)">[%s(zShort)]</a>
+    }else{
+      @ [%s(zShort)]
+    }
+    @ part of check-in
+    hyperlink_to_uuid(zShortCkin);
+    @ %h(zCom) (By:
+    hyperlink_to_user(zUser, zDate, " on");
+    hyperlink_to_date(zDate, ")");
+    if( g.okHistory ){
+      if( fpid ){
+        @ <a href="%s(g.zBaseURL)/fdiff?v1=%d(fpid)&amp;v2=%d(frid)">[diff]</a>
+      }
+      @ <a href="%s(g.zBaseURL)/annotate?mid=%d(mid)&amp;fnid=%d(fnid)">
+      @ [annotate]</a>
+      @ </td>
+    }
+  }
+  db_finalize(&q);
+  @ </table>
+  style_footer();
+}

Modified src/info.c from [bdf1a77d15] to [07a09dc029].

@@ -475,96 +475,10 @@
     }
     manifest_clear(&m);
   }
   style_footer();
 }
-
-/*
-** WEBPAGE: finfo
-** URL: /finfo?name=FILENAME
-**
-** Show the complete change history for a single file.
-*/
-void finfo_page(void){
-  Stmt q;
-  const char *zFilename;
-  char zPrevDate[20];
-  Blob title;
-
-  login_check_credentials();
-  if( !g.okRead ){ login_needed(); return; }
-  style_header("File History");
-  login_anonymous_available();
-
-  zPrevDate[0] = 0;
-  zFilename = PD("name","");
-  db_prepare(&q,
-    "SELECT substr(b.uuid,1,10), datetime(event.mtime,'localtime'),"
-    "       coalesce(event.ecomment, event.comment),"
-    "       coalesce(event.euser, event.user),"
-    "       mlink.pid, mlink.fid, mlink.mid, mlink.fnid, ci.uuid"
-    "  FROM mlink, blob b, event, blob ci"
-    " WHERE mlink.fnid=(SELECT fnid FROM filename WHERE name=%Q)"
-    "   AND b.rid=mlink.fid"
-    "   AND event.objid=mlink.mid"
-    "   AND event.objid=ci.rid"
-    " ORDER BY event.mtime DESC",
-    zFilename
-  );
-  blob_zero(&title);
-  blob_appendf(&title, "History of ");
-  hyperlinked_path(zFilename, &title);
-  @ <h2>%b(&title)</h2>
-  blob_reset(&title);
-  @ <table cellspacing=0 border=0 cellpadding=0>
-  while( db_step(&q)==SQLITE_ROW ){
-    const char *zUuid = db_column_text(&q, 0);
-    const char *zDate = db_column_text(&q, 1);
-    const char *zCom = db_column_text(&q, 2);
-    const char *zUser = db_column_text(&q, 3);
-    int fpid = db_column_int(&q, 4);
-    int frid = db_column_int(&q, 5);
-    int mid = db_column_int(&q, 6);
-    int fnid = db_column_int(&q, 7);
-    const char *zCkin = db_column_text(&q,8);
-    char zShort[20];
-    char zShortCkin[20];
-    if( memcmp(zDate, zPrevDate, 10) ){
-      sprintf(zPrevDate, "%.10s", zDate);
-      @ <tr><td colspan=3>
-      @   <div class="divider">%s(zPrevDate)</div>
-      @ </td></tr>
-    }
-    @ <tr><td valign="top">%s(&zDate[11])</td>
-    @ <td width="20"></td>
-    @ <td valign="top" align="left">
-    sqlite3_snprintf(sizeof(zShort), zShort, "%.10s", zUuid);
-    sqlite3_snprintf(sizeof(zShortCkin), zShortCkin, "%.10s", zCkin);
-    if( g.okHistory ){
-      @ <a href="%s(g.zTop)/artifact/%s(zUuid)">[%s(zShort)]</a>
-    }else{
-      @ [%s(zShort)]
-    }
-    @ part of check-in
-    hyperlink_to_uuid(zShortCkin);
-    @ %h(zCom) (By:
-    hyperlink_to_user(zUser, zDate, " on");
-    hyperlink_to_date(zDate, ")");
-    if( g.okHistory ){
-      if( fpid ){
-        @ <a href="%s(g.zBaseURL)/fdiff?v1=%d(fpid)&amp;v2=%d(frid)">[diff]</a>
-      }
-      @ <a href="%s(g.zBaseURL)/annotate?mid=%d(mid)&amp;fnid=%d(fnid)">
-      @ [annotate]</a>
-      @ </td>
-    }
-  }
-  db_finalize(&q);
-  @ </table>
-  style_footer();
-}
-
 
 /*
 ** WEBPAGE: vdiff
 ** URL: /vdiff?name=RID
 **

Modified src/main.mk from [5d15c133fb] to [08be0ee0ca].

@@ -36,10 +36,11 @@
   $(SRCDIR)/diff.c \
   $(SRCDIR)/diffcmd.c \
   $(SRCDIR)/doc.c \
   $(SRCDIR)/encode.c \
   $(SRCDIR)/file.c \
+  $(SRCDIR)/finfo.c \
   $(SRCDIR)/http.c \
   $(SRCDIR)/http_socket.c \
   $(SRCDIR)/http_transport.c \
   $(SRCDIR)/info.c \
   $(SRCDIR)/login.c \
@@ -105,10 +106,11 @@
   diff_.c \
   diffcmd_.c \
   doc_.c \
   encode_.c \
   file_.c \
+  finfo_.c \
   http_.c \
   http_socket_.c \
   http_transport_.c \
   info_.c \
   login_.c \
@@ -174,10 +176,11 @@
   diff.o \
   diffcmd.o \
   doc.o \
   encode.o \
   file.o \
+  finfo.o \
   http.o \
   http_socket.o \
   http_transport.o \
   info.o \
   login.o \
@@ -258,16 +261,16 @@
 	# noop
 
 clean:
 	rm -f *.o *_.c $(APPNAME) VERSION.h
 	rm -f translate makeheaders mkindex page_index.h headers
-	rm -f add.h allrepo.h bag.h blob.h branch.h browse.h captcha.h cgi.h checkin.h checkout.h clearsign.h clone.h comformat.h configure.h construct.h content.h db.h delta.h deltacmd.h descendants.h diff.h diffcmd.h doc.h encode.h file.h http.h http_socket.h http_transport.h info.h login.h main.h manifest.h md5.h merge.h merge3.h name.h pivot.h pqueue.h printf.h rebuild.h report.h rss.h rstats.h schema.h search.h setup.h sha1.h shun.h stat.h style.h sync.h tag.h th_main.h timeline.h tkt.h tktsetup.h undo.h update.h url.h user.h verify.h vfile.h wiki.h wikiformat.h winhttp.h xfer.h zip.h
+	rm -f add.h allrepo.h bag.h blob.h branch.h browse.h captcha.h cgi.h checkin.h checkout.h clearsign.h clone.h comformat.h configure.h construct.h content.h db.h delta.h deltacmd.h descendants.h diff.h diffcmd.h doc.h encode.h file.h finfo.h http.h http_socket.h http_transport.h info.h login.h main.h manifest.h md5.h merge.h merge3.h name.h pivot.h pqueue.h printf.h rebuild.h report.h rss.h rstats.h schema.h search.h setup.h sha1.h shun.h stat.h style.h sync.h tag.h th_main.h timeline.h tkt.h tktsetup.h undo.h update.h url.h user.h verify.h vfile.h wiki.h wikiformat.h winhttp.h xfer.h zip.h
 
 page_index.h: $(TRANS_SRC) mkindex
 	./mkindex $(TRANS_SRC) >$@
 headers:	page_index.h makeheaders VERSION.h
-	./makeheaders  add_.c:add.h allrepo_.c:allrepo.h bag_.c:bag.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h construct_.c:construct.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h file_.c:file.h http_.c:http.h http_socket_.c:http_socket.h http_transport_.c:http_transport.h info_.c:info.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h pivot_.c:pivot.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h rstats_.c:rstats.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h zip_.c:zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h VERSION.h
+	./makeheaders  add_.c:add.h allrepo_.c:allrepo.h bag_.c:bag.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h construct_.c:construct.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h file_.c:file.h finfo_.c:finfo.h http_.c:http.h http_socket_.c:http_socket.h http_transport_.c:http_transport.h info_.c:info.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h pivot_.c:pivot.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h rstats_.c:rstats.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h zip_.c:zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h VERSION.h
 	touch headers
 headers: Makefile
 Makefile:
 add_.c:	$(SRCDIR)/add.c translate
 	./translate $(SRCDIR)/add.c >add_.c
@@ -442,10 +445,17 @@
 
 file.o:	file_.c file.h  $(SRCDIR)/config.h
 	$(XTCC) -o file.o -c file_.c
 
 file.h:	headers
+finfo_.c:	$(SRCDIR)/finfo.c translate
+	./translate $(SRCDIR)/finfo.c >finfo_.c
+
+finfo.o:	finfo_.c finfo.h  $(SRCDIR)/config.h
+	$(XTCC) -o finfo.o -c finfo_.c
+
+finfo.h:	headers
 http_.c:	$(SRCDIR)/http.c translate
 	./translate $(SRCDIR)/http.c >http_.c
 
 http.o:	http_.c http.h  $(SRCDIR)/config.h
 	$(XTCC) -o http.o -c http_.c

Modified src/makemake.tcl from [be92f7b0d9] to [8696139730].

@@ -30,10 +30,11 @@
   diff
   diffcmd
   doc
   encode
   file
+  finfo
   http
   http_socket
   http_transport
   info
   login