Diff
Not logged in

Differences From:

File src/content.c part of check-in [48c4e69d2b] - Cluster-based synchronization appears to be working. by drh on 2007-09-09 17:51:16. Also file src/content.c part of check-in [bbcb6326c9] - Pulled in the navbar and timeline changes. by aku on 2007-09-17 00:58:51. [view]

To:

File src/content.c part of check-in [fb90abe5bd] - Detect delta loops and make at least one member of the loop a phantom. by drh on 2007-12-03 14:42:32. Also file src/content.c part of check-in [d0305b305a] - Merged mainline into my branch to get the newest application. by aku on 2007-12-05 08:07:46. [view]

@@ -45,13 +45,25 @@
   Stmt q;
   Blob src;
   int srcid;
   int rc = 0;
+  static Bag inProcess;
 
   assert( g.repositoryOpen );
   srcid = findSrcid(rid);
   blob_zero(pBlob);
   if( srcid ){
+    if( bag_find(&inProcess, srcid) ){
+      db_multi_exec(
+        "UPDATE blob SET content=NULL, size=-1 WHERE rid=%d;"
+        "DELETE FROM delta WHERE rid=%d;"
+        "INSERT OR IGNORE INTO phantom VALUES(%d);",
+        srcid, srcid, srcid
+      );
+      blob_zero(pBlob);
+      return 0;
+    }
+    bag_insert(&inProcess, srcid);
     if( content_get(srcid, &src) ){
       db_prepare(&q, "SELECT content FROM blob WHERE rid=%d AND size>=0", rid);
       if( db_step(&q)==SQLITE_ROW ){
         Blob delta;
@@ -64,8 +76,9 @@
       }
       db_finalize(&q);
       blob_reset(&src);
     }
+    bag_remove(&inProcess, srcid);
   }else{
     db_prepare(&q, "SELECT content FROM blob WHERE rid=%d AND size>=0", rid);
     if( db_step(&q)==SQLITE_ROW ){
       db_ephemeral_blob(&q, 0, pBlob);
@@ -74,8 +87,34 @@
     }
     db_finalize(&q);
   }
   return rc;
+}
+
+/*
+** Get the contents of a file within a given revision.
+*/
+int content_get_historical_file(const char *revision, const char *file, Blob *content){
+  Blob mfile;
+  Manifest m;
+  int i, rid=0;
+
+  rid = name_to_rid(revision);
+  content_get(rid, &mfile);
+
+  if( manifest_parse(&m, &mfile) ){
+    for(i=0; i<m.nFile; i++){
+      if( strcmp(m.aFile[i].zName, file)==0 ){
+        rid = uuid_to_rid(m.aFile[i].zUuid, 0);
+        return content_get(rid, content);
+      }
+    }
+    fossil_panic("file: %s does not exist in revision: %s", file, revision);
+  }else{
+    fossil_panic("could not parse manifest for revision: %s", revision);
+  }
+
+  return 0;
 }
 
 /*
 ** COMMAND:  test-content-get