##// END OF EJS Templates
largefiles: refactoring - return hex from _getfile and copyandhash
Mads Kiilerich -
r18999:c1b5f9c4 default
parent child Browse files
Show More
@@ -8,7 +8,6 b''
8
8
9 '''base class for store implementations and store-related utility code'''
9 '''base class for store implementations and store-related utility code'''
10
10
11 import binascii
12 import re
11 import re
13
12
14 from mercurial import util, node, hg
13 from mercurial import util, node, hg
@@ -74,7 +73,7 b' class basestore(object):'
74 createmode=self.repo.store.createmode)
73 createmode=self.repo.store.createmode)
75
74
76 try:
75 try:
77 hhash = binascii.hexlify(self._getfile(tmpfile, filename, hash))
76 hhash = self._getfile(tmpfile, filename, hash)
78 except StoreError, err:
77 except StoreError, err:
79 ui.warn(err.longmessage())
78 ui.warn(err.longmessage())
80 hhash = ""
79 hhash = ""
@@ -128,7 +127,7 b' class basestore(object):'
128 def _getfile(self, tmpfile, filename, hash):
127 def _getfile(self, tmpfile, filename, hash):
129 '''Fetch one revision of one file from the store and write it
128 '''Fetch one revision of one file from the store and write it
130 to tmpfile. Compute the hash of the file on-the-fly as it
129 to tmpfile. Compute the hash of the file on-the-fly as it
131 downloads and return the binary hash. Close tmpfile. Raise
130 downloads and return the hash. Close tmpfile. Raise
132 StoreError if unable to download the file (e.g. it does not
131 StoreError if unable to download the file (e.g. it does not
133 exist in the store).'''
132 exist in the store).'''
134 raise NotImplementedError('abstract method')
133 raise NotImplementedError('abstract method')
@@ -290,7 +290,7 b' def writestandin(repo, standin, hash, ex'
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. Close outfile
293 when done and return the binary hash.'''
293 when done and return the hash.'''
294 hasher = util.sha1('')
294 hasher = util.sha1('')
295 for data in instream:
295 for data in instream:
296 hasher.update(data)
296 hasher.update(data)
@@ -301,7 +301,7 b' def copyandhash(instream, outfile):'
301 # outfile was opened just to copy and hash.
301 # outfile was opened just to copy and hash.
302 outfile.close()
302 outfile.close()
303
303
304 return hasher.digest()
304 return hasher.hexdigest()
305
305
306 def hashrepofile(repo, file):
306 def hashrepofile(repo, file):
307 return hashfile(repo.wjoin(file))
307 return hashfile(repo.wjoin(file))
General Comments 0
You need to be logged in to leave comments. Login now