Check-in [e3c529c2f0]
Not logged in
Overview

SHA1 Hash:e3c529c2f066a72002964c1ae5d3fe5fabd7ecf0
Date: 2007-07-30 16:31:11
User: anonymous
Comment:Merge in clone and sync changes. Fix a bug in undelta.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/content.c from [fa624bb975] to [e02b11b8cf].

@@ -284,11 +284,11 @@
 ** converted to undeltaed text.
 */
 void content_deltify(int rid, int srcid, int force){
   int s;
   Blob data, src, delta;
-  static Stmt s1, s2;
+  Stmt s1, s2;
   if( srcid==rid ) return;
   if( !force && findSrcid(rid, 0)>0 ) return;
   s = srcid;
   while( (s = findSrcid(s, 0))>0 ){
     if( s==rid ){
@@ -300,20 +300,20 @@
   content_get(rid, &data);
   blob_delta_create(&src, &data, &delta);
   if( blob_size(&src)>=50 && blob_size(&data)>=50 &&
            blob_size(&delta) < blob_size(&data)*0.75 ){
     blob_compress(&delta, &delta);
-    db_static_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=:rid");
-    db_static_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(:rid,:sid)");
-    db_bind_int(&s1, ":rid", rid);
-    db_bind_blob(&s1, ":data", &delta);
-    db_bind_int(&s2, ":rid", rid);
+    db_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=%d", rid);
+    db_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(%d,:sid)", rid);
+    db_bind_blob(&s1, ":data", &delta);
     db_bind_int(&s2, ":sid", srcid);
     db_begin_transaction();
     db_exec(&s1);
     db_exec(&s2);
     db_end_transaction(0);
+    db_finalize(&s1);
+    db_finalize(&s2);
   }
   blob_reset(&src);
   blob_reset(&data);
   blob_reset(&delta);
   verify_before_commit(rid);

Modified src/db.c from [73fc8fe15d] to [44658ef357].

@@ -538,23 +538,26 @@
   if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
     db_err("pwd too big: max %d", sizeof(zPwd)-20);
   }
   n = strlen(zPwd);
   while( n>0 ){
-    if( access(zPwd, W_OK) ) return 0;
+    if( access(zPwd, W_OK) ) break;
     strcpy(&zPwd[n], "/_FOSSIL_");
     if( isValidLocalDb(zPwd) ){
+      /* Found a valid _FOSSIL_ file */
       zPwd[n] = 0;
       g.zLocalRoot = mprintf("%s/", zPwd);
-      break;
+      return 1;
     }
     n--;
     while( n>0 && zPwd[n]!='/' ){ n--; }
     while( n>0 && zPwd[n-1]=='/' ){ n--; }
     zPwd[n] = 0;
   }
-  return n>0;
+
+  /* A _FOSSIL_ file could not be found */
+  return 0;
 }
 
 /*
 ** Open the repository database given by zDbName.  If zDbName==NULL then
 ** get the name from the already open local database.
@@ -773,10 +776,41 @@
   return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName);
 }
 void db_lset_int(const char *zName, int value){
   db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
 }
+
+int db_row_to_table(const char *zFormat, ...){
+  Stmt q;
+  va_list ap;
+  int rc;
+
+  va_start(ap, zFormat);
+  rc = db_vprepare(&q, zFormat, ap);
+  va_end(ap);
+  if( rc!=SQLITE_OK ){
+    return rc;
+  }
+
+  @ <table border="0" cellpadding="0" cellspacing="0">
+  if( db_step(&q)==SQLITE_ROW ){
+    int ii;
+    for(ii=0; ii<sqlite3_column_count(q.pStmt); ii++){
+      char *zCol = htmlize(sqlite3_column_name(q.pStmt, ii), -1);
+      char *zVal = htmlize(sqlite3_column_text(q.pStmt, ii), -1);
+
+      @ <tr><td align=right>%s(zCol):<td width=10><td>%s(zVal)
+
+      free(zVal);
+      free(zCol);
+    }
+  }
+  @ </table>
+
+  return db_finalize(&q);
+}
+
 
 /*
 ** COMMAND: open
 **
 ** Create a new local repository.

Modified src/login.c from [769bfdbb7f] to [c801bf1f9b].

@@ -203,23 +203,19 @@
     g.isAnon = 0;
   }
 
   /* Check the login cookie to see if it matches a known valid user.
   */
-  if( uid==0 ){
-    if( (zCookie = P(login_cookie_name()))!=0 ){
-      uid = db_int(0,
-              "SELECT uid FROM user"
-              " WHERE uid=%d"
-              "   AND cookie=%Q"
-              "   AND ipaddr=%Q"
-              "   AND cexpire>julianday('now')",
-              atoi(zCookie), zCookie, zRemoteAddr
-           );
-    }else{
-      uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'");
-    }
+  if( uid==0 && (zCookie = P(login_cookie_name()))!=0 ){
+    uid = db_int(0,
+            "SELECT 1 FROM user"
+            " WHERE uid=%d"
+            "   AND cookie=%Q"
+            "   AND ipaddr=%Q"
+            "   AND cexpire>julianday('now')",
+            atoi(zCookie), zCookie, zRemoteAddr
+         );
   }
 
   if( uid==0 ){
     g.isAnon = 1;
     g.zLogin = "";

Modified src/xfer.c from [a734598a7e] to [5c87619787].

@@ -129,10 +129,11 @@
 
 /*
 ** Send all pending files.
 */
 static int send_all_pending(Blob *pOut){
+  int iRidSent = 0;
   int sent = 0;
   int nSent = 0;
   int maxSize = db_get_int("http-msg-size", 1000000);
   Stmt q;
 #if 0
@@ -156,16 +157,17 @@
       " SELECT rid FROM delta WHERE srcid=%d",
       rid, rid
     );
   }
 #endif
-  db_prepare(&q, "SELECT rid FROM pending");
+  db_prepare(&q, "SELECT rid FROM pending ORDER BY rid");
   while( db_step(&q)==SQLITE_ROW ){
     int rid = db_column_int(&q, 0);
     if( sent<maxSize ){
       sent += send_file(rid, pOut);
       nSent++;
+      iRidSent = rid;
     }else{
       char *zUuid = db_text(0,
                       "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
       if( zUuid ){
         if( pOut ){
@@ -176,10 +178,17 @@
         free(zUuid);
       }
     }
   }
   db_finalize(&q);
+
+  /* Delete the 'pending' records for all files just sent. Otherwise,
+  ** we can wind up sending some files more than once.
+  */
+  if( nSent>0 ){
+    db_multi_exec("DELETE FROM pending WHERE rid <= %d", iRidSent);
+  }
 
 #if 0
   db_multi_exec("DROP TABLE priority");
 #endif
   return nSent;