| | @@ -35,31 +35,33 @@ |
| 35 | 35 | ** |
| 36 | 36 | ** If addFlag is true then the tag is added. If false, then the |
| 37 | 37 | ** tag is removed. |
| 38 | 38 | */ |
| 39 | 39 | void tag_propagate( |
| 40 | | - int pid, /* Propagate the tag to children of this node */ |
| 41 | | - int tagid, /* Tag to propagate */ |
| 42 | | - int addFlag, /* True to add the tag. False to delete it. */ |
| 43 | | - double mtime /* Timestamp on the tag */ |
| 40 | + int pid, /* Propagate the tag to children of this node */ |
| 41 | + int tagid, /* Tag to propagate */ |
| 42 | + int addFlag, /* True to add the tag. False to delete it. */ |
| 43 | + const char *zValue, /* Value of the tag. Might be NULL */ |
| 44 | + double mtime /* Timestamp on the tag */ |
| 44 | 45 | ){ |
| 45 | 46 | PQueue queue; |
| 46 | 47 | Stmt s, ins; |
| 47 | 48 | pqueue_init(&queue); |
| 48 | 49 | pqueue_insert(&queue, pid, 0.0); |
| 49 | 50 | db_prepare(&s, |
| 50 | | - "SELECT cid, mtime, coalesce(srcid=0 AND mtime<:mtime, %d) AS doit" |
| 51 | + "SELECT cid, plink.mtime," |
| 52 | + " coalesce(srcid=0 AND tagxref.mtime<:mtime, %d) AS doit" |
| 51 | 53 | " FROM plink LEFT JOIN tagxref ON cid=rid AND tagid=%d" |
| 52 | 54 | " WHERE pid=:pid AND isprim", |
| 53 | 55 | addFlag, tagid |
| 54 | 56 | ); |
| 55 | 57 | db_bind_double(&s, ":mtime", mtime); |
| 56 | 58 | if( addFlag ){ |
| 57 | 59 | db_prepare(&ins, |
| 58 | | - "REPLACE INTO tagxref(tagid, addFlag, srcid, mtime, rid)" |
| 59 | | - "VALUES(%d,1,0,:mtime,:rid)", |
| 60 | | - tagid |
| 60 | + "REPLACE INTO tagxref(tagid, addFlag, srcid, value, mtime, rid)" |
| 61 | + "VALUES(%d,1,0,%Q,:mtime,:rid)", |
| 62 | + tagid, zValue |
| 61 | 63 | ); |
| 62 | 64 | db_bind_double(&ins, ":mtime", mtime); |
| 63 | 65 | }else{ |
| 64 | 66 | db_prepare(&ins, |
| 65 | 67 | "DELETE FROM tagxref WHERE tagid=%d AND rid=:rid", tagid |
| | @@ -89,18 +91,73 @@ |
| 89 | 91 | ** Propagate all propagatable tags in pid to its children. |
| 90 | 92 | */ |
| 91 | 93 | void tag_propagate_all(int pid){ |
| 92 | 94 | Stmt q; |
| 93 | 95 | db_prepare(&q, |
| 94 | | - "SELECT tagid, addflag, mtime FROM tagxref" |
| 96 | + "SELECT tagid, addflag, mtime, value FROM tagxref" |
| 95 | 97 | " WHERE rid=%d" |
| 96 | 98 | " AND (SELECT tagname FROM tag WHERE tagid=tagxref.tagid) LIKE 'br%'", |
| 97 | 99 | pid |
| 98 | 100 | ); |
| 99 | 101 | while( db_step(&q)==SQLITE_ROW ){ |
| 100 | 102 | int tagid = db_column_int(&q, 0); |
| 101 | 103 | int addflag = db_column_int(&q, 1); |
| 102 | 104 | double mtime = db_column_double(&q, 2); |
| 103 | | - tag_propagate(pid, tagid, addflag, mtime); |
| 105 | + const char *zValue = db_column_text(&q, 3); |
| 106 | + tag_propagate(pid, tagid, addflag, zValue, mtime); |
| 104 | 107 | } |
| 105 | 108 | db_finalize(&q); |
| 106 | 109 | } |
| 110 | + |
| 111 | +/* |
| 112 | +** Get a tagid for the given TAG. Create a new tag if necessary |
| 113 | +** if createFlag is 1. |
| 114 | +*/ |
| 115 | +int tag_findid(const char *zTag, int createFlag){ |
| 116 | + int id; |
| 117 | + id = db_int(0, "SELECT tagid FROM tag WHERE tagname=%Q", zTag); |
| 118 | + if( id==0 && createFlag ){ |
| 119 | + db_multi_exec("INSERT INTO tag(tagname) VALUES(%Q)", zTag); |
| 120 | + id = db_last_insert_rowid(); |
| 121 | + } |
| 122 | + return id; |
| 123 | +} |
| 124 | + |
| 125 | + |
| 126 | +/* |
| 127 | +** COMMAND: test-addtag |
| 128 | +** %fossil test-addtag TAGNAME UUID ?VALUE? |
| 129 | +** |
| 130 | +** Add a tag to the rebuildable tables of the local repository. |
| 131 | +** No tag artifact is created so the new tag is erased the next |
| 132 | +** time the repository is rebuilt. This routine is for testing |
| 133 | +** use only. |
| 134 | +*/ |
| 135 | +void addtag_cmd(void){ |
| 136 | + const char *zTag; |
| 137 | + const char *zValue; |
| 138 | + int tagid; |
| 139 | + int rid; |
| 140 | + double now; |
| 141 | + db_must_be_within_tree(); |
| 142 | + if( g.argc!=4 && g.argc!=5 ){ |
| 143 | + usage("TAGNAME UUID ?VALUE?"); |
| 144 | + } |
| 145 | + zTag = g.argv[2]; |
| 146 | + rid = name_to_rid(g.argv[3]); |
| 147 | + if( rid==0 ){ |
| 148 | + fossil_fatal("no such object: %s", g.argv[3]); |
| 149 | + } |
| 150 | + db_begin_transaction(); |
| 151 | + tagid = tag_findid(zTag, 1); |
| 152 | + zValue = g.argc==5 ? g.argv[4] : 0; |
| 153 | + db_multi_exec( |
| 154 | + "REPLACE INTO tagxref(tagid,addFlag,srcId,value,mtime,rid)" |
| 155 | + " VALUES(%d,1,-1,%Q,julianday('now'),%d)", |
| 156 | + tagid, rid, zValue, rid |
| 157 | + ); |
| 158 | + if( strncmp(zTag, "br", 2)==0 ){ |
| 159 | + now = db_double(0.0, "SELECT julianday('now')"); |
| 160 | + tag_propagate(rid, tagid, 1, zValue, now); |
| 161 | + } |
| 162 | + db_end_transaction(0); |
| 163 | +} |
| 107 | 164 | |