@@ -595,11 +595,32 @@
return zBaseSql;
}
/*
+** Equivalent to timeline_query_for_tty(), except that:
+**
+** a) accepts a the -type=XX flag to set the event type to filter on.
+** The values of XX are the same as supported by the /timeline page.
+**
+** b) The returned string must be freed using free().
+*/
+char * timeline_query_for_tty_m(void){
+ Blob bl;
+ char const * zType = 0;
+ blob_zero(&bl);
+ blob_append( &bl, timeline_query_for_tty(), -1 );
+ zType = find_option( "type", "t", 1 );
+ if( zType && *zType )
+ {
+ blob_appendf( &bl, " AND event.type=%Q", zType );
+ }
+ return blob_buffer(&bl);
+}
+
+/*
** COMMAND: timeline
**
-** Usage: %fossil timeline ?WHEN? ?BASELINE|DATETIME? ?-n|--count N?
+** Usage: %fossil timeline ?WHEN? ?BASELINE|DATETIME? ?-n|--count N? ?-t|--type TYPE?
**
** Print a summary of activity going backwards in date and time
** specified or from the current date and time if no arguments
** are given. Show as many as N (default 20) check-ins. The
@@ -614,27 +635,36 @@
** The BASELINE can be any unique prefix of 4 characters or more.
** The DATETIME should be in the ISO8601 format. For
** examples: "2007-08-18 07:21:21". You can also say "current"
** for the current version or "now" for the current time.
+**
+** The optional TYPE argument may any types supported by the /timeline
+** page. For example:
+**
+** w = wiki commits only
+** ci = file commits only
+** t = tickets only
*/
void timeline_cmd(void){
Stmt q;
int n, k;
const char *zCount;
+ const char *zType;
char *zOrigin;
char *zDate;
char *zSQL;
int objid = 0;
Blob uuid;
int mode = 1 ; /* 1: before 2:after 3:children 4:parents */
db_find_and_open_repository(1);
- zCount = find_option("n","count",1);
+ zCount = find_option("count","n",1);
+ zType = find_option("type","t",1);
if( zCount ){
n = atoi(zCount);
}else{
n = 20;
}
- if( g.argc==4 ){
+ if( g.argc>=4 ){
k = strlen(g.argv[2]);
if( strncmp(g.argv[2],"before",k)==0 ){
mode = 1;
}else if( strncmp(g.argv[2],"after",k)==0 && k>1 ){
@@ -646,12 +676,16 @@
}else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
mode = 4;
}else if( strncmp(g.argv[2],"parents",k)==0 ){
mode = 4;
- }else{
- usage("?WHEN? ?BASELINE|DATETIME?");
+ }else if(!zType && !zCount){
+ usage("?WHEN? ?BASELINE|DATETIME? ?-n|--count N? ?-t TYPE?");
}
- zOrigin = g.argv[3];
+ if( '-' != *g.argv[3] ){
+ zOrigin = g.argv[3];
+ }else{
+ zOrigin = "now";
+ }
}else if( g.argc==3 ){
zOrigin = g.argv[2];
}else{
zOrigin = "now";
@@ -678,10 +712,10 @@
fossil_fatal("cannot compute descendants or ancestors of a date");
}
zDate = mprintf("(SELECT julianday(%Q, 'utc'))", zOrigin);
}
- zSQL = mprintf("%s AND event.mtime %s %s",
- timeline_query_for_tty(),
+ zSQL = mprintf("%z AND event.mtime %s %s",
+ timeline_query_for_tty_m(),
(mode==1 || mode==4) ? "<=" : ">=",
zDate
);
if( mode==3 || mode==4 ){
@@ -692,10 +726,15 @@
compute_ancestors(objid, n);
}
zSQL = mprintf("%z AND blob.rid IN ok", zSQL);
}
+ if( zType && (zType[0]!='a') ){
+ zSQL = mprintf( "%z AND event.type=%Q ", zSQL, zType);
+ }
+
zSQL = mprintf("%z ORDER BY event.mtime DESC", zSQL);
db_prepare(&q, zSQL);
+ free( zSQL );
print_timeline(&q, n);
db_finalize(&q);
}