Fossil SCM

More fixes to the unversioned file sync protocol.

drh 2016-08-09 18:59 unversioned-files
Commit 48b9bf351f4a9eaf53cdf175838612f80912ccdd
2 files changed +5 -4 +27 -12
--- src/unversioned.c
+++ src/unversioned.c
@@ -284,28 +284,29 @@
284284
while( db_step(&q)==SQLITE_ROW ){
285285
fossil_print("%s\n", db_column_text(&q,0));
286286
}
287287
}else{
288288
db_prepare(&q,
289
- "SELECT hash, datetime(mtime,'unixepoch'), sz, name, content IS NULL"
289
+ "SELECT hash, datetime(mtime,'unixepoch'), sz, length(content), name"
290290
" FROM unversioned"
291291
" ORDER BY name;"
292292
);
293293
while( db_step(&q)==SQLITE_ROW ){
294294
const char *zHash = db_column_text(&q, 0);
295295
const char *zNoContent = "";
296296
if( zHash==0 ){
297297
if( !allFlag ) continue;
298298
zHash = "(deleted)";
299
- }else if( db_column_int(&q,4) ){
299
+ }else if( db_column_type(&q,3)==SQLITE_NULL ){
300300
zNoContent = " (no content)";
301301
}
302
- fossil_print("%12.12s %s %8d %s%s\n",
302
+ fossil_print("%12.12s %s %8d %8d %s%s\n",
303303
zHash,
304304
db_column_text(&q,1),
305305
db_column_int(&q,2),
306
- db_column_text(&q,3),
306
+ db_column_int(&q,3),
307
+ db_column_text(&q,4),
307308
zNoContent
308309
);
309310
}
310311
}
311312
db_finalize(&q);
312313
--- src/unversioned.c
+++ src/unversioned.c
@@ -284,28 +284,29 @@
284 while( db_step(&q)==SQLITE_ROW ){
285 fossil_print("%s\n", db_column_text(&q,0));
286 }
287 }else{
288 db_prepare(&q,
289 "SELECT hash, datetime(mtime,'unixepoch'), sz, name, content IS NULL"
290 " FROM unversioned"
291 " ORDER BY name;"
292 );
293 while( db_step(&q)==SQLITE_ROW ){
294 const char *zHash = db_column_text(&q, 0);
295 const char *zNoContent = "";
296 if( zHash==0 ){
297 if( !allFlag ) continue;
298 zHash = "(deleted)";
299 }else if( db_column_int(&q,4) ){
300 zNoContent = " (no content)";
301 }
302 fossil_print("%12.12s %s %8d %s%s\n",
303 zHash,
304 db_column_text(&q,1),
305 db_column_int(&q,2),
306 db_column_text(&q,3),
 
307 zNoContent
308 );
309 }
310 }
311 db_finalize(&q);
312
--- src/unversioned.c
+++ src/unversioned.c
@@ -284,28 +284,29 @@
284 while( db_step(&q)==SQLITE_ROW ){
285 fossil_print("%s\n", db_column_text(&q,0));
286 }
287 }else{
288 db_prepare(&q,
289 "SELECT hash, datetime(mtime,'unixepoch'), sz, length(content), name"
290 " FROM unversioned"
291 " ORDER BY name;"
292 );
293 while( db_step(&q)==SQLITE_ROW ){
294 const char *zHash = db_column_text(&q, 0);
295 const char *zNoContent = "";
296 if( zHash==0 ){
297 if( !allFlag ) continue;
298 zHash = "(deleted)";
299 }else if( db_column_type(&q,3)==SQLITE_NULL ){
300 zNoContent = " (no content)";
301 }
302 fossil_print("%12.12s %s %8d %8d %s%s\n",
303 zHash,
304 db_column_text(&q,1),
305 db_column_int(&q,2),
306 db_column_int(&q,3),
307 db_column_text(&q,4),
308 zNoContent
309 );
310 }
311 }
312 db_finalize(&q);
313
+27 -12
--- src/xfer.c
+++ src/xfer.c
@@ -311,10 +311,11 @@
311311
Blob *pHash; /* The HASH value */
312312
int sz; /* The SIZE */
313313
int flags; /* The FLAGS */
314314
Blob content; /* The CONTENT */
315315
Blob hash; /* Hash computed from CONTENT to compare with HASH */
316
+ Blob x; /* Compressed content */
316317
Stmt q; /* SQL statements for comparison and insert */
317318
int isDelete; /* HASH is "-" indicating this is a delete operation */
318319
int nullContent; /* True of CONTENT is NULL */
319320
int iStatus; /* Result from unversioned_status() */
320321
@@ -329,10 +330,11 @@
329330
blob_appendf(&pXfer->err, "malformed uvfile line");
330331
return;
331332
}
332333
blob_init(&content, 0, 0);
333334
blob_init(&hash, 0, 0);
335
+ blob_init(&x, 0, 0);
334336
if( sz>0 && (flags & 0x0005)==0 ){
335337
blob_extract(pXfer->pIn, sz, &content);
336338
nullContent = 0;
337339
sha1sum_blob(&content, &hash);
338340
if( blob_compare(&hash, pHash)!=0 ){
@@ -356,35 +358,45 @@
356358
/* Store the content */
357359
isDelete = blob_eq(pHash, "-");
358360
if( isDelete ){
359361
db_prepare(&q,
360362
"UPDATE unversioned"
361
- " SET rcvid=:rcvid, mtime=:mtime, hash=NULL, sz=0, content=NULL"
363
+ " SET rcvid=:rcvid, mtime=:mtime, hash=NULL, sz=0, encoding=0, content=NULL"
362364
" WHERE name=:name"
363365
);
366
+ db_bind_int(&q, ":rcvid", g.rcvid);
364367
}else if( iStatus==4 ){
365368
db_prepare(&q, "UPDATE unversioned SET mtime=:mtime WHERE name=:name");
366369
}else{
367370
db_prepare(&q,
368
- "REPLACE INTO unversioned(name, rcvid, mtime, hash, sz, content)"
369
- " VALUES(:name,:rcvid,:mtime,:hash,:sz,:content)"
371
+ "REPLACE INTO unversioned(name, rcvid, mtime, hash, sz, encoding, content)"
372
+ " VALUES(:name,:rcvid,:mtime,:hash,:sz,:encoding,:content)"
370373
);
374
+ db_bind_int(&q, ":rcvid", g.rcvid);
375
+ db_bind_text(&q, ":hash", blob_str(pHash));
376
+ db_bind_int(&q, ":sz", blob_size(&content));
377
+ if( !nullContent ){
378
+ blob_compress(&content, &x);
379
+ if( blob_size(&x) < 0.8*blob_size(&content) ){
380
+ db_bind_blob(&q, ":content", &x);
381
+ db_bind_int(&q, ":encoding", 1);
382
+ }else{
383
+ db_bind_blob(&q, ":content", &content);
384
+ db_bind_int(&q, ":encoding", 0);
385
+ }
386
+ }else{
387
+ db_bind_int(&q, ":encoding", 0);
388
+ }
371389
}
372390
db_bind_text(&q, ":name", blob_str(&pXfer->aToken[1]));
373
- db_bind_int(&q, ":rcvid", g.rcvid);
374391
db_bind_int64(&q, ":mtime", mtime);
375
- db_bind_text(&q, ":hash", blob_str(pHash));
376
- db_bind_int(&q, ":sz", blob_size(&content));
377
- if( !nullContent ){
378
- blob_compress(&content, &content);
379
- db_bind_blob(&q, ":content", &content);
380
- }
381392
db_step(&q);
382393
db_finalize(&q);
383394
db_unset("uv-hash", 0);
384395
385396
end_accept_unversioned_file:
397
+ blob_reset(&x);
386398
blob_reset(&content);
387399
blob_reset(&hash);
388400
}
389401
390402
/*
@@ -654,11 +666,11 @@
654666
if( db_step(&q1)==SQLITE_ROW ){
655667
sqlite3_int64 mtime = db_column_int64(&q1, 0);
656668
const char *zHash = db_column_text(&q1, 1);
657669
blob_appendf(pXfer->pOut, "uvfile %s %lld", zName, mtime);
658670
if( zHash==0 ){
659
- blob_append(pXfer->pOut, " 0 0 1\n", -1);
671
+ blob_append(pXfer->pOut, " - 0 1\n", -1);
660672
}else if( noContent ){
661673
blob_appendf(pXfer->pOut, " %s %d 4\n", zHash, db_column_int(&q1,3));
662674
}else{
663675
Blob content;
664676
blob_init(&content, 0, 0);
@@ -1706,11 +1718,11 @@
17061718
/* When syncing unversioned files, create a TEMP table in which to store
17071719
** the names of files that do not need to be sent from client to server.
17081720
*/
17091721
if( syncFlags & SYNC_UNVERSIONED ){
17101722
db_multi_exec(
1711
- "CREATE TEMP TABLE uv_toSend("
1723
+ "CREATE TEMP TABLE uv_tosend("
17121724
" name TEXT PRIMARY KEY,"
17131725
" mtimeOnly BOOLEAN"
17141726
") WITHOUT ROWID;"
17151727
"INSERT INTO uv_toSend(name,mtimeOnly)"
17161728
" SELECT name, 0 FROM unversioned WHERE hash IS NOT NULL;"
@@ -1841,10 +1853,11 @@
18411853
assert( uvStatus==2 );
18421854
db_prepare(&uvq, "SELECT name, mtimeOnly FROM uv_tosend");
18431855
while( db_step(&uvq)==SQLITE_ROW ){
18441856
send_unversioned_file(&xfer, db_column_text(&uvq,0), db_column_int(&uvq,1));
18451857
nCardSent++;
1858
+ nArtifactSent++;
18461859
}
18471860
db_finalize(&uvq);
18481861
uvDoPush = 0;
18491862
}
18501863
@@ -2055,10 +2068,12 @@
20552068
}
20562069
if( iStatus<=3 ){
20572070
db_multi_exec("DELETE FROM uv_tosend WHERE name=%Q", zName);
20582071
}else if( iStatus==4 ){
20592072
db_multi_exec("UPDATE uv_tosend SET mtimeOnly=1 WHERE name=%Q", zName);
2073
+ }else if( iStatus==5 ){
2074
+ db_multi_exec("REPLACE INTO uv_tosend(name,mtimeOnly) VALUES(%Q,0)", zName);
20602075
}
20612076
}else
20622077
20632078
/* push SERVERCODE PRODUCTCODE
20642079
**
20652080
--- src/xfer.c
+++ src/xfer.c
@@ -311,10 +311,11 @@
311 Blob *pHash; /* The HASH value */
312 int sz; /* The SIZE */
313 int flags; /* The FLAGS */
314 Blob content; /* The CONTENT */
315 Blob hash; /* Hash computed from CONTENT to compare with HASH */
 
316 Stmt q; /* SQL statements for comparison and insert */
317 int isDelete; /* HASH is "-" indicating this is a delete operation */
318 int nullContent; /* True of CONTENT is NULL */
319 int iStatus; /* Result from unversioned_status() */
320
@@ -329,10 +330,11 @@
329 blob_appendf(&pXfer->err, "malformed uvfile line");
330 return;
331 }
332 blob_init(&content, 0, 0);
333 blob_init(&hash, 0, 0);
 
334 if( sz>0 && (flags & 0x0005)==0 ){
335 blob_extract(pXfer->pIn, sz, &content);
336 nullContent = 0;
337 sha1sum_blob(&content, &hash);
338 if( blob_compare(&hash, pHash)!=0 ){
@@ -356,35 +358,45 @@
356 /* Store the content */
357 isDelete = blob_eq(pHash, "-");
358 if( isDelete ){
359 db_prepare(&q,
360 "UPDATE unversioned"
361 " SET rcvid=:rcvid, mtime=:mtime, hash=NULL, sz=0, content=NULL"
362 " WHERE name=:name"
363 );
 
364 }else if( iStatus==4 ){
365 db_prepare(&q, "UPDATE unversioned SET mtime=:mtime WHERE name=:name");
366 }else{
367 db_prepare(&q,
368 "REPLACE INTO unversioned(name, rcvid, mtime, hash, sz, content)"
369 " VALUES(:name,:rcvid,:mtime,:hash,:sz,:content)"
370 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371 }
372 db_bind_text(&q, ":name", blob_str(&pXfer->aToken[1]));
373 db_bind_int(&q, ":rcvid", g.rcvid);
374 db_bind_int64(&q, ":mtime", mtime);
375 db_bind_text(&q, ":hash", blob_str(pHash));
376 db_bind_int(&q, ":sz", blob_size(&content));
377 if( !nullContent ){
378 blob_compress(&content, &content);
379 db_bind_blob(&q, ":content", &content);
380 }
381 db_step(&q);
382 db_finalize(&q);
383 db_unset("uv-hash", 0);
384
385 end_accept_unversioned_file:
 
386 blob_reset(&content);
387 blob_reset(&hash);
388 }
389
390 /*
@@ -654,11 +666,11 @@
654 if( db_step(&q1)==SQLITE_ROW ){
655 sqlite3_int64 mtime = db_column_int64(&q1, 0);
656 const char *zHash = db_column_text(&q1, 1);
657 blob_appendf(pXfer->pOut, "uvfile %s %lld", zName, mtime);
658 if( zHash==0 ){
659 blob_append(pXfer->pOut, " 0 0 1\n", -1);
660 }else if( noContent ){
661 blob_appendf(pXfer->pOut, " %s %d 4\n", zHash, db_column_int(&q1,3));
662 }else{
663 Blob content;
664 blob_init(&content, 0, 0);
@@ -1706,11 +1718,11 @@
1706 /* When syncing unversioned files, create a TEMP table in which to store
1707 ** the names of files that do not need to be sent from client to server.
1708 */
1709 if( syncFlags & SYNC_UNVERSIONED ){
1710 db_multi_exec(
1711 "CREATE TEMP TABLE uv_toSend("
1712 " name TEXT PRIMARY KEY,"
1713 " mtimeOnly BOOLEAN"
1714 ") WITHOUT ROWID;"
1715 "INSERT INTO uv_toSend(name,mtimeOnly)"
1716 " SELECT name, 0 FROM unversioned WHERE hash IS NOT NULL;"
@@ -1841,10 +1853,11 @@
1841 assert( uvStatus==2 );
1842 db_prepare(&uvq, "SELECT name, mtimeOnly FROM uv_tosend");
1843 while( db_step(&uvq)==SQLITE_ROW ){
1844 send_unversioned_file(&xfer, db_column_text(&uvq,0), db_column_int(&uvq,1));
1845 nCardSent++;
 
1846 }
1847 db_finalize(&uvq);
1848 uvDoPush = 0;
1849 }
1850
@@ -2055,10 +2068,12 @@
2055 }
2056 if( iStatus<=3 ){
2057 db_multi_exec("DELETE FROM uv_tosend WHERE name=%Q", zName);
2058 }else if( iStatus==4 ){
2059 db_multi_exec("UPDATE uv_tosend SET mtimeOnly=1 WHERE name=%Q", zName);
 
 
2060 }
2061 }else
2062
2063 /* push SERVERCODE PRODUCTCODE
2064 **
2065
--- src/xfer.c
+++ src/xfer.c
@@ -311,10 +311,11 @@
311 Blob *pHash; /* The HASH value */
312 int sz; /* The SIZE */
313 int flags; /* The FLAGS */
314 Blob content; /* The CONTENT */
315 Blob hash; /* Hash computed from CONTENT to compare with HASH */
316 Blob x; /* Compressed content */
317 Stmt q; /* SQL statements for comparison and insert */
318 int isDelete; /* HASH is "-" indicating this is a delete operation */
319 int nullContent; /* True of CONTENT is NULL */
320 int iStatus; /* Result from unversioned_status() */
321
@@ -329,10 +330,11 @@
330 blob_appendf(&pXfer->err, "malformed uvfile line");
331 return;
332 }
333 blob_init(&content, 0, 0);
334 blob_init(&hash, 0, 0);
335 blob_init(&x, 0, 0);
336 if( sz>0 && (flags & 0x0005)==0 ){
337 blob_extract(pXfer->pIn, sz, &content);
338 nullContent = 0;
339 sha1sum_blob(&content, &hash);
340 if( blob_compare(&hash, pHash)!=0 ){
@@ -356,35 +358,45 @@
358 /* Store the content */
359 isDelete = blob_eq(pHash, "-");
360 if( isDelete ){
361 db_prepare(&q,
362 "UPDATE unversioned"
363 " SET rcvid=:rcvid, mtime=:mtime, hash=NULL, sz=0, encoding=0, content=NULL"
364 " WHERE name=:name"
365 );
366 db_bind_int(&q, ":rcvid", g.rcvid);
367 }else if( iStatus==4 ){
368 db_prepare(&q, "UPDATE unversioned SET mtime=:mtime WHERE name=:name");
369 }else{
370 db_prepare(&q,
371 "REPLACE INTO unversioned(name, rcvid, mtime, hash, sz, encoding, content)"
372 " VALUES(:name,:rcvid,:mtime,:hash,:sz,:encoding,:content)"
373 );
374 db_bind_int(&q, ":rcvid", g.rcvid);
375 db_bind_text(&q, ":hash", blob_str(pHash));
376 db_bind_int(&q, ":sz", blob_size(&content));
377 if( !nullContent ){
378 blob_compress(&content, &x);
379 if( blob_size(&x) < 0.8*blob_size(&content) ){
380 db_bind_blob(&q, ":content", &x);
381 db_bind_int(&q, ":encoding", 1);
382 }else{
383 db_bind_blob(&q, ":content", &content);
384 db_bind_int(&q, ":encoding", 0);
385 }
386 }else{
387 db_bind_int(&q, ":encoding", 0);
388 }
389 }
390 db_bind_text(&q, ":name", blob_str(&pXfer->aToken[1]));
 
391 db_bind_int64(&q, ":mtime", mtime);
 
 
 
 
 
 
392 db_step(&q);
393 db_finalize(&q);
394 db_unset("uv-hash", 0);
395
396 end_accept_unversioned_file:
397 blob_reset(&x);
398 blob_reset(&content);
399 blob_reset(&hash);
400 }
401
402 /*
@@ -654,11 +666,11 @@
666 if( db_step(&q1)==SQLITE_ROW ){
667 sqlite3_int64 mtime = db_column_int64(&q1, 0);
668 const char *zHash = db_column_text(&q1, 1);
669 blob_appendf(pXfer->pOut, "uvfile %s %lld", zName, mtime);
670 if( zHash==0 ){
671 blob_append(pXfer->pOut, " - 0 1\n", -1);
672 }else if( noContent ){
673 blob_appendf(pXfer->pOut, " %s %d 4\n", zHash, db_column_int(&q1,3));
674 }else{
675 Blob content;
676 blob_init(&content, 0, 0);
@@ -1706,11 +1718,11 @@
1718 /* When syncing unversioned files, create a TEMP table in which to store
1719 ** the names of files that do not need to be sent from client to server.
1720 */
1721 if( syncFlags & SYNC_UNVERSIONED ){
1722 db_multi_exec(
1723 "CREATE TEMP TABLE uv_tosend("
1724 " name TEXT PRIMARY KEY,"
1725 " mtimeOnly BOOLEAN"
1726 ") WITHOUT ROWID;"
1727 "INSERT INTO uv_toSend(name,mtimeOnly)"
1728 " SELECT name, 0 FROM unversioned WHERE hash IS NOT NULL;"
@@ -1841,10 +1853,11 @@
1853 assert( uvStatus==2 );
1854 db_prepare(&uvq, "SELECT name, mtimeOnly FROM uv_tosend");
1855 while( db_step(&uvq)==SQLITE_ROW ){
1856 send_unversioned_file(&xfer, db_column_text(&uvq,0), db_column_int(&uvq,1));
1857 nCardSent++;
1858 nArtifactSent++;
1859 }
1860 db_finalize(&uvq);
1861 uvDoPush = 0;
1862 }
1863
@@ -2055,10 +2068,12 @@
2068 }
2069 if( iStatus<=3 ){
2070 db_multi_exec("DELETE FROM uv_tosend WHERE name=%Q", zName);
2071 }else if( iStatus==4 ){
2072 db_multi_exec("UPDATE uv_tosend SET mtimeOnly=1 WHERE name=%Q", zName);
2073 }else if( iStatus==5 ){
2074 db_multi_exec("REPLACE INTO uv_tosend(name,mtimeOnly) VALUES(%Q,0)", zName);
2075 }
2076 }else
2077
2078 /* push SERVERCODE PRODUCTCODE
2079 **
2080

Keyboard Shortcuts

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