Fossil

Check-in [e3c529c2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge in clone and sync changes. Fix a bug in undelta.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e3c529c2f066a72002964c1ae5d3fe5fabd7ecf0
User & Date: dan 2007-07-30 16:31:11
Original User & Date: anonymous 2007-07-30 16:31:11
Context
2007-07-30
21:23
Fix another bug in the pivot finder. Null-merge with the dan-branch so that we now only have a single leaf on the tree. check-in: fa0ba20a user: drh tags: trunk
16:31
Merge in clone and sync changes. Fix a bug in undelta. check-in: e3c529c2 user: dan tags: trunk
14:28
Use POST instead of GET for the /xfer method. Other bug fixes in the URL parser. check-in: e621b6db user: drh tags: trunk
05:17
Delete records from the temporary table "pending" after sending them. check-in: 23c8dad3 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/content.c.

282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
...
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314


315
316
317
318
319
320
321
**
** If srcid is a delta that depends on rid, then srcid is
** converted to undeltaed text.
*/
void content_deltify(int rid, int srcid, int force){
  int s;
  Blob data, src, delta;
  static 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 ){
      content_undelta(srcid);
      break;
................................................................................
  }
  content_get(srcid, &src);
  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_bind_int(&s2, ":sid", srcid);
    db_begin_transaction();
    db_exec(&s1);
    db_exec(&s2);
    db_end_transaction(0);


  }
  blob_reset(&src);
  blob_reset(&data);
  blob_reset(&delta);
  verify_before_commit(rid);
}








|







 







|
|
<

<





>
>







282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
...
298
299
300
301
302
303
304
305
306

307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
**
** If srcid is a delta that depends on rid, then srcid is
** converted to undeltaed text.
*/
void content_deltify(int rid, int srcid, int force){
  int s;
  Blob data, src, delta;
  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 ){
      content_undelta(srcid);
      break;
................................................................................
  }
  content_get(srcid, &src);
  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_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);
}

Changes to src/db.c.

536
537
538
539
540
541
542
543
544
545

546
547
548

549
550
551
552
553
554


555
556
557
558
559
560
561
562
...
771
772
773
774
775
776
777































778
779
780
781
782
783
784
  char zPwd[2000];
  if( g.localOpen) return 1;
  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;
    strcpy(&zPwd[n], "/_FOSSIL_");
    if( isValidLocalDb(zPwd) ){

      zPwd[n] = 0;
      g.zLocalRoot = mprintf("%s/", zPwd);
      break;

    }
    n--;
    while( n>0 && zPwd[n]!='/' ){ n--; }
    while( n>0 && zPwd[n-1]=='/' ){ n--; }
    zPwd[n] = 0;
  }


  return n>0;
}

/*
** Open the repository database given by zDbName.  If zDbName==NULL then
** get the name from the already open local database.
*/
void db_open_repository(const char *zDbName){
................................................................................
}
int db_lget_int(const char *zName, int dflt){
  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);
}
































/*
** COMMAND: open
**
** Create a new local repository.
*/
void cmd_open(void){







|


>


<
>






>
>
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







536
537
538
539
540
541
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
...
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
  char zPwd[2000];
  if( g.localOpen) return 1;
  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) ) break;
    strcpy(&zPwd[n], "/_FOSSIL_");
    if( isValidLocalDb(zPwd) ){
      /* Found a valid _FOSSIL_ file */
      zPwd[n] = 0;
      g.zLocalRoot = mprintf("%s/", zPwd);

      return 1;
    }
    n--;
    while( n>0 && zPwd[n]!='/' ){ n--; }
    while( n>0 && zPwd[n-1]=='/' ){ n--; }
    zPwd[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.
*/
void db_open_repository(const char *zDbName){
................................................................................
}
int db_lget_int(const char *zName, int dflt){
  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.
*/
void cmd_open(void){

Changes to src/login.c.

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
    zCap = "s";
    g.noPswd = 1;
    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 ){
    g.isAnon = 1;
    g.zLogin = "";
    zCap = db_get("nologin-cap","onrj");
  }else if( zCap==0 ){







<
|
|
|
|
|
|
|
|
|
<
<
<







201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216



217
218
219
220
221
222
223
    zCap = "s";
    g.noPswd = 1;
    g.isAnon = 0;
  }

  /* Check the login cookie to see if it matches a known valid user.
  */

  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 = "";
    zCap = db_get("nologin-cap","onrj");
  }else if( zCap==0 ){

Changes to src/xfer.c.

127
128
129
130
131
132
133

134
135
136
137
138
139
140
...
154
155
156
157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
...
175
176
177
178
179
180
181







182
183
184
185
186
187
188
}


/*
** Send all pending files.
*/
static int send_all_pending(Blob *pOut){

  int sent = 0;
  int nSent = 0;
  int maxSize = db_get_int("http-msg-size", 1000000);
  Stmt q;
#if 0
  db_multi_exec(
    "CREATE TEMP TABLE priority(rid INTEGER PRIMARY KEY);"
................................................................................
      " SELECT srcid FROM delta WHERE rid=%d"
      " UNION ALL"
      " SELECT rid FROM delta WHERE srcid=%d",
      rid, rid
    );
  }
#endif
  db_prepare(&q, "SELECT rid FROM pending");
  while( db_step(&q)==SQLITE_ROW ){
    int rid = db_column_int(&q, 0);
    if( sent<maxSize ){
      sent += send_file(rid, pOut);
      nSent++;

    }else{
      char *zUuid = db_text(0,
                      "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
      if( zUuid ){
        if( pOut ){
          blob_appendf(pOut, "igot %s\n", zUuid);
        }else{
................................................................................
        }
        free(zUuid);
      }
    }
  }
  db_finalize(&q);
  







#if 0
  db_multi_exec("DROP TABLE priority");
#endif
  return nSent;
}









>







 







|





>







 







>
>
>
>
>
>
>







127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
}


/*
** 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
  db_multi_exec(
    "CREATE TEMP TABLE priority(rid INTEGER PRIMARY KEY);"
................................................................................
      " SELECT srcid FROM delta WHERE rid=%d"
      " UNION ALL"
      " SELECT rid FROM delta WHERE srcid=%d",
      rid, rid
    );
  }
#endif
  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 ){
          blob_appendf(pOut, "igot %s\n", zUuid);
        }else{
................................................................................
        }
        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;
}