Fossil SCM

Remove unnecessary references to sha1sum from xfer.c.

drh 2017-02-28 22:15 fossil-2.0
Commit 7ec259c3acff7fcad95740c2b7e1028488e4f107
1 file changed +17 -24
+17 -24
--- src/xfer.c
+++ src/xfer.c
@@ -122,12 +122,13 @@
122122
int *pnUuidList
123123
){
124124
int n;
125125
int rid;
126126
int srcid = 0;
127
- Blob content, hash;
127
+ Blob content;
128128
int isPriv;
129
+ Blob *pUuid;
129130
130131
isPriv = pXfer->nextIsPrivate;
131132
pXfer->nextIsPrivate = 0;
132133
if( pXfer->nToken<3
133134
|| pXfer->nToken>4
@@ -138,13 +139,13 @@
138139
){
139140
blob_appendf(&pXfer->err, "malformed file line");
140141
return;
141142
}
142143
blob_zero(&content);
143
- blob_zero(&hash);
144144
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)) ){
146147
/* Ignore files that have been shunned */
147148
blob_reset(&content);
148149
return;
149150
}
150151
if( isPriv && !g.perm.Private ){
@@ -158,26 +159,26 @@
158159
pXfer->nDeltaRcvd++;
159160
}else{
160161
srcid = 0;
161162
pXfer->nFileRcvd++;
162163
}
163
- rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid,
164
+ rid = content_put_ex(&content, blob_str(pUuid), srcid,
164165
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));
167168
remote_has(rid);
168169
blob_reset(&content);
169170
return;
170171
}
171172
if( pXfer->nToken==4 ){
172173
Blob src, next;
173174
srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv);
174175
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,
176177
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));
179180
pXfer->nDanglingFile++;
180181
db_multi_exec("DELETE FROM phantom WHERE rid=%d", rid);
181182
if( !isPriv ) content_make_public(rid);
182183
blob_reset(&src);
183184
blob_reset(&content);
@@ -189,19 +190,15 @@
189190
blob_reset(&content);
190191
content = next;
191192
}else{
192193
pXfer->nFileRcvd++;
193194
}
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));
203200
if( rid==0 ){
204201
blob_appendf(&pXfer->err, "%s", g.zErrMsg);
205202
blob_reset(&content);
206203
}else{
207204
if( !isPriv ) content_make_public(rid);
@@ -297,11 +294,11 @@
297294
**
298295
** If the 0x0001 bit of FLAGS is set, that means the file has been
299296
** deleted, SIZE is zero, the HASH is "-", and the "\n CONTENT" is omitted.
300297
**
301298
** 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.
303300
**
304301
** If the 0x0004 bit of FLAGS is set, that means the CONTENT is omitted.
305302
** The sender might have omitted the content because it is too big to
306303
** transmit, or because it is unchanged and this record exists purely
307304
** to update the MTIME.
@@ -310,11 +307,10 @@
310307
sqlite3_int64 mtime; /* The MTIME */
311308
Blob *pHash; /* The HASH value */
312309
int sz; /* The SIZE */
313310
int flags; /* The FLAGS */
314311
Blob content; /* The CONTENT */
315
- Blob hash; /* Hash computed from CONTENT to compare with HASH */
316312
Blob x; /* Compressed content */
317313
Stmt q; /* SQL statements for comparison and insert */
318314
int isDelete; /* HASH is "-" indicating this is a delete */
319315
int nullContent; /* True of CONTENT is NULL */
320316
int iStatus; /* Result from unversioned_status() */
@@ -329,17 +325,15 @@
329325
){
330326
blob_appendf(&pXfer->err, "malformed uvfile line");
331327
return;
332328
}
333329
blob_init(&content, 0, 0);
334
- blob_init(&hash, 0, 0);
335330
blob_init(&x, 0, 0);
336331
if( sz>0 && (flags & 0x0005)==0 ){
337332
blob_extract(pXfer->pIn, sz, &content);
338333
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 ){
341335
blob_appendf(&pXfer->err, "in uvfile line, HASH does not match CONTENT");
342336
goto end_accept_unversioned_file;
343337
}
344338
}else{
345339
nullContent = 1;
@@ -399,11 +393,10 @@
399393
db_unset("uv-hash", 0);
400394
401395
end_accept_unversioned_file:
402396
blob_reset(&x);
403397
blob_reset(&content);
404
- blob_reset(&hash);
405398
}
406399
407400
/*
408401
** Try to send a file as a delta against its parent.
409402
** If successful, return the number of bytes in the delta.
410403
--- 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

Keyboard Shortcuts

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