Fossil SCM

Fix an inefficiency in uv-sync in which the uv-catalog is always sent even if the uv-hash matches. Also add preliminary change to support uv-push.

drh 2021-07-06 13:15 trunk
Commit d015a269e63fe4c34bc16e41cd26695850e8a196381351d8494298d9f3f36d66
2 files changed +1 -1 +44 -40
+1 -1
--- src/blob.c
+++ src/blob.c
@@ -460,11 +460,11 @@
460460
** Compare a blob to a string. Return TRUE if they are equal.
461461
*/
462462
int blob_eq_str(Blob *pBlob, const char *z, int n){
463463
Blob t;
464464
blob_is_init(pBlob);
465
- if( n<=0 ) n = strlen(z);
465
+ if( n<=0 ) n = (int)strlen(z);
466466
t.aData = (char*)z;
467467
t.nUsed = n;
468468
t.xRealloc = blobReallocStatic;
469469
return blob_compare(pBlob, &t)==0;
470470
}
471471
--- src/blob.c
+++ src/blob.c
@@ -460,11 +460,11 @@
460 ** Compare a blob to a string. Return TRUE if they are equal.
461 */
462 int blob_eq_str(Blob *pBlob, const char *z, int n){
463 Blob t;
464 blob_is_init(pBlob);
465 if( n<=0 ) n = strlen(z);
466 t.aData = (char*)z;
467 t.nUsed = n;
468 t.xRealloc = blobReallocStatic;
469 return blob_compare(pBlob, &t)==0;
470 }
471
--- src/blob.c
+++ src/blob.c
@@ -460,11 +460,11 @@
460 ** Compare a blob to a string. Return TRUE if they are equal.
461 */
462 int blob_eq_str(Blob *pBlob, const char *z, int n){
463 Blob t;
464 blob_is_init(pBlob);
465 if( n<=0 ) n = (int)strlen(z);
466 t.aData = (char*)z;
467 t.nUsed = n;
468 t.xRealloc = blobReallocStatic;
469 return blob_compare(pBlob, &t)==0;
470 }
471
+44 -40
--- src/xfer.c
+++ src/xfer.c
@@ -1061,29 +1061,27 @@
10611061
** If HASH is different from the unversioned content hash on this server,
10621062
** then send a bunch of uvigot cards, one for each entry unversioned file
10631063
** on this server.
10641064
*/
10651065
static void send_unversioned_catalog(Xfer *pXfer){
1066
+ int nUvIgot = 0;
1067
+ Stmt uvq;
10661068
unversioned_schema();
1067
- if( !blob_eq(&pXfer->aToken[2], unversioned_content_hash(0)) ){
1068
- int nUvIgot = 0;
1069
- Stmt uvq;
1070
- db_prepare(&uvq,
1071
- "SELECT name, mtime, hash, sz FROM unversioned"
1072
- );
1073
- while( db_step(&uvq)==SQLITE_ROW ){
1074
- const char *zName = db_column_text(&uvq,0);
1075
- sqlite3_int64 mtime = db_column_int64(&uvq,1);
1076
- const char *zHash = db_column_text(&uvq,2);
1077
- int sz = db_column_int(&uvq,3);
1078
- nUvIgot++;
1079
- if( zHash==0 ){ sz = 0; zHash = "-"; }
1080
- blob_appendf(pXfer->pOut, "uvigot %s %lld %s %d\n",
1081
- zName, mtime, zHash, sz);
1082
- }
1083
- db_finalize(&uvq);
1084
- }
1069
+ db_prepare(&uvq,
1070
+ "SELECT name, mtime, hash, sz FROM unversioned"
1071
+ );
1072
+ while( db_step(&uvq)==SQLITE_ROW ){
1073
+ const char *zName = db_column_text(&uvq,0);
1074
+ sqlite3_int64 mtime = db_column_int64(&uvq,1);
1075
+ const char *zHash = db_column_text(&uvq,2);
1076
+ int sz = db_column_int(&uvq,3);
1077
+ nUvIgot++;
1078
+ if( zHash==0 ){ sz = 0; zHash = "-"; }
1079
+ blob_appendf(pXfer->pOut, "uvigot %s %lld %s %d\n",
1080
+ zName, mtime, zHash, sz);
1081
+ }
1082
+ db_finalize(&uvq);
10851083
}
10861084
10871085
/*
10881086
** Called when there is an attempt to transfer private content to and
10891087
** from a server without authorization.
@@ -1616,18 +1614,20 @@
16161614
** "uvigot" cards.
16171615
*/
16181616
if( blob_eq(&xfer.aToken[1], "uv-hash")
16191617
&& blob_is_hname(&xfer.aToken[2])
16201618
){
1621
- if( !uvCatalogSent ){
1622
- if( g.perm.Read && g.perm.WrUnver ){
1619
+ if( !uvCatalogSent
1620
+ && g.perm.Read
1621
+ && !blob_eq_str(&xfer.aToken[2], unversioned_content_hash(0),-1)
1622
+ ){
1623
+ if( g.perm.WrUnver ){
16231624
@ pragma uv-push-ok
1624
- send_unversioned_catalog(&xfer);
16251625
}else if( g.perm.Read ){
16261626
@ pragma uv-pull-only
1627
- send_unversioned_catalog(&xfer);
16281627
}
1628
+ send_unversioned_catalog(&xfer);
16291629
}
16301630
uvCatalogSent = 1;
16311631
}
16321632
16331633
/* pragma ci-lock CHECKIN-HASH CLIENT-ID
@@ -1813,17 +1813,18 @@
18131813
#define SYNC_PULL 0x0002 /* pull content server to client */
18141814
#define SYNC_CLONE 0x0004 /* clone the repository */
18151815
#define SYNC_PRIVATE 0x0008 /* Also transfer private content */
18161816
#define SYNC_VERBOSE 0x0010 /* Extra diagnostics */
18171817
#define SYNC_RESYNC 0x0020 /* --verily */
1818
-#define SYNC_UNVERSIONED 0x0040 /* Sync unversioned content */
1819
-#define SYNC_UV_REVERT 0x0080 /* Copy server unversioned to client */
1820
-#define SYNC_FROMPARENT 0x0100 /* Pull from the parent project */
1821
-#define SYNC_UV_TRACE 0x0200 /* Describe UV activities */
1822
-#define SYNC_UV_DRYRUN 0x0400 /* Do not actually exchange files */
1823
-#define SYNC_IFABLE 0x0800 /* Inability to sync is not fatal */
1824
-#define SYNC_CKIN_LOCK 0x1000 /* Lock the current check-in */
1818
+#define SYNC_UVPULL 0x0040 /* Unversioned pull */
1819
+#define SYNC_FROMPARENT 0x0080 /* Pull from the parent project */
1820
+#define SYNC_UNVERSIONED 0x0100 /* Sync unversioned content */
1821
+#define SYNC_UV_REVERT 0x0200 /* Copy server unversioned to client */
1822
+#define SYNC_UV_TRACE 0x0400 /* Describe UV activities */
1823
+#define SYNC_UV_DRYRUN 0x0800 /* Do not actually exchange files */
1824
+#define SYNC_IFABLE 0x1000 /* Inability to sync is not fatal */
1825
+#define SYNC_CKIN_LOCK 0x2000 /* Lock the current check-in */
18251826
#endif
18261827
18271828
/*
18281829
** Floating-point absolute value
18291830
*/
@@ -1879,11 +1880,12 @@
18791880
const char *zCkinLock; /* Name of check-in to lock. NULL for none */
18801881
const char *zClientId; /* A unique identifier for this check-out */
18811882
unsigned int mHttpFlags;/* Flags for the http_exchange() subsystem */
18821883
18831884
if( db_get_boolean("dont-push", 0) ) syncFlags &= ~SYNC_PUSH;
1884
- if( (syncFlags & (SYNC_PUSH|SYNC_PULL|SYNC_CLONE|SYNC_UNVERSIONED))==0
1885
+ if( (syncFlags & (SYNC_PUSH|SYNC_PULL|SYNC_CLONE|
1886
+ SYNC_UNVERSIONED|SYNC_UVPULL))==0
18851887
&& configRcvMask==0 && configSendMask==0 ) return 0;
18861888
if( syncFlags & SYNC_FROMPARENT ){
18871889
configRcvMask = 0;
18881890
configSendMask = 0;
18891891
syncFlags &= ~(SYNC_PUSH);
@@ -2036,11 +2038,11 @@
20362038
20372039
/* Client sends a request to sync unversioned files.
20382040
** On a clone, delay sending this until the second cycle since
20392041
** the login card might fail on the first cycle.
20402042
*/
2041
- if( (syncFlags & SYNC_UNVERSIONED)!=0
2043
+ if( (syncFlags & (SYNC_UNVERSIONED|SYNC_UVPULL))!=0
20422044
&& ((syncFlags & SYNC_CLONE)==0 || nCycle>0)
20432045
&& !uvHashSent
20442046
){
20452047
blob_appendf(&send, "pragma uv-hash %s\n", unversioned_content_hash(0));
20462048
nCardSent++;
@@ -2492,19 +2494,21 @@
24922494
** this client lacks the necessary permissions) then it sends a
24932495
** "uv-pull-only" pragma so that the client will know not to waste
24942496
** bandwidth trying to upload unversioned content. If the server
24952497
** does accept new unversioned content, it sends "uv-push-ok".
24962498
*/
2497
- if( blob_eq(&xfer.aToken[1], "uv-pull-only") ){
2498
- fossil_print(
2499
- "Warning: uv-pull-only \n"
2500
- " Unable to push unversioned content because you lack\n"
2501
- " sufficient permission on the server\n"
2502
- );
2503
- if( syncFlags & SYNC_UV_REVERT ) uvDoPush = 1;
2504
- }else if( blob_eq(&xfer.aToken[1], "uv-push-ok") ){
2505
- uvDoPush = 1;
2499
+ if( syncFlags & SYNC_UNVERSIONED ){
2500
+ if( blob_eq(&xfer.aToken[1], "uv-pull-only") ){
2501
+ fossil_print(
2502
+ "Warning: uv-pull-only \n"
2503
+ " Unable to push unversioned content because you lack\n"
2504
+ " sufficient permission on the server\n"
2505
+ );
2506
+ if( syncFlags & SYNC_UV_REVERT ) uvDoPush = 1;
2507
+ }else if( blob_eq(&xfer.aToken[1], "uv-push-ok") ){
2508
+ uvDoPush = 1;
2509
+ }
25062510
}
25072511
25082512
/* pragma ci-lock-fail USER-HOLDING-LOCK LOCK-TIME
25092513
**
25102514
** The server generates this message when a "pragma ci-lock"
25112515
--- src/xfer.c
+++ src/xfer.c
@@ -1061,29 +1061,27 @@
1061 ** If HASH is different from the unversioned content hash on this server,
1062 ** then send a bunch of uvigot cards, one for each entry unversioned file
1063 ** on this server.
1064 */
1065 static void send_unversioned_catalog(Xfer *pXfer){
 
 
1066 unversioned_schema();
1067 if( !blob_eq(&pXfer->aToken[2], unversioned_content_hash(0)) ){
1068 int nUvIgot = 0;
1069 Stmt uvq;
1070 db_prepare(&uvq,
1071 "SELECT name, mtime, hash, sz FROM unversioned"
1072 );
1073 while( db_step(&uvq)==SQLITE_ROW ){
1074 const char *zName = db_column_text(&uvq,0);
1075 sqlite3_int64 mtime = db_column_int64(&uvq,1);
1076 const char *zHash = db_column_text(&uvq,2);
1077 int sz = db_column_int(&uvq,3);
1078 nUvIgot++;
1079 if( zHash==0 ){ sz = 0; zHash = "-"; }
1080 blob_appendf(pXfer->pOut, "uvigot %s %lld %s %d\n",
1081 zName, mtime, zHash, sz);
1082 }
1083 db_finalize(&uvq);
1084 }
1085 }
1086
1087 /*
1088 ** Called when there is an attempt to transfer private content to and
1089 ** from a server without authorization.
@@ -1616,18 +1614,20 @@
1616 ** "uvigot" cards.
1617 */
1618 if( blob_eq(&xfer.aToken[1], "uv-hash")
1619 && blob_is_hname(&xfer.aToken[2])
1620 ){
1621 if( !uvCatalogSent ){
1622 if( g.perm.Read && g.perm.WrUnver ){
 
 
 
1623 @ pragma uv-push-ok
1624 send_unversioned_catalog(&xfer);
1625 }else if( g.perm.Read ){
1626 @ pragma uv-pull-only
1627 send_unversioned_catalog(&xfer);
1628 }
 
1629 }
1630 uvCatalogSent = 1;
1631 }
1632
1633 /* pragma ci-lock CHECKIN-HASH CLIENT-ID
@@ -1813,17 +1813,18 @@
1813 #define SYNC_PULL 0x0002 /* pull content server to client */
1814 #define SYNC_CLONE 0x0004 /* clone the repository */
1815 #define SYNC_PRIVATE 0x0008 /* Also transfer private content */
1816 #define SYNC_VERBOSE 0x0010 /* Extra diagnostics */
1817 #define SYNC_RESYNC 0x0020 /* --verily */
1818 #define SYNC_UNVERSIONED 0x0040 /* Sync unversioned content */
1819 #define SYNC_UV_REVERT 0x0080 /* Copy server unversioned to client */
1820 #define SYNC_FROMPARENT 0x0100 /* Pull from the parent project */
1821 #define SYNC_UV_TRACE 0x0200 /* Describe UV activities */
1822 #define SYNC_UV_DRYRUN 0x0400 /* Do not actually exchange files */
1823 #define SYNC_IFABLE 0x0800 /* Inability to sync is not fatal */
1824 #define SYNC_CKIN_LOCK 0x1000 /* Lock the current check-in */
 
1825 #endif
1826
1827 /*
1828 ** Floating-point absolute value
1829 */
@@ -1879,11 +1880,12 @@
1879 const char *zCkinLock; /* Name of check-in to lock. NULL for none */
1880 const char *zClientId; /* A unique identifier for this check-out */
1881 unsigned int mHttpFlags;/* Flags for the http_exchange() subsystem */
1882
1883 if( db_get_boolean("dont-push", 0) ) syncFlags &= ~SYNC_PUSH;
1884 if( (syncFlags & (SYNC_PUSH|SYNC_PULL|SYNC_CLONE|SYNC_UNVERSIONED))==0
 
1885 && configRcvMask==0 && configSendMask==0 ) return 0;
1886 if( syncFlags & SYNC_FROMPARENT ){
1887 configRcvMask = 0;
1888 configSendMask = 0;
1889 syncFlags &= ~(SYNC_PUSH);
@@ -2036,11 +2038,11 @@
2036
2037 /* Client sends a request to sync unversioned files.
2038 ** On a clone, delay sending this until the second cycle since
2039 ** the login card might fail on the first cycle.
2040 */
2041 if( (syncFlags & SYNC_UNVERSIONED)!=0
2042 && ((syncFlags & SYNC_CLONE)==0 || nCycle>0)
2043 && !uvHashSent
2044 ){
2045 blob_appendf(&send, "pragma uv-hash %s\n", unversioned_content_hash(0));
2046 nCardSent++;
@@ -2492,19 +2494,21 @@
2492 ** this client lacks the necessary permissions) then it sends a
2493 ** "uv-pull-only" pragma so that the client will know not to waste
2494 ** bandwidth trying to upload unversioned content. If the server
2495 ** does accept new unversioned content, it sends "uv-push-ok".
2496 */
2497 if( blob_eq(&xfer.aToken[1], "uv-pull-only") ){
2498 fossil_print(
2499 "Warning: uv-pull-only \n"
2500 " Unable to push unversioned content because you lack\n"
2501 " sufficient permission on the server\n"
2502 );
2503 if( syncFlags & SYNC_UV_REVERT ) uvDoPush = 1;
2504 }else if( blob_eq(&xfer.aToken[1], "uv-push-ok") ){
2505 uvDoPush = 1;
 
 
2506 }
2507
2508 /* pragma ci-lock-fail USER-HOLDING-LOCK LOCK-TIME
2509 **
2510 ** The server generates this message when a "pragma ci-lock"
2511
--- src/xfer.c
+++ src/xfer.c
@@ -1061,29 +1061,27 @@
1061 ** If HASH is different from the unversioned content hash on this server,
1062 ** then send a bunch of uvigot cards, one for each entry unversioned file
1063 ** on this server.
1064 */
1065 static void send_unversioned_catalog(Xfer *pXfer){
1066 int nUvIgot = 0;
1067 Stmt uvq;
1068 unversioned_schema();
1069 db_prepare(&uvq,
1070 "SELECT name, mtime, hash, sz FROM unversioned"
1071 );
1072 while( db_step(&uvq)==SQLITE_ROW ){
1073 const char *zName = db_column_text(&uvq,0);
1074 sqlite3_int64 mtime = db_column_int64(&uvq,1);
1075 const char *zHash = db_column_text(&uvq,2);
1076 int sz = db_column_int(&uvq,3);
1077 nUvIgot++;
1078 if( zHash==0 ){ sz = 0; zHash = "-"; }
1079 blob_appendf(pXfer->pOut, "uvigot %s %lld %s %d\n",
1080 zName, mtime, zHash, sz);
1081 }
1082 db_finalize(&uvq);
 
 
 
 
1083 }
1084
1085 /*
1086 ** Called when there is an attempt to transfer private content to and
1087 ** from a server without authorization.
@@ -1616,18 +1614,20 @@
1614 ** "uvigot" cards.
1615 */
1616 if( blob_eq(&xfer.aToken[1], "uv-hash")
1617 && blob_is_hname(&xfer.aToken[2])
1618 ){
1619 if( !uvCatalogSent
1620 && g.perm.Read
1621 && !blob_eq_str(&xfer.aToken[2], unversioned_content_hash(0),-1)
1622 ){
1623 if( g.perm.WrUnver ){
1624 @ pragma uv-push-ok
 
1625 }else if( g.perm.Read ){
1626 @ pragma uv-pull-only
 
1627 }
1628 send_unversioned_catalog(&xfer);
1629 }
1630 uvCatalogSent = 1;
1631 }
1632
1633 /* pragma ci-lock CHECKIN-HASH CLIENT-ID
@@ -1813,17 +1813,18 @@
1813 #define SYNC_PULL 0x0002 /* pull content server to client */
1814 #define SYNC_CLONE 0x0004 /* clone the repository */
1815 #define SYNC_PRIVATE 0x0008 /* Also transfer private content */
1816 #define SYNC_VERBOSE 0x0010 /* Extra diagnostics */
1817 #define SYNC_RESYNC 0x0020 /* --verily */
1818 #define SYNC_UVPULL 0x0040 /* Unversioned pull */
1819 #define SYNC_FROMPARENT 0x0080 /* Pull from the parent project */
1820 #define SYNC_UNVERSIONED 0x0100 /* Sync unversioned content */
1821 #define SYNC_UV_REVERT 0x0200 /* Copy server unversioned to client */
1822 #define SYNC_UV_TRACE 0x0400 /* Describe UV activities */
1823 #define SYNC_UV_DRYRUN 0x0800 /* Do not actually exchange files */
1824 #define SYNC_IFABLE 0x1000 /* Inability to sync is not fatal */
1825 #define SYNC_CKIN_LOCK 0x2000 /* Lock the current check-in */
1826 #endif
1827
1828 /*
1829 ** Floating-point absolute value
1830 */
@@ -1879,11 +1880,12 @@
1880 const char *zCkinLock; /* Name of check-in to lock. NULL for none */
1881 const char *zClientId; /* A unique identifier for this check-out */
1882 unsigned int mHttpFlags;/* Flags for the http_exchange() subsystem */
1883
1884 if( db_get_boolean("dont-push", 0) ) syncFlags &= ~SYNC_PUSH;
1885 if( (syncFlags & (SYNC_PUSH|SYNC_PULL|SYNC_CLONE|
1886 SYNC_UNVERSIONED|SYNC_UVPULL))==0
1887 && configRcvMask==0 && configSendMask==0 ) return 0;
1888 if( syncFlags & SYNC_FROMPARENT ){
1889 configRcvMask = 0;
1890 configSendMask = 0;
1891 syncFlags &= ~(SYNC_PUSH);
@@ -2036,11 +2038,11 @@
2038
2039 /* Client sends a request to sync unversioned files.
2040 ** On a clone, delay sending this until the second cycle since
2041 ** the login card might fail on the first cycle.
2042 */
2043 if( (syncFlags & (SYNC_UNVERSIONED|SYNC_UVPULL))!=0
2044 && ((syncFlags & SYNC_CLONE)==0 || nCycle>0)
2045 && !uvHashSent
2046 ){
2047 blob_appendf(&send, "pragma uv-hash %s\n", unversioned_content_hash(0));
2048 nCardSent++;
@@ -2492,19 +2494,21 @@
2494 ** this client lacks the necessary permissions) then it sends a
2495 ** "uv-pull-only" pragma so that the client will know not to waste
2496 ** bandwidth trying to upload unversioned content. If the server
2497 ** does accept new unversioned content, it sends "uv-push-ok".
2498 */
2499 if( syncFlags & SYNC_UNVERSIONED ){
2500 if( blob_eq(&xfer.aToken[1], "uv-pull-only") ){
2501 fossil_print(
2502 "Warning: uv-pull-only \n"
2503 " Unable to push unversioned content because you lack\n"
2504 " sufficient permission on the server\n"
2505 );
2506 if( syncFlags & SYNC_UV_REVERT ) uvDoPush = 1;
2507 }else if( blob_eq(&xfer.aToken[1], "uv-push-ok") ){
2508 uvDoPush = 1;
2509 }
2510 }
2511
2512 /* pragma ci-lock-fail USER-HOLDING-LOCK LOCK-TIME
2513 **
2514 ** The server generates this message when a "pragma ci-lock"
2515

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button