Fossil SCM

Avoid unnecessary SHA1 calls in the bundle.c module.

drh 2017-03-01 00:34 fossil-2.0
Commit 527d4eddc7f3be9fa3bfba58009128908db40df1
1 file changed +7 -13
+7 -13
--- src/bundle.c
+++ src/bundle.c
@@ -35,11 +35,11 @@
3535
@ bcname TEXT,
3636
@ bcvalue ANY
3737
@ );
3838
@ CREATE TABLE IF NOT EXISTS "%w".bblob(
3939
@ blobid INTEGER PRIMARY KEY, -- Blob ID
40
-@ uuid TEXT NOT NULL, -- SHA1 hash of expanded blob
40
+@ uuid TEXT NOT NULL, -- hash of expanded blob
4141
@ sz INT NOT NULL, -- Size of blob after expansion
4242
@ delta ANY, -- Delta compression basis, or NULL
4343
@ notes TEXT, -- Description of content
4444
@ data BLOB -- compressed content
4545
@ );
@@ -439,11 +439,11 @@
439439
" WHERE bix.delta=%d"
440440
" AND bix.blobid=bblob.blobid;",
441441
iSrc
442442
);
443443
while( db_step(&q)==SQLITE_ROW ){
444
- Blob h1, h2, c1, c2;
444
+ Blob h1, c1, c2;
445445
int rid;
446446
blob_zero(&h1);
447447
db_column_blob(&q, 0, &h1);
448448
blob_zero(&c1);
449449
db_column_blob(&q, 1, &c1);
@@ -461,16 +461,13 @@
461461
blob_delta_apply(pBasis, &c1, &c2);
462462
blob_reset(&c1);
463463
}else{
464464
c2 = c1;
465465
}
466
- sha1sum_blob(&c2, &h2);
467
- if( blob_compare(&h1, &h2)!=0 ){
468
- fossil_fatal("SHA1 hash mismatch - wanted %s, got %s",
469
- blob_str(&h1), blob_str(&h2));
466
+ if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){
467
+ fossil_fatal("artifact hash error on %b", &h1);
470468
}
471
- blob_reset(&h2);
472469
rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv);
473470
if( rid==0 ){
474471
fossil_fatal("%s", g.zErrMsg);
475472
}else{
476473
if( !isPriv ) content_make_public(rid);
@@ -491,11 +488,11 @@
491488
static void bundle_extract_item(
492489
int blobid, /* ID of the item to extract */
493490
Blob *pOut /* Write the content into this blob */
494491
){
495492
Stmt q;
496
- Blob x, basis, h1, h2;
493
+ Blob x, basis, h1;
497494
static Bag busy;
498495
499496
db_prepare(&q, "SELECT uuid, delta, data FROM bblob"
500497
" WHERE blobid=%d", blobid);
501498
if( db_step(&q)!=SQLITE_ROW ){
@@ -525,17 +522,14 @@
525522
}else{
526523
*pOut = x;
527524
}
528525
blob_zero(&h1);
529526
db_column_blob(&q, 0, &h1);
530
- sha1sum_blob(pOut, &h2);
531
- if( blob_compare(&h1, &h2)!=0 ){
532
- fossil_fatal("SHA1 hash mismatch - wanted %s, got %s",
533
- blob_str(&h1), blob_str(&h2));
527
+ if( hname_verify_hash(pOut, blob_buffer(&h1), blob_size(&h1))==0 ){
528
+ fossil_fatal("incorrect hash for artifact %b", &h1);
534529
}
535530
blob_reset(&h1);
536
- blob_reset(&h2);
537531
bag_remove(&busy, blobid);
538532
db_finalize(&q);
539533
}
540534
541535
/* fossil bundle cat BUNDLE UUID...
542536
--- src/bundle.c
+++ src/bundle.c
@@ -35,11 +35,11 @@
35 @ bcname TEXT,
36 @ bcvalue ANY
37 @ );
38 @ CREATE TABLE IF NOT EXISTS "%w".bblob(
39 @ blobid INTEGER PRIMARY KEY, -- Blob ID
40 @ uuid TEXT NOT NULL, -- SHA1 hash of expanded blob
41 @ sz INT NOT NULL, -- Size of blob after expansion
42 @ delta ANY, -- Delta compression basis, or NULL
43 @ notes TEXT, -- Description of content
44 @ data BLOB -- compressed content
45 @ );
@@ -439,11 +439,11 @@
439 " WHERE bix.delta=%d"
440 " AND bix.blobid=bblob.blobid;",
441 iSrc
442 );
443 while( db_step(&q)==SQLITE_ROW ){
444 Blob h1, h2, c1, c2;
445 int rid;
446 blob_zero(&h1);
447 db_column_blob(&q, 0, &h1);
448 blob_zero(&c1);
449 db_column_blob(&q, 1, &c1);
@@ -461,16 +461,13 @@
461 blob_delta_apply(pBasis, &c1, &c2);
462 blob_reset(&c1);
463 }else{
464 c2 = c1;
465 }
466 sha1sum_blob(&c2, &h2);
467 if( blob_compare(&h1, &h2)!=0 ){
468 fossil_fatal("SHA1 hash mismatch - wanted %s, got %s",
469 blob_str(&h1), blob_str(&h2));
470 }
471 blob_reset(&h2);
472 rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv);
473 if( rid==0 ){
474 fossil_fatal("%s", g.zErrMsg);
475 }else{
476 if( !isPriv ) content_make_public(rid);
@@ -491,11 +488,11 @@
491 static void bundle_extract_item(
492 int blobid, /* ID of the item to extract */
493 Blob *pOut /* Write the content into this blob */
494 ){
495 Stmt q;
496 Blob x, basis, h1, h2;
497 static Bag busy;
498
499 db_prepare(&q, "SELECT uuid, delta, data FROM bblob"
500 " WHERE blobid=%d", blobid);
501 if( db_step(&q)!=SQLITE_ROW ){
@@ -525,17 +522,14 @@
525 }else{
526 *pOut = x;
527 }
528 blob_zero(&h1);
529 db_column_blob(&q, 0, &h1);
530 sha1sum_blob(pOut, &h2);
531 if( blob_compare(&h1, &h2)!=0 ){
532 fossil_fatal("SHA1 hash mismatch - wanted %s, got %s",
533 blob_str(&h1), blob_str(&h2));
534 }
535 blob_reset(&h1);
536 blob_reset(&h2);
537 bag_remove(&busy, blobid);
538 db_finalize(&q);
539 }
540
541 /* fossil bundle cat BUNDLE UUID...
542
--- src/bundle.c
+++ src/bundle.c
@@ -35,11 +35,11 @@
35 @ bcname TEXT,
36 @ bcvalue ANY
37 @ );
38 @ CREATE TABLE IF NOT EXISTS "%w".bblob(
39 @ blobid INTEGER PRIMARY KEY, -- Blob ID
40 @ uuid TEXT NOT NULL, -- hash of expanded blob
41 @ sz INT NOT NULL, -- Size of blob after expansion
42 @ delta ANY, -- Delta compression basis, or NULL
43 @ notes TEXT, -- Description of content
44 @ data BLOB -- compressed content
45 @ );
@@ -439,11 +439,11 @@
439 " WHERE bix.delta=%d"
440 " AND bix.blobid=bblob.blobid;",
441 iSrc
442 );
443 while( db_step(&q)==SQLITE_ROW ){
444 Blob h1, c1, c2;
445 int rid;
446 blob_zero(&h1);
447 db_column_blob(&q, 0, &h1);
448 blob_zero(&c1);
449 db_column_blob(&q, 1, &c1);
@@ -461,16 +461,13 @@
461 blob_delta_apply(pBasis, &c1, &c2);
462 blob_reset(&c1);
463 }else{
464 c2 = c1;
465 }
466 if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){
467 fossil_fatal("artifact hash error on %b", &h1);
 
 
468 }
 
469 rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv);
470 if( rid==0 ){
471 fossil_fatal("%s", g.zErrMsg);
472 }else{
473 if( !isPriv ) content_make_public(rid);
@@ -491,11 +488,11 @@
488 static void bundle_extract_item(
489 int blobid, /* ID of the item to extract */
490 Blob *pOut /* Write the content into this blob */
491 ){
492 Stmt q;
493 Blob x, basis, h1;
494 static Bag busy;
495
496 db_prepare(&q, "SELECT uuid, delta, data FROM bblob"
497 " WHERE blobid=%d", blobid);
498 if( db_step(&q)!=SQLITE_ROW ){
@@ -525,17 +522,14 @@
522 }else{
523 *pOut = x;
524 }
525 blob_zero(&h1);
526 db_column_blob(&q, 0, &h1);
527 if( hname_verify_hash(pOut, blob_buffer(&h1), blob_size(&h1))==0 ){
528 fossil_fatal("incorrect hash for artifact %b", &h1);
 
 
529 }
530 blob_reset(&h1);
 
531 bag_remove(&busy, blobid);
532 db_finalize(&q);
533 }
534
535 /* fossil bundle cat BUNDLE UUID...
536

Keyboard Shortcuts

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