Fossil SCM
Remove unnecessary references to sha1sum from xfer.c.
Commit
7ec259c3acff7fcad95740c2b7e1028488e4f107
Parent
fc246fc4d1e9e98…
1 file changed
+17
-24
+17
-24
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -122,12 +122,13 @@ | ||
| 122 | 122 | int *pnUuidList |
| 123 | 123 | ){ |
| 124 | 124 | int n; |
| 125 | 125 | int rid; |
| 126 | 126 | int srcid = 0; |
| 127 | - Blob content, hash; | |
| 127 | + Blob content; | |
| 128 | 128 | int isPriv; |
| 129 | + Blob *pUuid; | |
| 129 | 130 | |
| 130 | 131 | isPriv = pXfer->nextIsPrivate; |
| 131 | 132 | pXfer->nextIsPrivate = 0; |
| 132 | 133 | if( pXfer->nToken<3 |
| 133 | 134 | || pXfer->nToken>4 |
| @@ -138,13 +139,13 @@ | ||
| 138 | 139 | ){ |
| 139 | 140 | blob_appendf(&pXfer->err, "malformed file line"); |
| 140 | 141 | return; |
| 141 | 142 | } |
| 142 | 143 | blob_zero(&content); |
| 143 | - blob_zero(&hash); | |
| 144 | 144 | blob_extract(pXfer->pIn, n, &content); |
| 145 | - if( !cloneFlag && uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){ | |
| 145 | + pUuid = &pXfer->aToken[1]; | |
| 146 | + if( !cloneFlag && uuid_is_shunned(blob_str(pUuid)) ){ | |
| 146 | 147 | /* Ignore files that have been shunned */ |
| 147 | 148 | blob_reset(&content); |
| 148 | 149 | return; |
| 149 | 150 | } |
| 150 | 151 | if( isPriv && !g.perm.Private ){ |
| @@ -158,26 +159,26 @@ | ||
| 158 | 159 | pXfer->nDeltaRcvd++; |
| 159 | 160 | }else{ |
| 160 | 161 | srcid = 0; |
| 161 | 162 | pXfer->nFileRcvd++; |
| 162 | 163 | } |
| 163 | - rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid, | |
| 164 | + rid = content_put_ex(&content, blob_str(pUuid), srcid, | |
| 164 | 165 | 0, isPriv); |
| 165 | - Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]), | |
| 166 | - blob_size(&pXfer->aToken[1])); | |
| 166 | + Th_AppendToList(pzUuidList, pnUuidList, blob_str(pUuid), | |
| 167 | + blob_size(pUuid)); | |
| 167 | 168 | remote_has(rid); |
| 168 | 169 | blob_reset(&content); |
| 169 | 170 | return; |
| 170 | 171 | } |
| 171 | 172 | if( pXfer->nToken==4 ){ |
| 172 | 173 | Blob src, next; |
| 173 | 174 | srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv); |
| 174 | 175 | if( content_get(srcid, &src)==0 ){ |
| 175 | - rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid, | |
| 176 | + rid = content_put_ex(&content, blob_str(pUuid), srcid, | |
| 176 | 177 | 0, isPriv); |
| 177 | - Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]), | |
| 178 | - blob_size(&pXfer->aToken[1])); | |
| 178 | + Th_AppendToList(pzUuidList, pnUuidList, blob_str(pUuid), | |
| 179 | + blob_size(pUuid)); | |
| 179 | 180 | pXfer->nDanglingFile++; |
| 180 | 181 | db_multi_exec("DELETE FROM phantom WHERE rid=%d", rid); |
| 181 | 182 | if( !isPriv ) content_make_public(rid); |
| 182 | 183 | blob_reset(&src); |
| 183 | 184 | blob_reset(&content); |
| @@ -189,19 +190,15 @@ | ||
| 189 | 190 | blob_reset(&content); |
| 190 | 191 | content = next; |
| 191 | 192 | }else{ |
| 192 | 193 | pXfer->nFileRcvd++; |
| 193 | 194 | } |
| 194 | - sha1sum_blob(&content, &hash); | |
| 195 | - if( !blob_eq_str(&pXfer->aToken[1], blob_str(&hash), -1) ){ | |
| 196 | - blob_appendf(&pXfer->err, | |
| 197 | - "wrong hash on received artifact: expected %s but got %s", | |
| 198 | - blob_str(&pXfer->aToken[1]), blob_str(&hash)); | |
| 199 | - } | |
| 200 | - rid = content_put_ex(&content, blob_str(&hash), 0, 0, isPriv); | |
| 201 | - Th_AppendToList(pzUuidList, pnUuidList, blob_str(&hash), blob_size(&hash)); | |
| 202 | - blob_reset(&hash); | |
| 195 | + if( hname_verify_hash(&content, blob_buffer(pUuid), blob_size(pUuid))==0 ){ | |
| 196 | + blob_appendf(&pXfer->err, "wrong hash on received artifact: %b", pUuid); | |
| 197 | + } | |
| 198 | + rid = content_put_ex(&content, blob_str(pUuid), 0, 0, isPriv); | |
| 199 | + Th_AppendToList(pzUuidList, pnUuidList, blob_str(pUuid), blob_size(pUuid)); | |
| 203 | 200 | if( rid==0 ){ |
| 204 | 201 | blob_appendf(&pXfer->err, "%s", g.zErrMsg); |
| 205 | 202 | blob_reset(&content); |
| 206 | 203 | }else{ |
| 207 | 204 | if( !isPriv ) content_make_public(rid); |
| @@ -297,11 +294,11 @@ | ||
| 297 | 294 | ** |
| 298 | 295 | ** If the 0x0001 bit of FLAGS is set, that means the file has been |
| 299 | 296 | ** deleted, SIZE is zero, the HASH is "-", and the "\n CONTENT" is omitted. |
| 300 | 297 | ** |
| 301 | 298 | ** SIZE is the number of bytes of CONTENT. The CONTENT is uncompressed. |
| 302 | -** HASH is the SHA1 hash of CONTENT. | |
| 299 | +** HASH is the artifact hash of CONTENT. | |
| 303 | 300 | ** |
| 304 | 301 | ** If the 0x0004 bit of FLAGS is set, that means the CONTENT is omitted. |
| 305 | 302 | ** The sender might have omitted the content because it is too big to |
| 306 | 303 | ** transmit, or because it is unchanged and this record exists purely |
| 307 | 304 | ** to update the MTIME. |
| @@ -310,11 +307,10 @@ | ||
| 310 | 307 | sqlite3_int64 mtime; /* The MTIME */ |
| 311 | 308 | Blob *pHash; /* The HASH value */ |
| 312 | 309 | int sz; /* The SIZE */ |
| 313 | 310 | int flags; /* The FLAGS */ |
| 314 | 311 | Blob content; /* The CONTENT */ |
| 315 | - Blob hash; /* Hash computed from CONTENT to compare with HASH */ | |
| 316 | 312 | Blob x; /* Compressed content */ |
| 317 | 313 | Stmt q; /* SQL statements for comparison and insert */ |
| 318 | 314 | int isDelete; /* HASH is "-" indicating this is a delete */ |
| 319 | 315 | int nullContent; /* True of CONTENT is NULL */ |
| 320 | 316 | int iStatus; /* Result from unversioned_status() */ |
| @@ -329,17 +325,15 @@ | ||
| 329 | 325 | ){ |
| 330 | 326 | blob_appendf(&pXfer->err, "malformed uvfile line"); |
| 331 | 327 | return; |
| 332 | 328 | } |
| 333 | 329 | blob_init(&content, 0, 0); |
| 334 | - blob_init(&hash, 0, 0); | |
| 335 | 330 | blob_init(&x, 0, 0); |
| 336 | 331 | if( sz>0 && (flags & 0x0005)==0 ){ |
| 337 | 332 | blob_extract(pXfer->pIn, sz, &content); |
| 338 | 333 | nullContent = 0; |
| 339 | - sha1sum_blob(&content, &hash); | |
| 340 | - if( blob_compare(&hash, pHash)!=0 ){ | |
| 334 | + if( hname_verify_hash(&content, blob_buffer(pHash), blob_size(pHash))==0 ){ | |
| 341 | 335 | blob_appendf(&pXfer->err, "in uvfile line, HASH does not match CONTENT"); |
| 342 | 336 | goto end_accept_unversioned_file; |
| 343 | 337 | } |
| 344 | 338 | }else{ |
| 345 | 339 | nullContent = 1; |
| @@ -399,11 +393,10 @@ | ||
| 399 | 393 | db_unset("uv-hash", 0); |
| 400 | 394 | |
| 401 | 395 | end_accept_unversioned_file: |
| 402 | 396 | blob_reset(&x); |
| 403 | 397 | blob_reset(&content); |
| 404 | - blob_reset(&hash); | |
| 405 | 398 | } |
| 406 | 399 | |
| 407 | 400 | /* |
| 408 | 401 | ** Try to send a file as a delta against its parent. |
| 409 | 402 | ** If successful, return the number of bytes in the delta. |
| 410 | 403 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -122,12 +122,13 @@ | |
| 122 | int *pnUuidList |
| 123 | ){ |
| 124 | int n; |
| 125 | int rid; |
| 126 | int srcid = 0; |
| 127 | Blob content, hash; |
| 128 | int isPriv; |
| 129 | |
| 130 | isPriv = pXfer->nextIsPrivate; |
| 131 | pXfer->nextIsPrivate = 0; |
| 132 | if( pXfer->nToken<3 |
| 133 | || pXfer->nToken>4 |
| @@ -138,13 +139,13 @@ | |
| 138 | ){ |
| 139 | blob_appendf(&pXfer->err, "malformed file line"); |
| 140 | return; |
| 141 | } |
| 142 | blob_zero(&content); |
| 143 | blob_zero(&hash); |
| 144 | blob_extract(pXfer->pIn, n, &content); |
| 145 | if( !cloneFlag && uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){ |
| 146 | /* Ignore files that have been shunned */ |
| 147 | blob_reset(&content); |
| 148 | return; |
| 149 | } |
| 150 | if( isPriv && !g.perm.Private ){ |
| @@ -158,26 +159,26 @@ | |
| 158 | pXfer->nDeltaRcvd++; |
| 159 | }else{ |
| 160 | srcid = 0; |
| 161 | pXfer->nFileRcvd++; |
| 162 | } |
| 163 | rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid, |
| 164 | 0, isPriv); |
| 165 | Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]), |
| 166 | blob_size(&pXfer->aToken[1])); |
| 167 | remote_has(rid); |
| 168 | blob_reset(&content); |
| 169 | return; |
| 170 | } |
| 171 | if( pXfer->nToken==4 ){ |
| 172 | Blob src, next; |
| 173 | srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv); |
| 174 | if( content_get(srcid, &src)==0 ){ |
| 175 | rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid, |
| 176 | 0, isPriv); |
| 177 | Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]), |
| 178 | blob_size(&pXfer->aToken[1])); |
| 179 | pXfer->nDanglingFile++; |
| 180 | db_multi_exec("DELETE FROM phantom WHERE rid=%d", rid); |
| 181 | if( !isPriv ) content_make_public(rid); |
| 182 | blob_reset(&src); |
| 183 | blob_reset(&content); |
| @@ -189,19 +190,15 @@ | |
| 189 | blob_reset(&content); |
| 190 | content = next; |
| 191 | }else{ |
| 192 | pXfer->nFileRcvd++; |
| 193 | } |
| 194 | sha1sum_blob(&content, &hash); |
| 195 | if( !blob_eq_str(&pXfer->aToken[1], blob_str(&hash), -1) ){ |
| 196 | blob_appendf(&pXfer->err, |
| 197 | "wrong hash on received artifact: expected %s but got %s", |
| 198 | blob_str(&pXfer->aToken[1]), blob_str(&hash)); |
| 199 | } |
| 200 | rid = content_put_ex(&content, blob_str(&hash), 0, 0, isPriv); |
| 201 | Th_AppendToList(pzUuidList, pnUuidList, blob_str(&hash), blob_size(&hash)); |
| 202 | blob_reset(&hash); |
| 203 | if( rid==0 ){ |
| 204 | blob_appendf(&pXfer->err, "%s", g.zErrMsg); |
| 205 | blob_reset(&content); |
| 206 | }else{ |
| 207 | if( !isPriv ) content_make_public(rid); |
| @@ -297,11 +294,11 @@ | |
| 297 | ** |
| 298 | ** If the 0x0001 bit of FLAGS is set, that means the file has been |
| 299 | ** deleted, SIZE is zero, the HASH is "-", and the "\n CONTENT" is omitted. |
| 300 | ** |
| 301 | ** SIZE is the number of bytes of CONTENT. The CONTENT is uncompressed. |
| 302 | ** HASH is the SHA1 hash of CONTENT. |
| 303 | ** |
| 304 | ** If the 0x0004 bit of FLAGS is set, that means the CONTENT is omitted. |
| 305 | ** The sender might have omitted the content because it is too big to |
| 306 | ** transmit, or because it is unchanged and this record exists purely |
| 307 | ** to update the MTIME. |
| @@ -310,11 +307,10 @@ | |
| 310 | sqlite3_int64 mtime; /* The MTIME */ |
| 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 */ |
| 319 | int nullContent; /* True of CONTENT is NULL */ |
| 320 | int iStatus; /* Result from unversioned_status() */ |
| @@ -329,17 +325,15 @@ | |
| 329 | ){ |
| 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 ){ |
| 341 | blob_appendf(&pXfer->err, "in uvfile line, HASH does not match CONTENT"); |
| 342 | goto end_accept_unversioned_file; |
| 343 | } |
| 344 | }else{ |
| 345 | nullContent = 1; |
| @@ -399,11 +393,10 @@ | |
| 399 | db_unset("uv-hash", 0); |
| 400 | |
| 401 | end_accept_unversioned_file: |
| 402 | blob_reset(&x); |
| 403 | blob_reset(&content); |
| 404 | blob_reset(&hash); |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | ** Try to send a file as a delta against its parent. |
| 409 | ** If successful, return the number of bytes in the delta. |
| 410 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -122,12 +122,13 @@ | |
| 122 | int *pnUuidList |
| 123 | ){ |
| 124 | int n; |
| 125 | int rid; |
| 126 | int srcid = 0; |
| 127 | Blob content; |
| 128 | int isPriv; |
| 129 | Blob *pUuid; |
| 130 | |
| 131 | isPriv = pXfer->nextIsPrivate; |
| 132 | pXfer->nextIsPrivate = 0; |
| 133 | if( pXfer->nToken<3 |
| 134 | || pXfer->nToken>4 |
| @@ -138,13 +139,13 @@ | |
| 139 | ){ |
| 140 | blob_appendf(&pXfer->err, "malformed file line"); |
| 141 | return; |
| 142 | } |
| 143 | blob_zero(&content); |
| 144 | blob_extract(pXfer->pIn, n, &content); |
| 145 | pUuid = &pXfer->aToken[1]; |
| 146 | if( !cloneFlag && uuid_is_shunned(blob_str(pUuid)) ){ |
| 147 | /* Ignore files that have been shunned */ |
| 148 | blob_reset(&content); |
| 149 | return; |
| 150 | } |
| 151 | if( isPriv && !g.perm.Private ){ |
| @@ -158,26 +159,26 @@ | |
| 159 | pXfer->nDeltaRcvd++; |
| 160 | }else{ |
| 161 | srcid = 0; |
| 162 | pXfer->nFileRcvd++; |
| 163 | } |
| 164 | rid = content_put_ex(&content, blob_str(pUuid), srcid, |
| 165 | 0, isPriv); |
| 166 | Th_AppendToList(pzUuidList, pnUuidList, blob_str(pUuid), |
| 167 | blob_size(pUuid)); |
| 168 | remote_has(rid); |
| 169 | blob_reset(&content); |
| 170 | return; |
| 171 | } |
| 172 | if( pXfer->nToken==4 ){ |
| 173 | Blob src, next; |
| 174 | srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv); |
| 175 | if( content_get(srcid, &src)==0 ){ |
| 176 | rid = content_put_ex(&content, blob_str(pUuid), srcid, |
| 177 | 0, isPriv); |
| 178 | Th_AppendToList(pzUuidList, pnUuidList, blob_str(pUuid), |
| 179 | blob_size(pUuid)); |
| 180 | pXfer->nDanglingFile++; |
| 181 | db_multi_exec("DELETE FROM phantom WHERE rid=%d", rid); |
| 182 | if( !isPriv ) content_make_public(rid); |
| 183 | blob_reset(&src); |
| 184 | blob_reset(&content); |
| @@ -189,19 +190,15 @@ | |
| 190 | blob_reset(&content); |
| 191 | content = next; |
| 192 | }else{ |
| 193 | pXfer->nFileRcvd++; |
| 194 | } |
| 195 | if( hname_verify_hash(&content, blob_buffer(pUuid), blob_size(pUuid))==0 ){ |
| 196 | blob_appendf(&pXfer->err, "wrong hash on received artifact: %b", pUuid); |
| 197 | } |
| 198 | rid = content_put_ex(&content, blob_str(pUuid), 0, 0, isPriv); |
| 199 | Th_AppendToList(pzUuidList, pnUuidList, blob_str(pUuid), blob_size(pUuid)); |
| 200 | if( rid==0 ){ |
| 201 | blob_appendf(&pXfer->err, "%s", g.zErrMsg); |
| 202 | blob_reset(&content); |
| 203 | }else{ |
| 204 | if( !isPriv ) content_make_public(rid); |
| @@ -297,11 +294,11 @@ | |
| 294 | ** |
| 295 | ** If the 0x0001 bit of FLAGS is set, that means the file has been |
| 296 | ** deleted, SIZE is zero, the HASH is "-", and the "\n CONTENT" is omitted. |
| 297 | ** |
| 298 | ** SIZE is the number of bytes of CONTENT. The CONTENT is uncompressed. |
| 299 | ** HASH is the artifact hash of CONTENT. |
| 300 | ** |
| 301 | ** If the 0x0004 bit of FLAGS is set, that means the CONTENT is omitted. |
| 302 | ** The sender might have omitted the content because it is too big to |
| 303 | ** transmit, or because it is unchanged and this record exists purely |
| 304 | ** to update the MTIME. |
| @@ -310,11 +307,10 @@ | |
| 307 | sqlite3_int64 mtime; /* The MTIME */ |
| 308 | Blob *pHash; /* The HASH value */ |
| 309 | int sz; /* The SIZE */ |
| 310 | int flags; /* The FLAGS */ |
| 311 | Blob content; /* The CONTENT */ |
| 312 | Blob x; /* Compressed content */ |
| 313 | Stmt q; /* SQL statements for comparison and insert */ |
| 314 | int isDelete; /* HASH is "-" indicating this is a delete */ |
| 315 | int nullContent; /* True of CONTENT is NULL */ |
| 316 | int iStatus; /* Result from unversioned_status() */ |
| @@ -329,17 +325,15 @@ | |
| 325 | ){ |
| 326 | blob_appendf(&pXfer->err, "malformed uvfile line"); |
| 327 | return; |
| 328 | } |
| 329 | blob_init(&content, 0, 0); |
| 330 | blob_init(&x, 0, 0); |
| 331 | if( sz>0 && (flags & 0x0005)==0 ){ |
| 332 | blob_extract(pXfer->pIn, sz, &content); |
| 333 | nullContent = 0; |
| 334 | if( hname_verify_hash(&content, blob_buffer(pHash), blob_size(pHash))==0 ){ |
| 335 | blob_appendf(&pXfer->err, "in uvfile line, HASH does not match CONTENT"); |
| 336 | goto end_accept_unversioned_file; |
| 337 | } |
| 338 | }else{ |
| 339 | nullContent = 1; |
| @@ -399,11 +393,10 @@ | |
| 393 | db_unset("uv-hash", 0); |
| 394 | |
| 395 | end_accept_unversioned_file: |
| 396 | blob_reset(&x); |
| 397 | blob_reset(&content); |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | ** Try to send a file as a delta against its parent. |
| 402 | ** If successful, return the number of bytes in the delta. |
| 403 |