Diff
Not logged in

Differences From:

File src/tag.c part of check-in [432d4391b9] - Fix a bug in the "leaves" page when the repository is empty. Begin adding support for the ability to erase tags. by drh on 2009-01-21 13:50:11. [view]

To:

File src/tag.c part of check-in [08db9e11cb] - Track the origin of tags and display that origin in the tag and properities information field of the "vinfo" page. Must "fossil rebuild" after this change. by drh on 2009-01-21 23:40:17. [view]

@@ -40,8 +40,9 @@
 void tag_propagate(
   int pid,             /* Propagate the tag to children of this node */
   int tagid,           /* Tag to propagate */
   int tagType,         /* 2 for a propagating tag.  0 for an antitag */
+  int origId,          /* Artifact of tag, when tagType==2 */
   const char *zValue,  /* Value of the tag.  Might be NULL */
   double mtime         /* Timestamp on the tag */
 ){
   PQueue queue;
@@ -59,11 +60,11 @@
   );
   db_bind_double(&s, ":mtime", mtime);
   if( tagType==2 ){
     db_prepare(&ins,
-       "REPLACE INTO tagxref(tagid, tagtype, srcid, value, mtime, rid)"
-       "VALUES(%d,2,0,%Q,:mtime,:rid)",
-       tagid, zValue
+       "REPLACE INTO tagxref(tagid, tagtype, srcid, origid, value, mtime, rid)"
+       "VALUES(%d,2,0,%d,%Q,:mtime,:rid)",
+       tagid, origId, zValue
     );
     db_bind_double(&ins, ":mtime", mtime);
   }else{
     zValue = 0;
@@ -109,9 +110,9 @@
 */
 void tag_propagate_all(int pid){
   Stmt q;
   db_prepare(&q,
-     "SELECT tagid, tagtype, mtime, value FROM tagxref"
+     "SELECT tagid, tagtype, mtime, value, origid FROM tagxref"
      " WHERE rid=%d"
      "   AND (tagtype=0 OR tagtype=2)",
      pid
   );
@@ -119,9 +120,10 @@
     int tagid = db_column_int(&q, 0);
     int tagtype = db_column_int(&q, 1);
     double mtime = db_column_double(&q, 2);
     const char *zValue = db_column_text(&q, 3);
-    tag_propagate(pid, tagid, tagtype, zValue, mtime);
+    int origid = db_column_int(&q, 4);
+    tag_propagate(pid, tagid, tagtype, origid, zValue, mtime);
   }
   db_finalize(&q);
 }
 
@@ -143,9 +145,9 @@
 ** Insert a tag into the database.
 */
 void tag_insert(
   const char *zTag,        /* Name of the tag (w/o the "+" or "-" prefix */
-  int tagtype,             /* 0:cancel  1:singleton  2:propagated -1:erase */
+  int tagtype,             /* 0:cancel  1:singleton  2:propagated */
   const char *zValue,      /* Value if the tag is really a property */
   int srcId,               /* Artifact that contains this tag */
   double mtime,            /* Timestamp.  Use default if <=0.0 */
   int rid                  /* Artifact to which the tag is to attached */
@@ -170,12 +172,8 @@
   db_finalize(&s);
   if( rc==SQLITE_ROW ){
     /* Another entry that is more recent already exists.  Do nothing */
     return;
-  }
-  if( tagtype<0 ){
-    return;
-    /* TBD: erase tags */
   }
   db_prepare(&s,
     "REPLACE INTO tagxref(tagid,tagtype,srcId,value,mtime,rid)"
     " VALUES(%d,%d,%d,%Q,:mtime,%d)",
@@ -205,9 +203,9 @@
   if( zCol ){
     db_multi_exec("UPDATE event SET %s=%Q WHERE objid=%d", zCol, zValue, rid);
   }
   if( tagtype==0 || tagtype==2 ){
-    tag_propagate(rid, tagid, tagtype, zValue, mtime);
+    tag_propagate(rid, tagid, tagtype, rid, zValue, mtime);
   }
 }