Index: src/timeline.c ================================================================== --- src/timeline.c +++ src/timeline.c @@ -1333,10 +1333,71 @@ } /* If execution reaches this point, the pattern was empty. Return NULL. */ return 0; } + +/* +** Add SQL text to the WHERE clause expression in pCond that restricts +** the timeline to elements of the zTagSql tag or branch. In other words, +** handle the r= and t= query parameters. +** +** zTagSql is an SQL expression that identifies the tags to be displayed. +** If zTagSql is NULL, this routine is a no-op. +** +** If the "related" flag is set, the first check-in before and after the +** branch is also shown. If related==0, then only the specified tag or +** branch is shown. +*/ +static void timeline_tag_or_branch_conditional( + const char *zTagSql, /* SQL expression for the tag or branch to display */ + Blob *pCond, /* WHERE clause under construction */ + int related, /* TRUE to show related check-ins */ + int tmFlags /* Other timeline flags */ +){ + if( zTagSql ){ + blob_append_sql(pCond, + " AND (EXISTS(SELECT 1 FROM tagxref NATURAL JOIN tag" + " WHERE %s AND tagtype>0 AND rid=blob.rid)\n", zTagSql/*safe-for-%s*/); + + if( related ){ + /* The next two blob_appendf() calls add SQL that causes check-ins that + ** are not part of the branch which are parents or children of the + ** branch to be included in the report. This related check-ins are + ** useful in helping to visualize what has happened on a quiescent + ** branch that is infrequently merged with a much more activate branch. + */ + blob_append_sql(pCond, + " OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=cid" + " NATURAL JOIN tag WHERE %s AND tagtype>0 AND pid=blob.rid)\n", + zTagSql/*safe-for-%s*/ + ); + if( (tmFlags & TIMELINE_UNHIDE)==0 ){ + blob_append_sql(pCond, + " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=cid" + " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)\n", + TAG_HIDDEN + ); + } + if( P("mionly")==0 ){ + blob_append_sql(pCond, + " OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=pid" + " NATURAL JOIN tag WHERE %s AND tagtype>0 AND cid=blob.rid)\n", + zTagSql/*safe-for-%s*/ + ); + if( (tmFlags & TIMELINE_UNHIDE)==0 ){ + blob_append_sql(pCond, + " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=pid" + " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)\n", + TAG_HIDDEN + ); + } + } + } + blob_append_sql(pCond, ")"); + } +} /* ** WEBPAGE: timeline ** ** Query parameters: @@ -1677,10 +1738,11 @@ "CREATE TEMP TABLE IF NOT EXISTS ok(rid INTEGER PRIMARY KEY)" ); zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", p_rid ? p_rid : d_rid); blob_append_sql(&sql, " AND event.objid IN ok"); + timeline_tag_or_branch_conditional(zTagSql, &sql, related, tmFlags); nd = 0; if( d_rid ){ compute_descendants(d_rid, nEntry+1); nd = db_int(0, "SELECT count(*)-1 FROM ok"); if( nd>=0 ) db_multi_exec("%s", blob_sql_text(&sql)); @@ -1765,51 +1827,11 @@ } else if( zDay ){ blob_append_sql(&cond, " AND %Q=strftime('%%Y-%%m-%%d',event.mtime) ", zDay); } - if( zTagSql ){ - blob_append_sql(&cond, - " AND (EXISTS(SELECT 1 FROM tagxref NATURAL JOIN tag" - " WHERE %s AND tagtype>0 AND rid=blob.rid)\n", zTagSql/*safe-for-%s*/); - - if( related ){ - /* The next two blob_appendf() calls add SQL that causes check-ins that - ** are not part of the branch which are parents or children of the - ** branch to be included in the report. This related check-ins are - ** useful in helping to visualize what has happened on a quiescent - ** branch that is infrequently merged with a much more activate branch. - */ - blob_append_sql(&cond, - " OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=cid" - " NATURAL JOIN tag WHERE %s AND tagtype>0 AND pid=blob.rid)\n", - zTagSql/*safe-for-%s*/ - ); - if( (tmFlags & TIMELINE_UNHIDE)==0 ){ - blob_append_sql(&cond, - " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=cid" - " WHERE tagid=%d AND tagtype>0 AND pid=blob.rid)\n", - TAG_HIDDEN - ); - } - if( P("mionly")==0 ){ - blob_append_sql(&cond, - " OR EXISTS(SELECT 1 FROM plink CROSS JOIN tagxref ON rid=pid" - " NATURAL JOIN tag WHERE %s AND tagtype>0 AND cid=blob.rid)\n", - zTagSql/*safe-for-%s*/ - ); - if( (tmFlags & TIMELINE_UNHIDE)==0 ){ - blob_append_sql(&cond, - " AND NOT EXISTS(SELECT 1 FROM plink JOIN tagxref ON rid=pid" - " WHERE tagid=%d AND tagtype>0 AND cid=blob.rid)\n", - TAG_HIDDEN - ); - } - } - } - blob_append_sql(&cond, ")"); - } + timeline_tag_or_branch_conditional(zTagSql, &cond, related, tmFlags); if( (zType[0]=='w' && !g.perm.RdWiki) || (zType[0]=='t' && !g.perm.RdTkt) || (zType[0]=='e' && !g.perm.RdWiki) || (zType[0]=='c' && !g.perm.Read) || (zType[0]=='g' && !g.perm.Read)