Fossil SCM

timeline command now supports a ?-t|--type TYPE? option to filter on specific event types. Fixed a memleak in the timeline command.

stephan 2008-12-12 23:17 trunk
Commit bab8363876617441f52ea6ebeb955f95d2277aa8
1 file changed +46 -7
+46 -7
--- src/timeline.c
+++ src/timeline.c
@@ -592,15 +592,36 @@
592592
@ FROM event, blob
593593
@ WHERE blob.rid=event.objid
594594
;
595595
return zBaseSql;
596596
}
597
+
598
+/*
599
+** Equivalent to timeline_query_for_tty(), except that:
600
+**
601
+** a) accepts a the -type=XX flag to set the event type to filter on.
602
+** The values of XX are the same as supported by the /timeline page.
603
+**
604
+** b) The returned string must be freed using free().
605
+*/
606
+char * timeline_query_for_tty_m(void){
607
+ Blob bl;
608
+ char const * zType = 0;
609
+ blob_zero(&bl);
610
+ blob_append( &bl, timeline_query_for_tty(), -1 );
611
+ zType = find_option( "type", "t", 1 );
612
+ if( zType && *zType )
613
+ {
614
+ blob_appendf( &bl, " AND event.type=%Q", zType );
615
+ }
616
+ return blob_buffer(&bl);
617
+}
597618
598619
/*
599620
** COMMAND: timeline
600621
**
601
-** Usage: %fossil timeline ?WHEN? ?BASELINE|DATETIME? ?-n|--count N?
622
+** Usage: %fossil timeline ?WHEN? ?BASELINE|DATETIME? ?-n|--count N? ?-t|--type TYPE?
602623
**
603624
** Print a summary of activity going backwards in date and time
604625
** specified or from the current date and time if no arguments
605626
** are given. Show as many as N (default 20) check-ins. The
606627
** WHEN argument can be any unique abbreviation of one of these
@@ -613,29 +634,38 @@
613634
**
614635
** The BASELINE can be any unique prefix of 4 characters or more.
615636
** The DATETIME should be in the ISO8601 format. For
616637
** examples: "2007-08-18 07:21:21". You can also say "current"
617638
** for the current version or "now" for the current time.
639
+**
640
+** The optional TYPE argument may any types supported by the /timeline
641
+** page. For example:
642
+**
643
+** w = wiki commits only
644
+** ci = file commits only
645
+** t = tickets only
618646
*/
619647
void timeline_cmd(void){
620648
Stmt q;
621649
int n, k;
622650
const char *zCount;
651
+ const char *zType;
623652
char *zOrigin;
624653
char *zDate;
625654
char *zSQL;
626655
int objid = 0;
627656
Blob uuid;
628657
int mode = 1 ; /* 1: before 2:after 3:children 4:parents */
629658
db_find_and_open_repository(1);
630
- zCount = find_option("n","count",1);
659
+ zCount = find_option("count","n",1);
660
+ zType = find_option("type","t",1);
631661
if( zCount ){
632662
n = atoi(zCount);
633663
}else{
634664
n = 20;
635665
}
636
- if( g.argc==4 ){
666
+ if( g.argc>=4 ){
637667
k = strlen(g.argv[2]);
638668
if( strncmp(g.argv[2],"before",k)==0 ){
639669
mode = 1;
640670
}else if( strncmp(g.argv[2],"after",k)==0 && k>1 ){
641671
mode = 2;
@@ -645,14 +675,18 @@
645675
mode = 3;
646676
}else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
647677
mode = 4;
648678
}else if( strncmp(g.argv[2],"parents",k)==0 ){
649679
mode = 4;
680
+ }else if(!zType && !zCount){
681
+ usage("?WHEN? ?BASELINE|DATETIME? ?-n|--count N? ?-t TYPE?");
682
+ }
683
+ if( '-' != *g.argv[3] ){
684
+ zOrigin = g.argv[3];
650685
}else{
651
- usage("?WHEN? ?BASELINE|DATETIME?");
686
+ zOrigin = "now";
652687
}
653
- zOrigin = g.argv[3];
654688
}else if( g.argc==3 ){
655689
zOrigin = g.argv[2];
656690
}else{
657691
zOrigin = "now";
658692
}
@@ -677,12 +711,12 @@
677711
if( mode==3 || mode==4 ){
678712
fossil_fatal("cannot compute descendants or ancestors of a date");
679713
}
680714
zDate = mprintf("(SELECT julianday(%Q, 'utc'))", zOrigin);
681715
}
682
- zSQL = mprintf("%s AND event.mtime %s %s",
683
- timeline_query_for_tty(),
716
+ zSQL = mprintf("%z AND event.mtime %s %s",
717
+ timeline_query_for_tty_m(),
684718
(mode==1 || mode==4) ? "<=" : ">=",
685719
zDate
686720
);
687721
if( mode==3 || mode==4 ){
688722
db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
@@ -691,12 +725,17 @@
691725
}else{
692726
compute_ancestors(objid, n);
693727
}
694728
zSQL = mprintf("%z AND blob.rid IN ok", zSQL);
695729
}
730
+ if( zType && (zType[0]!='a') ){
731
+ zSQL = mprintf( "%z AND event.type=%Q ", zSQL, zType);
732
+ }
733
+
696734
zSQL = mprintf("%z ORDER BY event.mtime DESC", zSQL);
697735
db_prepare(&q, zSQL);
736
+ free( zSQL );
698737
print_timeline(&q, n);
699738
db_finalize(&q);
700739
}
701740
702741
/*
703742
--- src/timeline.c
+++ src/timeline.c
@@ -592,15 +592,36 @@
592 @ FROM event, blob
593 @ WHERE blob.rid=event.objid
594 ;
595 return zBaseSql;
596 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597
598 /*
599 ** COMMAND: timeline
600 **
601 ** Usage: %fossil timeline ?WHEN? ?BASELINE|DATETIME? ?-n|--count N?
602 **
603 ** Print a summary of activity going backwards in date and time
604 ** specified or from the current date and time if no arguments
605 ** are given. Show as many as N (default 20) check-ins. The
606 ** WHEN argument can be any unique abbreviation of one of these
@@ -613,29 +634,38 @@
613 **
614 ** The BASELINE can be any unique prefix of 4 characters or more.
615 ** The DATETIME should be in the ISO8601 format. For
616 ** examples: "2007-08-18 07:21:21". You can also say "current"
617 ** for the current version or "now" for the current time.
 
 
 
 
 
 
 
618 */
619 void timeline_cmd(void){
620 Stmt q;
621 int n, k;
622 const char *zCount;
 
623 char *zOrigin;
624 char *zDate;
625 char *zSQL;
626 int objid = 0;
627 Blob uuid;
628 int mode = 1 ; /* 1: before 2:after 3:children 4:parents */
629 db_find_and_open_repository(1);
630 zCount = find_option("n","count",1);
 
631 if( zCount ){
632 n = atoi(zCount);
633 }else{
634 n = 20;
635 }
636 if( g.argc==4 ){
637 k = strlen(g.argv[2]);
638 if( strncmp(g.argv[2],"before",k)==0 ){
639 mode = 1;
640 }else if( strncmp(g.argv[2],"after",k)==0 && k>1 ){
641 mode = 2;
@@ -645,14 +675,18 @@
645 mode = 3;
646 }else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
647 mode = 4;
648 }else if( strncmp(g.argv[2],"parents",k)==0 ){
649 mode = 4;
 
 
 
 
 
650 }else{
651 usage("?WHEN? ?BASELINE|DATETIME?");
652 }
653 zOrigin = g.argv[3];
654 }else if( g.argc==3 ){
655 zOrigin = g.argv[2];
656 }else{
657 zOrigin = "now";
658 }
@@ -677,12 +711,12 @@
677 if( mode==3 || mode==4 ){
678 fossil_fatal("cannot compute descendants or ancestors of a date");
679 }
680 zDate = mprintf("(SELECT julianday(%Q, 'utc'))", zOrigin);
681 }
682 zSQL = mprintf("%s AND event.mtime %s %s",
683 timeline_query_for_tty(),
684 (mode==1 || mode==4) ? "<=" : ">=",
685 zDate
686 );
687 if( mode==3 || mode==4 ){
688 db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
@@ -691,12 +725,17 @@
691 }else{
692 compute_ancestors(objid, n);
693 }
694 zSQL = mprintf("%z AND blob.rid IN ok", zSQL);
695 }
 
 
 
 
696 zSQL = mprintf("%z ORDER BY event.mtime DESC", zSQL);
697 db_prepare(&q, zSQL);
 
698 print_timeline(&q, n);
699 db_finalize(&q);
700 }
701
702 /*
703
--- src/timeline.c
+++ src/timeline.c
@@ -592,15 +592,36 @@
592 @ FROM event, blob
593 @ WHERE blob.rid=event.objid
594 ;
595 return zBaseSql;
596 }
597
598 /*
599 ** Equivalent to timeline_query_for_tty(), except that:
600 **
601 ** a) accepts a the -type=XX flag to set the event type to filter on.
602 ** The values of XX are the same as supported by the /timeline page.
603 **
604 ** b) The returned string must be freed using free().
605 */
606 char * timeline_query_for_tty_m(void){
607 Blob bl;
608 char const * zType = 0;
609 blob_zero(&bl);
610 blob_append( &bl, timeline_query_for_tty(), -1 );
611 zType = find_option( "type", "t", 1 );
612 if( zType && *zType )
613 {
614 blob_appendf( &bl, " AND event.type=%Q", zType );
615 }
616 return blob_buffer(&bl);
617 }
618
619 /*
620 ** COMMAND: timeline
621 **
622 ** Usage: %fossil timeline ?WHEN? ?BASELINE|DATETIME? ?-n|--count N? ?-t|--type TYPE?
623 **
624 ** Print a summary of activity going backwards in date and time
625 ** specified or from the current date and time if no arguments
626 ** are given. Show as many as N (default 20) check-ins. The
627 ** WHEN argument can be any unique abbreviation of one of these
@@ -613,29 +634,38 @@
634 **
635 ** The BASELINE can be any unique prefix of 4 characters or more.
636 ** The DATETIME should be in the ISO8601 format. For
637 ** examples: "2007-08-18 07:21:21". You can also say "current"
638 ** for the current version or "now" for the current time.
639 **
640 ** The optional TYPE argument may any types supported by the /timeline
641 ** page. For example:
642 **
643 ** w = wiki commits only
644 ** ci = file commits only
645 ** t = tickets only
646 */
647 void timeline_cmd(void){
648 Stmt q;
649 int n, k;
650 const char *zCount;
651 const char *zType;
652 char *zOrigin;
653 char *zDate;
654 char *zSQL;
655 int objid = 0;
656 Blob uuid;
657 int mode = 1 ; /* 1: before 2:after 3:children 4:parents */
658 db_find_and_open_repository(1);
659 zCount = find_option("count","n",1);
660 zType = find_option("type","t",1);
661 if( zCount ){
662 n = atoi(zCount);
663 }else{
664 n = 20;
665 }
666 if( g.argc>=4 ){
667 k = strlen(g.argv[2]);
668 if( strncmp(g.argv[2],"before",k)==0 ){
669 mode = 1;
670 }else if( strncmp(g.argv[2],"after",k)==0 && k>1 ){
671 mode = 2;
@@ -645,14 +675,18 @@
675 mode = 3;
676 }else if( strncmp(g.argv[2],"ancestors",k)==0 && k>1 ){
677 mode = 4;
678 }else if( strncmp(g.argv[2],"parents",k)==0 ){
679 mode = 4;
680 }else if(!zType && !zCount){
681 usage("?WHEN? ?BASELINE|DATETIME? ?-n|--count N? ?-t TYPE?");
682 }
683 if( '-' != *g.argv[3] ){
684 zOrigin = g.argv[3];
685 }else{
686 zOrigin = "now";
687 }
 
688 }else if( g.argc==3 ){
689 zOrigin = g.argv[2];
690 }else{
691 zOrigin = "now";
692 }
@@ -677,12 +711,12 @@
711 if( mode==3 || mode==4 ){
712 fossil_fatal("cannot compute descendants or ancestors of a date");
713 }
714 zDate = mprintf("(SELECT julianday(%Q, 'utc'))", zOrigin);
715 }
716 zSQL = mprintf("%z AND event.mtime %s %s",
717 timeline_query_for_tty_m(),
718 (mode==1 || mode==4) ? "<=" : ">=",
719 zDate
720 );
721 if( mode==3 || mode==4 ){
722 db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
@@ -691,12 +725,17 @@
725 }else{
726 compute_ancestors(objid, n);
727 }
728 zSQL = mprintf("%z AND blob.rid IN ok", zSQL);
729 }
730 if( zType && (zType[0]!='a') ){
731 zSQL = mprintf( "%z AND event.type=%Q ", zSQL, zType);
732 }
733
734 zSQL = mprintf("%z ORDER BY event.mtime DESC", zSQL);
735 db_prepare(&q, zSQL);
736 free( zSQL );
737 print_timeline(&q, n);
738 db_finalize(&q);
739 }
740
741 /*
742

Keyboard Shortcuts

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