Fossil SCM
Avoid unnecessary SHA1 calls in the bundle.c module.
Commit
527d4eddc7f3be9fa3bfba58009128908db40df1
Parent
f7861887d36f0e2…
1 file changed
+7
-13
+7
-13
| --- src/bundle.c | ||
| +++ src/bundle.c | ||
| @@ -35,11 +35,11 @@ | ||
| 35 | 35 | @ bcname TEXT, |
| 36 | 36 | @ bcvalue ANY |
| 37 | 37 | @ ); |
| 38 | 38 | @ CREATE TABLE IF NOT EXISTS "%w".bblob( |
| 39 | 39 | @ 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 | |
| 41 | 41 | @ sz INT NOT NULL, -- Size of blob after expansion |
| 42 | 42 | @ delta ANY, -- Delta compression basis, or NULL |
| 43 | 43 | @ notes TEXT, -- Description of content |
| 44 | 44 | @ data BLOB -- compressed content |
| 45 | 45 | @ ); |
| @@ -439,11 +439,11 @@ | ||
| 439 | 439 | " WHERE bix.delta=%d" |
| 440 | 440 | " AND bix.blobid=bblob.blobid;", |
| 441 | 441 | iSrc |
| 442 | 442 | ); |
| 443 | 443 | while( db_step(&q)==SQLITE_ROW ){ |
| 444 | - Blob h1, h2, c1, c2; | |
| 444 | + Blob h1, c1, c2; | |
| 445 | 445 | int rid; |
| 446 | 446 | blob_zero(&h1); |
| 447 | 447 | db_column_blob(&q, 0, &h1); |
| 448 | 448 | blob_zero(&c1); |
| 449 | 449 | db_column_blob(&q, 1, &c1); |
| @@ -461,16 +461,13 @@ | ||
| 461 | 461 | blob_delta_apply(pBasis, &c1, &c2); |
| 462 | 462 | blob_reset(&c1); |
| 463 | 463 | }else{ |
| 464 | 464 | c2 = c1; |
| 465 | 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)); | |
| 466 | + if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){ | |
| 467 | + fossil_fatal("artifact hash error on %b", &h1); | |
| 470 | 468 | } |
| 471 | - blob_reset(&h2); | |
| 472 | 469 | rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv); |
| 473 | 470 | if( rid==0 ){ |
| 474 | 471 | fossil_fatal("%s", g.zErrMsg); |
| 475 | 472 | }else{ |
| 476 | 473 | if( !isPriv ) content_make_public(rid); |
| @@ -491,11 +488,11 @@ | ||
| 491 | 488 | static void bundle_extract_item( |
| 492 | 489 | int blobid, /* ID of the item to extract */ |
| 493 | 490 | Blob *pOut /* Write the content into this blob */ |
| 494 | 491 | ){ |
| 495 | 492 | Stmt q; |
| 496 | - Blob x, basis, h1, h2; | |
| 493 | + Blob x, basis, h1; | |
| 497 | 494 | static Bag busy; |
| 498 | 495 | |
| 499 | 496 | db_prepare(&q, "SELECT uuid, delta, data FROM bblob" |
| 500 | 497 | " WHERE blobid=%d", blobid); |
| 501 | 498 | if( db_step(&q)!=SQLITE_ROW ){ |
| @@ -525,17 +522,14 @@ | ||
| 525 | 522 | }else{ |
| 526 | 523 | *pOut = x; |
| 527 | 524 | } |
| 528 | 525 | blob_zero(&h1); |
| 529 | 526 | 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); | |
| 534 | 529 | } |
| 535 | 530 | blob_reset(&h1); |
| 536 | - blob_reset(&h2); | |
| 537 | 531 | bag_remove(&busy, blobid); |
| 538 | 532 | db_finalize(&q); |
| 539 | 533 | } |
| 540 | 534 | |
| 541 | 535 | /* fossil bundle cat BUNDLE UUID... |
| 542 | 536 |
| --- 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 |