Fossil SCM
Merge in clone and sync changes. Fix a bug in undelta.
Commit
e3c529c2f066a72002964c1ae5d3fe5fabd7ecf0
Parent
e621b6dbe310661…
7 files changed
+5
-5
+5
-5
+37
-3
+37
-3
+9
-13
+10
-1
+10
-1
+5
-5
| --- src/content.c | ||
| +++ src/content.c | ||
| @@ -284,11 +284,11 @@ | ||
| 284 | 284 | ** converted to undeltaed text. |
| 285 | 285 | */ |
| 286 | 286 | void content_deltify(int rid, int srcid, int force){ |
| 287 | 287 | int s; |
| 288 | 288 | Blob data, src, delta; |
| 289 | - static Stmt s1, s2; | |
| 289 | + Stmt s1, s2; | |
| 290 | 290 | if( srcid==rid ) return; |
| 291 | 291 | if( !force && findSrcid(rid, 0)>0 ) return; |
| 292 | 292 | s = srcid; |
| 293 | 293 | while( (s = findSrcid(s, 0))>0 ){ |
| 294 | 294 | if( s==rid ){ |
| @@ -300,20 +300,20 @@ | ||
| 300 | 300 | content_get(rid, &data); |
| 301 | 301 | blob_delta_create(&src, &data, &delta); |
| 302 | 302 | if( blob_size(&src)>=50 && blob_size(&data)>=50 && |
| 303 | 303 | blob_size(&delta) < blob_size(&data)*0.75 ){ |
| 304 | 304 | blob_compress(&delta, &delta); |
| 305 | - db_static_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=:rid"); | |
| 306 | - db_static_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(:rid,:sid)"); | |
| 307 | - db_bind_int(&s1, ":rid", rid); | |
| 305 | + db_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=%d", rid); | |
| 306 | + db_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(%d,:sid)", rid); | |
| 308 | 307 | db_bind_blob(&s1, ":data", &delta); |
| 309 | - db_bind_int(&s2, ":rid", rid); | |
| 310 | 308 | db_bind_int(&s2, ":sid", srcid); |
| 311 | 309 | db_begin_transaction(); |
| 312 | 310 | db_exec(&s1); |
| 313 | 311 | db_exec(&s2); |
| 314 | 312 | db_end_transaction(0); |
| 313 | + db_finalize(&s1); | |
| 314 | + db_finalize(&s2); | |
| 315 | 315 | } |
| 316 | 316 | blob_reset(&src); |
| 317 | 317 | blob_reset(&data); |
| 318 | 318 | blob_reset(&delta); |
| 319 | 319 | verify_before_commit(rid); |
| 320 | 320 |
| --- src/content.c | |
| +++ src/content.c | |
| @@ -284,11 +284,11 @@ | |
| 284 | ** converted to undeltaed text. |
| 285 | */ |
| 286 | void content_deltify(int rid, int srcid, int force){ |
| 287 | int s; |
| 288 | Blob data, src, delta; |
| 289 | static Stmt s1, s2; |
| 290 | if( srcid==rid ) return; |
| 291 | if( !force && findSrcid(rid, 0)>0 ) return; |
| 292 | s = srcid; |
| 293 | while( (s = findSrcid(s, 0))>0 ){ |
| 294 | if( s==rid ){ |
| @@ -300,20 +300,20 @@ | |
| 300 | content_get(rid, &data); |
| 301 | blob_delta_create(&src, &data, &delta); |
| 302 | if( blob_size(&src)>=50 && blob_size(&data)>=50 && |
| 303 | blob_size(&delta) < blob_size(&data)*0.75 ){ |
| 304 | blob_compress(&delta, &delta); |
| 305 | db_static_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=:rid"); |
| 306 | db_static_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(:rid,:sid)"); |
| 307 | db_bind_int(&s1, ":rid", rid); |
| 308 | db_bind_blob(&s1, ":data", &delta); |
| 309 | db_bind_int(&s2, ":rid", rid); |
| 310 | db_bind_int(&s2, ":sid", srcid); |
| 311 | db_begin_transaction(); |
| 312 | db_exec(&s1); |
| 313 | db_exec(&s2); |
| 314 | db_end_transaction(0); |
| 315 | } |
| 316 | blob_reset(&src); |
| 317 | blob_reset(&data); |
| 318 | blob_reset(&delta); |
| 319 | verify_before_commit(rid); |
| 320 |
| --- src/content.c | |
| +++ src/content.c | |
| @@ -284,11 +284,11 @@ | |
| 284 | ** converted to undeltaed text. |
| 285 | */ |
| 286 | void content_deltify(int rid, int srcid, int force){ |
| 287 | int s; |
| 288 | Blob data, src, delta; |
| 289 | Stmt s1, s2; |
| 290 | if( srcid==rid ) return; |
| 291 | if( !force && findSrcid(rid, 0)>0 ) return; |
| 292 | s = srcid; |
| 293 | while( (s = findSrcid(s, 0))>0 ){ |
| 294 | if( s==rid ){ |
| @@ -300,20 +300,20 @@ | |
| 300 | content_get(rid, &data); |
| 301 | blob_delta_create(&src, &data, &delta); |
| 302 | if( blob_size(&src)>=50 && blob_size(&data)>=50 && |
| 303 | blob_size(&delta) < blob_size(&data)*0.75 ){ |
| 304 | blob_compress(&delta, &delta); |
| 305 | db_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=%d", rid); |
| 306 | db_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(%d,:sid)", rid); |
| 307 | db_bind_blob(&s1, ":data", &delta); |
| 308 | db_bind_int(&s2, ":sid", srcid); |
| 309 | db_begin_transaction(); |
| 310 | db_exec(&s1); |
| 311 | db_exec(&s2); |
| 312 | db_end_transaction(0); |
| 313 | db_finalize(&s1); |
| 314 | db_finalize(&s2); |
| 315 | } |
| 316 | blob_reset(&src); |
| 317 | blob_reset(&data); |
| 318 | blob_reset(&delta); |
| 319 | verify_before_commit(rid); |
| 320 |
+5
-5
| --- src/content.c | ||
| +++ src/content.c | ||
| @@ -284,11 +284,11 @@ | ||
| 284 | 284 | ** converted to undeltaed text. |
| 285 | 285 | */ |
| 286 | 286 | void content_deltify(int rid, int srcid, int force){ |
| 287 | 287 | int s; |
| 288 | 288 | Blob data, src, delta; |
| 289 | - static Stmt s1, s2; | |
| 289 | + Stmt s1, s2; | |
| 290 | 290 | if( srcid==rid ) return; |
| 291 | 291 | if( !force && findSrcid(rid, 0)>0 ) return; |
| 292 | 292 | s = srcid; |
| 293 | 293 | while( (s = findSrcid(s, 0))>0 ){ |
| 294 | 294 | if( s==rid ){ |
| @@ -300,20 +300,20 @@ | ||
| 300 | 300 | content_get(rid, &data); |
| 301 | 301 | blob_delta_create(&src, &data, &delta); |
| 302 | 302 | if( blob_size(&src)>=50 && blob_size(&data)>=50 && |
| 303 | 303 | blob_size(&delta) < blob_size(&data)*0.75 ){ |
| 304 | 304 | blob_compress(&delta, &delta); |
| 305 | - db_static_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=:rid"); | |
| 306 | - db_static_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(:rid,:sid)"); | |
| 307 | - db_bind_int(&s1, ":rid", rid); | |
| 305 | + db_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=%d", rid); | |
| 306 | + db_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(%d,:sid)", rid); | |
| 308 | 307 | db_bind_blob(&s1, ":data", &delta); |
| 309 | - db_bind_int(&s2, ":rid", rid); | |
| 310 | 308 | db_bind_int(&s2, ":sid", srcid); |
| 311 | 309 | db_begin_transaction(); |
| 312 | 310 | db_exec(&s1); |
| 313 | 311 | db_exec(&s2); |
| 314 | 312 | db_end_transaction(0); |
| 313 | + db_finalize(&s1); | |
| 314 | + db_finalize(&s2); | |
| 315 | 315 | } |
| 316 | 316 | blob_reset(&src); |
| 317 | 317 | blob_reset(&data); |
| 318 | 318 | blob_reset(&delta); |
| 319 | 319 | verify_before_commit(rid); |
| 320 | 320 |
| --- src/content.c | |
| +++ src/content.c | |
| @@ -284,11 +284,11 @@ | |
| 284 | ** converted to undeltaed text. |
| 285 | */ |
| 286 | void content_deltify(int rid, int srcid, int force){ |
| 287 | int s; |
| 288 | Blob data, src, delta; |
| 289 | static Stmt s1, s2; |
| 290 | if( srcid==rid ) return; |
| 291 | if( !force && findSrcid(rid, 0)>0 ) return; |
| 292 | s = srcid; |
| 293 | while( (s = findSrcid(s, 0))>0 ){ |
| 294 | if( s==rid ){ |
| @@ -300,20 +300,20 @@ | |
| 300 | content_get(rid, &data); |
| 301 | blob_delta_create(&src, &data, &delta); |
| 302 | if( blob_size(&src)>=50 && blob_size(&data)>=50 && |
| 303 | blob_size(&delta) < blob_size(&data)*0.75 ){ |
| 304 | blob_compress(&delta, &delta); |
| 305 | db_static_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=:rid"); |
| 306 | db_static_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(:rid,:sid)"); |
| 307 | db_bind_int(&s1, ":rid", rid); |
| 308 | db_bind_blob(&s1, ":data", &delta); |
| 309 | db_bind_int(&s2, ":rid", rid); |
| 310 | db_bind_int(&s2, ":sid", srcid); |
| 311 | db_begin_transaction(); |
| 312 | db_exec(&s1); |
| 313 | db_exec(&s2); |
| 314 | db_end_transaction(0); |
| 315 | } |
| 316 | blob_reset(&src); |
| 317 | blob_reset(&data); |
| 318 | blob_reset(&delta); |
| 319 | verify_before_commit(rid); |
| 320 |
| --- src/content.c | |
| +++ src/content.c | |
| @@ -284,11 +284,11 @@ | |
| 284 | ** converted to undeltaed text. |
| 285 | */ |
| 286 | void content_deltify(int rid, int srcid, int force){ |
| 287 | int s; |
| 288 | Blob data, src, delta; |
| 289 | Stmt s1, s2; |
| 290 | if( srcid==rid ) return; |
| 291 | if( !force && findSrcid(rid, 0)>0 ) return; |
| 292 | s = srcid; |
| 293 | while( (s = findSrcid(s, 0))>0 ){ |
| 294 | if( s==rid ){ |
| @@ -300,20 +300,20 @@ | |
| 300 | content_get(rid, &data); |
| 301 | blob_delta_create(&src, &data, &delta); |
| 302 | if( blob_size(&src)>=50 && blob_size(&data)>=50 && |
| 303 | blob_size(&delta) < blob_size(&data)*0.75 ){ |
| 304 | blob_compress(&delta, &delta); |
| 305 | db_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=%d", rid); |
| 306 | db_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(%d,:sid)", rid); |
| 307 | db_bind_blob(&s1, ":data", &delta); |
| 308 | db_bind_int(&s2, ":sid", srcid); |
| 309 | db_begin_transaction(); |
| 310 | db_exec(&s1); |
| 311 | db_exec(&s2); |
| 312 | db_end_transaction(0); |
| 313 | db_finalize(&s1); |
| 314 | db_finalize(&s2); |
| 315 | } |
| 316 | blob_reset(&src); |
| 317 | blob_reset(&data); |
| 318 | blob_reset(&delta); |
| 319 | verify_before_commit(rid); |
| 320 |
M
src/db.c
+37
-3
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -538,23 +538,26 @@ | ||
| 538 | 538 | if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){ |
| 539 | 539 | db_err("pwd too big: max %d", sizeof(zPwd)-20); |
| 540 | 540 | } |
| 541 | 541 | n = strlen(zPwd); |
| 542 | 542 | while( n>0 ){ |
| 543 | - if( access(zPwd, W_OK) ) return 0; | |
| 543 | + if( access(zPwd, W_OK) ) break; | |
| 544 | 544 | strcpy(&zPwd[n], "/_FOSSIL_"); |
| 545 | 545 | if( isValidLocalDb(zPwd) ){ |
| 546 | + /* Found a valid _FOSSIL_ file */ | |
| 546 | 547 | zPwd[n] = 0; |
| 547 | 548 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 548 | - break; | |
| 549 | + return 1; | |
| 549 | 550 | } |
| 550 | 551 | n--; |
| 551 | 552 | while( n>0 && zPwd[n]!='/' ){ n--; } |
| 552 | 553 | while( n>0 && zPwd[n-1]=='/' ){ n--; } |
| 553 | 554 | zPwd[n] = 0; |
| 554 | 555 | } |
| 555 | - return n>0; | |
| 556 | + | |
| 557 | + /* A _FOSSIL_ file could not be found */ | |
| 558 | + return 0; | |
| 556 | 559 | } |
| 557 | 560 | |
| 558 | 561 | /* |
| 559 | 562 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 560 | 563 | ** get the name from the already open local database. |
| @@ -773,10 +776,41 @@ | ||
| 773 | 776 | return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName); |
| 774 | 777 | } |
| 775 | 778 | void db_lset_int(const char *zName, int value){ |
| 776 | 779 | db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value); |
| 777 | 780 | } |
| 781 | + | |
| 782 | +int db_row_to_table(const char *zFormat, ...){ | |
| 783 | + Stmt q; | |
| 784 | + va_list ap; | |
| 785 | + int rc; | |
| 786 | + | |
| 787 | + va_start(ap, zFormat); | |
| 788 | + rc = db_vprepare(&q, zFormat, ap); | |
| 789 | + va_end(ap); | |
| 790 | + if( rc!=SQLITE_OK ){ | |
| 791 | + return rc; | |
| 792 | + } | |
| 793 | + | |
| 794 | + @ <table border="0" cellpadding="0" cellspacing="0"> | |
| 795 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 796 | + int ii; | |
| 797 | + for(ii=0; ii<sqlite3_column_count(q.pStmt); ii++){ | |
| 798 | + char *zCol = htmlize(sqlite3_column_name(q.pStmt, ii), -1); | |
| 799 | + char *zVal = htmlize(sqlite3_column_text(q.pStmt, ii), -1); | |
| 800 | + | |
| 801 | + @ <tr><td align=right>%s(zCol):<td width=10><td>%s(zVal) | |
| 802 | + | |
| 803 | + free(zVal); | |
| 804 | + free(zCol); | |
| 805 | + } | |
| 806 | + } | |
| 807 | + @ </table> | |
| 808 | + | |
| 809 | + return db_finalize(&q); | |
| 810 | +} | |
| 811 | + | |
| 778 | 812 | |
| 779 | 813 | /* |
| 780 | 814 | ** COMMAND: open |
| 781 | 815 | ** |
| 782 | 816 | ** Create a new local repository. |
| 783 | 817 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -538,23 +538,26 @@ | |
| 538 | if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){ |
| 539 | db_err("pwd too big: max %d", sizeof(zPwd)-20); |
| 540 | } |
| 541 | n = strlen(zPwd); |
| 542 | while( n>0 ){ |
| 543 | if( access(zPwd, W_OK) ) return 0; |
| 544 | strcpy(&zPwd[n], "/_FOSSIL_"); |
| 545 | if( isValidLocalDb(zPwd) ){ |
| 546 | zPwd[n] = 0; |
| 547 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 548 | break; |
| 549 | } |
| 550 | n--; |
| 551 | while( n>0 && zPwd[n]!='/' ){ n--; } |
| 552 | while( n>0 && zPwd[n-1]=='/' ){ n--; } |
| 553 | zPwd[n] = 0; |
| 554 | } |
| 555 | return n>0; |
| 556 | } |
| 557 | |
| 558 | /* |
| 559 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 560 | ** get the name from the already open local database. |
| @@ -773,10 +776,41 @@ | |
| 773 | return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName); |
| 774 | } |
| 775 | void db_lset_int(const char *zName, int value){ |
| 776 | db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value); |
| 777 | } |
| 778 | |
| 779 | /* |
| 780 | ** COMMAND: open |
| 781 | ** |
| 782 | ** Create a new local repository. |
| 783 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -538,23 +538,26 @@ | |
| 538 | if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){ |
| 539 | db_err("pwd too big: max %d", sizeof(zPwd)-20); |
| 540 | } |
| 541 | n = strlen(zPwd); |
| 542 | while( n>0 ){ |
| 543 | if( access(zPwd, W_OK) ) break; |
| 544 | strcpy(&zPwd[n], "/_FOSSIL_"); |
| 545 | if( isValidLocalDb(zPwd) ){ |
| 546 | /* Found a valid _FOSSIL_ file */ |
| 547 | zPwd[n] = 0; |
| 548 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 549 | return 1; |
| 550 | } |
| 551 | n--; |
| 552 | while( n>0 && zPwd[n]!='/' ){ n--; } |
| 553 | while( n>0 && zPwd[n-1]=='/' ){ n--; } |
| 554 | zPwd[n] = 0; |
| 555 | } |
| 556 | |
| 557 | /* A _FOSSIL_ file could not be found */ |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 563 | ** get the name from the already open local database. |
| @@ -773,10 +776,41 @@ | |
| 776 | return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName); |
| 777 | } |
| 778 | void db_lset_int(const char *zName, int value){ |
| 779 | db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value); |
| 780 | } |
| 781 | |
| 782 | int db_row_to_table(const char *zFormat, ...){ |
| 783 | Stmt q; |
| 784 | va_list ap; |
| 785 | int rc; |
| 786 | |
| 787 | va_start(ap, zFormat); |
| 788 | rc = db_vprepare(&q, zFormat, ap); |
| 789 | va_end(ap); |
| 790 | if( rc!=SQLITE_OK ){ |
| 791 | return rc; |
| 792 | } |
| 793 | |
| 794 | @ <table border="0" cellpadding="0" cellspacing="0"> |
| 795 | if( db_step(&q)==SQLITE_ROW ){ |
| 796 | int ii; |
| 797 | for(ii=0; ii<sqlite3_column_count(q.pStmt); ii++){ |
| 798 | char *zCol = htmlize(sqlite3_column_name(q.pStmt, ii), -1); |
| 799 | char *zVal = htmlize(sqlite3_column_text(q.pStmt, ii), -1); |
| 800 | |
| 801 | @ <tr><td align=right>%s(zCol):<td width=10><td>%s(zVal) |
| 802 | |
| 803 | free(zVal); |
| 804 | free(zCol); |
| 805 | } |
| 806 | } |
| 807 | @ </table> |
| 808 | |
| 809 | return db_finalize(&q); |
| 810 | } |
| 811 | |
| 812 | |
| 813 | /* |
| 814 | ** COMMAND: open |
| 815 | ** |
| 816 | ** Create a new local repository. |
| 817 |
M
src/db.c
+37
-3
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -538,23 +538,26 @@ | ||
| 538 | 538 | if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){ |
| 539 | 539 | db_err("pwd too big: max %d", sizeof(zPwd)-20); |
| 540 | 540 | } |
| 541 | 541 | n = strlen(zPwd); |
| 542 | 542 | while( n>0 ){ |
| 543 | - if( access(zPwd, W_OK) ) return 0; | |
| 543 | + if( access(zPwd, W_OK) ) break; | |
| 544 | 544 | strcpy(&zPwd[n], "/_FOSSIL_"); |
| 545 | 545 | if( isValidLocalDb(zPwd) ){ |
| 546 | + /* Found a valid _FOSSIL_ file */ | |
| 546 | 547 | zPwd[n] = 0; |
| 547 | 548 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 548 | - break; | |
| 549 | + return 1; | |
| 549 | 550 | } |
| 550 | 551 | n--; |
| 551 | 552 | while( n>0 && zPwd[n]!='/' ){ n--; } |
| 552 | 553 | while( n>0 && zPwd[n-1]=='/' ){ n--; } |
| 553 | 554 | zPwd[n] = 0; |
| 554 | 555 | } |
| 555 | - return n>0; | |
| 556 | + | |
| 557 | + /* A _FOSSIL_ file could not be found */ | |
| 558 | + return 0; | |
| 556 | 559 | } |
| 557 | 560 | |
| 558 | 561 | /* |
| 559 | 562 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 560 | 563 | ** get the name from the already open local database. |
| @@ -773,10 +776,41 @@ | ||
| 773 | 776 | return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName); |
| 774 | 777 | } |
| 775 | 778 | void db_lset_int(const char *zName, int value){ |
| 776 | 779 | db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value); |
| 777 | 780 | } |
| 781 | + | |
| 782 | +int db_row_to_table(const char *zFormat, ...){ | |
| 783 | + Stmt q; | |
| 784 | + va_list ap; | |
| 785 | + int rc; | |
| 786 | + | |
| 787 | + va_start(ap, zFormat); | |
| 788 | + rc = db_vprepare(&q, zFormat, ap); | |
| 789 | + va_end(ap); | |
| 790 | + if( rc!=SQLITE_OK ){ | |
| 791 | + return rc; | |
| 792 | + } | |
| 793 | + | |
| 794 | + @ <table border="0" cellpadding="0" cellspacing="0"> | |
| 795 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 796 | + int ii; | |
| 797 | + for(ii=0; ii<sqlite3_column_count(q.pStmt); ii++){ | |
| 798 | + char *zCol = htmlize(sqlite3_column_name(q.pStmt, ii), -1); | |
| 799 | + char *zVal = htmlize(sqlite3_column_text(q.pStmt, ii), -1); | |
| 800 | + | |
| 801 | + @ <tr><td align=right>%s(zCol):<td width=10><td>%s(zVal) | |
| 802 | + | |
| 803 | + free(zVal); | |
| 804 | + free(zCol); | |
| 805 | + } | |
| 806 | + } | |
| 807 | + @ </table> | |
| 808 | + | |
| 809 | + return db_finalize(&q); | |
| 810 | +} | |
| 811 | + | |
| 778 | 812 | |
| 779 | 813 | /* |
| 780 | 814 | ** COMMAND: open |
| 781 | 815 | ** |
| 782 | 816 | ** Create a new local repository. |
| 783 | 817 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -538,23 +538,26 @@ | |
| 538 | if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){ |
| 539 | db_err("pwd too big: max %d", sizeof(zPwd)-20); |
| 540 | } |
| 541 | n = strlen(zPwd); |
| 542 | while( n>0 ){ |
| 543 | if( access(zPwd, W_OK) ) return 0; |
| 544 | strcpy(&zPwd[n], "/_FOSSIL_"); |
| 545 | if( isValidLocalDb(zPwd) ){ |
| 546 | zPwd[n] = 0; |
| 547 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 548 | break; |
| 549 | } |
| 550 | n--; |
| 551 | while( n>0 && zPwd[n]!='/' ){ n--; } |
| 552 | while( n>0 && zPwd[n-1]=='/' ){ n--; } |
| 553 | zPwd[n] = 0; |
| 554 | } |
| 555 | return n>0; |
| 556 | } |
| 557 | |
| 558 | /* |
| 559 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 560 | ** get the name from the already open local database. |
| @@ -773,10 +776,41 @@ | |
| 773 | return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName); |
| 774 | } |
| 775 | void db_lset_int(const char *zName, int value){ |
| 776 | db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value); |
| 777 | } |
| 778 | |
| 779 | /* |
| 780 | ** COMMAND: open |
| 781 | ** |
| 782 | ** Create a new local repository. |
| 783 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -538,23 +538,26 @@ | |
| 538 | if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){ |
| 539 | db_err("pwd too big: max %d", sizeof(zPwd)-20); |
| 540 | } |
| 541 | n = strlen(zPwd); |
| 542 | while( n>0 ){ |
| 543 | if( access(zPwd, W_OK) ) break; |
| 544 | strcpy(&zPwd[n], "/_FOSSIL_"); |
| 545 | if( isValidLocalDb(zPwd) ){ |
| 546 | /* Found a valid _FOSSIL_ file */ |
| 547 | zPwd[n] = 0; |
| 548 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 549 | return 1; |
| 550 | } |
| 551 | n--; |
| 552 | while( n>0 && zPwd[n]!='/' ){ n--; } |
| 553 | while( n>0 && zPwd[n-1]=='/' ){ n--; } |
| 554 | zPwd[n] = 0; |
| 555 | } |
| 556 | |
| 557 | /* A _FOSSIL_ file could not be found */ |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 563 | ** get the name from the already open local database. |
| @@ -773,10 +776,41 @@ | |
| 776 | return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName); |
| 777 | } |
| 778 | void db_lset_int(const char *zName, int value){ |
| 779 | db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value); |
| 780 | } |
| 781 | |
| 782 | int db_row_to_table(const char *zFormat, ...){ |
| 783 | Stmt q; |
| 784 | va_list ap; |
| 785 | int rc; |
| 786 | |
| 787 | va_start(ap, zFormat); |
| 788 | rc = db_vprepare(&q, zFormat, ap); |
| 789 | va_end(ap); |
| 790 | if( rc!=SQLITE_OK ){ |
| 791 | return rc; |
| 792 | } |
| 793 | |
| 794 | @ <table border="0" cellpadding="0" cellspacing="0"> |
| 795 | if( db_step(&q)==SQLITE_ROW ){ |
| 796 | int ii; |
| 797 | for(ii=0; ii<sqlite3_column_count(q.pStmt); ii++){ |
| 798 | char *zCol = htmlize(sqlite3_column_name(q.pStmt, ii), -1); |
| 799 | char *zVal = htmlize(sqlite3_column_text(q.pStmt, ii), -1); |
| 800 | |
| 801 | @ <tr><td align=right>%s(zCol):<td width=10><td>%s(zVal) |
| 802 | |
| 803 | free(zVal); |
| 804 | free(zCol); |
| 805 | } |
| 806 | } |
| 807 | @ </table> |
| 808 | |
| 809 | return db_finalize(&q); |
| 810 | } |
| 811 | |
| 812 | |
| 813 | /* |
| 814 | ** COMMAND: open |
| 815 | ** |
| 816 | ** Create a new local repository. |
| 817 |
+9
-13
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -203,23 +203,19 @@ | ||
| 203 | 203 | g.isAnon = 0; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /* Check the login cookie to see if it matches a known valid user. |
| 207 | 207 | */ |
| 208 | - if( uid==0 ){ | |
| 209 | - if( (zCookie = P(login_cookie_name()))!=0 ){ | |
| 210 | - uid = db_int(0, | |
| 211 | - "SELECT uid FROM user" | |
| 212 | - " WHERE uid=%d" | |
| 213 | - " AND cookie=%Q" | |
| 214 | - " AND ipaddr=%Q" | |
| 215 | - " AND cexpire>julianday('now')", | |
| 216 | - atoi(zCookie), zCookie, zRemoteAddr | |
| 217 | - ); | |
| 218 | - }else{ | |
| 219 | - uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'"); | |
| 220 | - } | |
| 208 | + if( uid==0 && (zCookie = P(login_cookie_name()))!=0 ){ | |
| 209 | + uid = db_int(0, | |
| 210 | + "SELECT 1 FROM user" | |
| 211 | + " WHERE uid=%d" | |
| 212 | + " AND cookie=%Q" | |
| 213 | + " AND ipaddr=%Q" | |
| 214 | + " AND cexpire>julianday('now')", | |
| 215 | + atoi(zCookie), zCookie, zRemoteAddr | |
| 216 | + ); | |
| 221 | 217 | } |
| 222 | 218 | |
| 223 | 219 | if( uid==0 ){ |
| 224 | 220 | g.isAnon = 1; |
| 225 | 221 | g.zLogin = ""; |
| 226 | 222 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -203,23 +203,19 @@ | |
| 203 | g.isAnon = 0; |
| 204 | } |
| 205 | |
| 206 | /* Check the login cookie to see if it matches a known valid user. |
| 207 | */ |
| 208 | if( uid==0 ){ |
| 209 | if( (zCookie = P(login_cookie_name()))!=0 ){ |
| 210 | uid = db_int(0, |
| 211 | "SELECT uid FROM user" |
| 212 | " WHERE uid=%d" |
| 213 | " AND cookie=%Q" |
| 214 | " AND ipaddr=%Q" |
| 215 | " AND cexpire>julianday('now')", |
| 216 | atoi(zCookie), zCookie, zRemoteAddr |
| 217 | ); |
| 218 | }else{ |
| 219 | uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'"); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | if( uid==0 ){ |
| 224 | g.isAnon = 1; |
| 225 | g.zLogin = ""; |
| 226 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -203,23 +203,19 @@ | |
| 203 | g.isAnon = 0; |
| 204 | } |
| 205 | |
| 206 | /* Check the login cookie to see if it matches a known valid user. |
| 207 | */ |
| 208 | if( uid==0 && (zCookie = P(login_cookie_name()))!=0 ){ |
| 209 | uid = db_int(0, |
| 210 | "SELECT 1 FROM user" |
| 211 | " WHERE uid=%d" |
| 212 | " AND cookie=%Q" |
| 213 | " AND ipaddr=%Q" |
| 214 | " AND cexpire>julianday('now')", |
| 215 | atoi(zCookie), zCookie, zRemoteAddr |
| 216 | ); |
| 217 | } |
| 218 | |
| 219 | if( uid==0 ){ |
| 220 | g.isAnon = 1; |
| 221 | g.zLogin = ""; |
| 222 |
+10
-1
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -129,10 +129,11 @@ | ||
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | ** Send all pending files. |
| 132 | 132 | */ |
| 133 | 133 | static int send_all_pending(Blob *pOut){ |
| 134 | + int iRidSent = 0; | |
| 134 | 135 | int sent = 0; |
| 135 | 136 | int nSent = 0; |
| 136 | 137 | int maxSize = db_get_int("http-msg-size", 1000000); |
| 137 | 138 | Stmt q; |
| 138 | 139 | #if 0 |
| @@ -156,16 +157,17 @@ | ||
| 156 | 157 | " SELECT rid FROM delta WHERE srcid=%d", |
| 157 | 158 | rid, rid |
| 158 | 159 | ); |
| 159 | 160 | } |
| 160 | 161 | #endif |
| 161 | - db_prepare(&q, "SELECT rid FROM pending"); | |
| 162 | + db_prepare(&q, "SELECT rid FROM pending ORDER BY rid"); | |
| 162 | 163 | while( db_step(&q)==SQLITE_ROW ){ |
| 163 | 164 | int rid = db_column_int(&q, 0); |
| 164 | 165 | if( sent<maxSize ){ |
| 165 | 166 | sent += send_file(rid, pOut); |
| 166 | 167 | nSent++; |
| 168 | + iRidSent = rid; | |
| 167 | 169 | }else{ |
| 168 | 170 | char *zUuid = db_text(0, |
| 169 | 171 | "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid); |
| 170 | 172 | if( zUuid ){ |
| 171 | 173 | if( pOut ){ |
| @@ -177,10 +179,17 @@ | ||
| 177 | 179 | } |
| 178 | 180 | } |
| 179 | 181 | } |
| 180 | 182 | db_finalize(&q); |
| 181 | 183 | |
| 184 | + /* Delete the 'pending' records for all files just sent. Otherwise, | |
| 185 | + ** we can wind up sending some files more than once. | |
| 186 | + */ | |
| 187 | + if( nSent>0 ){ | |
| 188 | + db_multi_exec("DELETE FROM pending WHERE rid <= %d", iRidSent); | |
| 189 | + } | |
| 190 | + | |
| 182 | 191 | #if 0 |
| 183 | 192 | db_multi_exec("DROP TABLE priority"); |
| 184 | 193 | #endif |
| 185 | 194 | return nSent; |
| 186 | 195 | } |
| 187 | 196 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -129,10 +129,11 @@ | |
| 129 | |
| 130 | /* |
| 131 | ** Send all pending files. |
| 132 | */ |
| 133 | static int send_all_pending(Blob *pOut){ |
| 134 | int sent = 0; |
| 135 | int nSent = 0; |
| 136 | int maxSize = db_get_int("http-msg-size", 1000000); |
| 137 | Stmt q; |
| 138 | #if 0 |
| @@ -156,16 +157,17 @@ | |
| 156 | " SELECT rid FROM delta WHERE srcid=%d", |
| 157 | rid, rid |
| 158 | ); |
| 159 | } |
| 160 | #endif |
| 161 | db_prepare(&q, "SELECT rid FROM pending"); |
| 162 | while( db_step(&q)==SQLITE_ROW ){ |
| 163 | int rid = db_column_int(&q, 0); |
| 164 | if( sent<maxSize ){ |
| 165 | sent += send_file(rid, pOut); |
| 166 | nSent++; |
| 167 | }else{ |
| 168 | char *zUuid = db_text(0, |
| 169 | "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid); |
| 170 | if( zUuid ){ |
| 171 | if( pOut ){ |
| @@ -177,10 +179,17 @@ | |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | db_finalize(&q); |
| 181 | |
| 182 | #if 0 |
| 183 | db_multi_exec("DROP TABLE priority"); |
| 184 | #endif |
| 185 | return nSent; |
| 186 | } |
| 187 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -129,10 +129,11 @@ | |
| 129 | |
| 130 | /* |
| 131 | ** Send all pending files. |
| 132 | */ |
| 133 | static int send_all_pending(Blob *pOut){ |
| 134 | int iRidSent = 0; |
| 135 | int sent = 0; |
| 136 | int nSent = 0; |
| 137 | int maxSize = db_get_int("http-msg-size", 1000000); |
| 138 | Stmt q; |
| 139 | #if 0 |
| @@ -156,16 +157,17 @@ | |
| 157 | " SELECT rid FROM delta WHERE srcid=%d", |
| 158 | rid, rid |
| 159 | ); |
| 160 | } |
| 161 | #endif |
| 162 | db_prepare(&q, "SELECT rid FROM pending ORDER BY rid"); |
| 163 | while( db_step(&q)==SQLITE_ROW ){ |
| 164 | int rid = db_column_int(&q, 0); |
| 165 | if( sent<maxSize ){ |
| 166 | sent += send_file(rid, pOut); |
| 167 | nSent++; |
| 168 | iRidSent = rid; |
| 169 | }else{ |
| 170 | char *zUuid = db_text(0, |
| 171 | "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid); |
| 172 | if( zUuid ){ |
| 173 | if( pOut ){ |
| @@ -177,10 +179,17 @@ | |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | db_finalize(&q); |
| 183 | |
| 184 | /* Delete the 'pending' records for all files just sent. Otherwise, |
| 185 | ** we can wind up sending some files more than once. |
| 186 | */ |
| 187 | if( nSent>0 ){ |
| 188 | db_multi_exec("DELETE FROM pending WHERE rid <= %d", iRidSent); |
| 189 | } |
| 190 | |
| 191 | #if 0 |
| 192 | db_multi_exec("DROP TABLE priority"); |
| 193 | #endif |
| 194 | return nSent; |
| 195 | } |
| 196 |
+10
-1
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -129,10 +129,11 @@ | ||
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | ** Send all pending files. |
| 132 | 132 | */ |
| 133 | 133 | static int send_all_pending(Blob *pOut){ |
| 134 | + int iRidSent = 0; | |
| 134 | 135 | int sent = 0; |
| 135 | 136 | int nSent = 0; |
| 136 | 137 | int maxSize = db_get_int("http-msg-size", 1000000); |
| 137 | 138 | Stmt q; |
| 138 | 139 | #if 0 |
| @@ -156,16 +157,17 @@ | ||
| 156 | 157 | " SELECT rid FROM delta WHERE srcid=%d", |
| 157 | 158 | rid, rid |
| 158 | 159 | ); |
| 159 | 160 | } |
| 160 | 161 | #endif |
| 161 | - db_prepare(&q, "SELECT rid FROM pending"); | |
| 162 | + db_prepare(&q, "SELECT rid FROM pending ORDER BY rid"); | |
| 162 | 163 | while( db_step(&q)==SQLITE_ROW ){ |
| 163 | 164 | int rid = db_column_int(&q, 0); |
| 164 | 165 | if( sent<maxSize ){ |
| 165 | 166 | sent += send_file(rid, pOut); |
| 166 | 167 | nSent++; |
| 168 | + iRidSent = rid; | |
| 167 | 169 | }else{ |
| 168 | 170 | char *zUuid = db_text(0, |
| 169 | 171 | "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid); |
| 170 | 172 | if( zUuid ){ |
| 171 | 173 | if( pOut ){ |
| @@ -177,10 +179,17 @@ | ||
| 177 | 179 | } |
| 178 | 180 | } |
| 179 | 181 | } |
| 180 | 182 | db_finalize(&q); |
| 181 | 183 | |
| 184 | + /* Delete the 'pending' records for all files just sent. Otherwise, | |
| 185 | + ** we can wind up sending some files more than once. | |
| 186 | + */ | |
| 187 | + if( nSent>0 ){ | |
| 188 | + db_multi_exec("DELETE FROM pending WHERE rid <= %d", iRidSent); | |
| 189 | + } | |
| 190 | + | |
| 182 | 191 | #if 0 |
| 183 | 192 | db_multi_exec("DROP TABLE priority"); |
| 184 | 193 | #endif |
| 185 | 194 | return nSent; |
| 186 | 195 | } |
| 187 | 196 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -129,10 +129,11 @@ | |
| 129 | |
| 130 | /* |
| 131 | ** Send all pending files. |
| 132 | */ |
| 133 | static int send_all_pending(Blob *pOut){ |
| 134 | int sent = 0; |
| 135 | int nSent = 0; |
| 136 | int maxSize = db_get_int("http-msg-size", 1000000); |
| 137 | Stmt q; |
| 138 | #if 0 |
| @@ -156,16 +157,17 @@ | |
| 156 | " SELECT rid FROM delta WHERE srcid=%d", |
| 157 | rid, rid |
| 158 | ); |
| 159 | } |
| 160 | #endif |
| 161 | db_prepare(&q, "SELECT rid FROM pending"); |
| 162 | while( db_step(&q)==SQLITE_ROW ){ |
| 163 | int rid = db_column_int(&q, 0); |
| 164 | if( sent<maxSize ){ |
| 165 | sent += send_file(rid, pOut); |
| 166 | nSent++; |
| 167 | }else{ |
| 168 | char *zUuid = db_text(0, |
| 169 | "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid); |
| 170 | if( zUuid ){ |
| 171 | if( pOut ){ |
| @@ -177,10 +179,17 @@ | |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | db_finalize(&q); |
| 181 | |
| 182 | #if 0 |
| 183 | db_multi_exec("DROP TABLE priority"); |
| 184 | #endif |
| 185 | return nSent; |
| 186 | } |
| 187 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -129,10 +129,11 @@ | |
| 129 | |
| 130 | /* |
| 131 | ** Send all pending files. |
| 132 | */ |
| 133 | static int send_all_pending(Blob *pOut){ |
| 134 | int iRidSent = 0; |
| 135 | int sent = 0; |
| 136 | int nSent = 0; |
| 137 | int maxSize = db_get_int("http-msg-size", 1000000); |
| 138 | Stmt q; |
| 139 | #if 0 |
| @@ -156,16 +157,17 @@ | |
| 157 | " SELECT rid FROM delta WHERE srcid=%d", |
| 158 | rid, rid |
| 159 | ); |
| 160 | } |
| 161 | #endif |
| 162 | db_prepare(&q, "SELECT rid FROM pending ORDER BY rid"); |
| 163 | while( db_step(&q)==SQLITE_ROW ){ |
| 164 | int rid = db_column_int(&q, 0); |
| 165 | if( sent<maxSize ){ |
| 166 | sent += send_file(rid, pOut); |
| 167 | nSent++; |
| 168 | iRidSent = rid; |
| 169 | }else{ |
| 170 | char *zUuid = db_text(0, |
| 171 | "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid); |
| 172 | if( zUuid ){ |
| 173 | if( pOut ){ |
| @@ -177,10 +179,17 @@ | |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | db_finalize(&q); |
| 183 | |
| 184 | /* Delete the 'pending' records for all files just sent. Otherwise, |
| 185 | ** we can wind up sending some files more than once. |
| 186 | */ |
| 187 | if( nSent>0 ){ |
| 188 | db_multi_exec("DELETE FROM pending WHERE rid <= %d", iRidSent); |
| 189 | } |
| 190 | |
| 191 | #if 0 |
| 192 | db_multi_exec("DROP TABLE priority"); |
| 193 | #endif |
| 194 | return nSent; |
| 195 | } |
| 196 |