| | @@ -26,43 +26,53 @@ |
| 26 | 26 | ** |
| 27 | 27 | ** This routine assumes that tagid is a tag that should be |
| 28 | 28 | ** propagated and that the tag is already present in pid. |
| 29 | 29 | ** |
| 30 | 30 | ** If tagtype is 2 then the tag is being propagated from an |
| 31 | | -** ancestor node. If tagtype is 0 it means a branch tag is |
| 32 | | -** being cancelled. |
| 31 | +** ancestor node. If tagtype is 0 it means a propagating tag is |
| 32 | +** being blocked. |
| 33 | 33 | */ |
| 34 | 34 | static void tag_propagate( |
| 35 | 35 | int pid, /* Propagate the tag to children of this node */ |
| 36 | 36 | int tagid, /* Tag to propagate */ |
| 37 | 37 | int tagType, /* 2 for a propagating tag. 0 for an antitag */ |
| 38 | 38 | int origId, /* Artifact of tag, when tagType==2 */ |
| 39 | 39 | const char *zValue, /* Value of the tag. Might be NULL */ |
| 40 | 40 | double mtime /* Timestamp on the tag */ |
| 41 | 41 | ){ |
| 42 | | - PQueue queue; |
| 43 | | - Stmt s, ins, eventupdate; |
| 42 | + PQueue queue; /* Queue of check-ins to be tagged */ |
| 43 | + Stmt s; /* Query the children of :pid to which to propagate */ |
| 44 | + Stmt ins; /* INSERT INTO tagxref */ |
| 45 | + Stmt eventupdate; /* UPDATE event */ |
| 44 | 46 | |
| 45 | 47 | assert( tagType==0 || tagType==2 ); |
| 46 | 48 | pqueue_init(&queue); |
| 47 | 49 | pqueue_insert(&queue, pid, 0.0); |
| 50 | + |
| 51 | + /* Query for children of :pid to which to propagate the tag. |
| 52 | + ** Three returns: (1) rid of the child. (2) timestamp of child. |
| 53 | + ** (3) True to propagate or false to block. |
| 54 | + */ |
| 48 | 55 | db_prepare(&s, |
| 49 | 56 | "SELECT cid, plink.mtime," |
| 50 | 57 | " coalesce(srcid=0 AND tagxref.mtime<:mtime, %d) AS doit" |
| 51 | 58 | " FROM plink LEFT JOIN tagxref ON cid=rid AND tagid=%d" |
| 52 | 59 | " WHERE pid=:pid AND isprim", |
| 53 | | - tagType!=0, tagid |
| 60 | + tagType==2, tagid |
| 54 | 61 | ); |
| 55 | 62 | db_bind_double(&s, ":mtime", mtime); |
| 63 | + |
| 56 | 64 | if( tagType==2 ){ |
| 65 | + /* Set the propagated tag marker on checkin :rid */ |
| 57 | 66 | db_prepare(&ins, |
| 58 | 67 | "REPLACE INTO tagxref(tagid, tagtype, srcid, origid, value, mtime, rid)" |
| 59 | 68 | "VALUES(%d,2,0,%d,%Q,:mtime,:rid)", |
| 60 | 69 | tagid, origId, zValue |
| 61 | 70 | ); |
| 62 | 71 | db_bind_double(&ins, ":mtime", mtime); |
| 63 | 72 | }else{ |
| 73 | + /* Remove all references to the tag from checkin :rid */ |
| 64 | 74 | zValue = 0; |
| 65 | 75 | db_prepare(&ins, |
| 66 | 76 | "DELETE FROM tagxref WHERE tagid=%d AND rid=:rid", tagid |
| 67 | 77 | ); |
| 68 | 78 | } |
| 69 | 79 | |