287 '''write hash to <repo.root>/<standin>''' |
287 '''write hash to <repo.root>/<standin>''' |
288 writehash(hash, repo.wjoin(standin), executable) |
288 writehash(hash, repo.wjoin(standin), executable) |
289 |
289 |
290 def copyandhash(instream, outfile): |
290 def copyandhash(instream, outfile): |
291 '''Read bytes from instream (iterable) and write them to outfile, |
291 '''Read bytes from instream (iterable) and write them to outfile, |
292 computing the SHA-1 hash of the data along the way. Close outfile |
292 computing the SHA-1 hash of the data along the way. Return the hash.''' |
293 when done and return the hash.''' |
|
294 hasher = util.sha1('') |
293 hasher = util.sha1('') |
295 for data in instream: |
294 for data in instream: |
296 hasher.update(data) |
295 hasher.update(data) |
297 outfile.write(data) |
296 outfile.write(data) |
298 |
|
299 # Blecch: closing a file that somebody else opened is rude and |
|
300 # wrong. But it's so darn convenient and practical! After all, |
|
301 # outfile was opened just to copy and hash. |
|
302 outfile.close() |
|
303 |
|
304 return hasher.hexdigest() |
297 return hasher.hexdigest() |
305 |
298 |
306 def hashrepofile(repo, file): |
299 def hashrepofile(repo, file): |
307 return hashfile(repo.wjoin(file)) |
300 return hashfile(repo.wjoin(file)) |
308 |
301 |