Mercurial > hg
comparison hgext/largefiles/basestore.py @ 19918:ae65192fd6b4
largefiles: refactor basestore, extract _gethash method
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Thu, 10 Oct 2013 04:28:44 +0200 |
parents | 9d33d6e0d442 |
children | cce7ab960312 |
comparison
equal
deleted
inserted
replaced
19917:cff331cbb5ee | 19918:ae65192fd6b4 |
---|---|
57 summary.)''' | 57 summary.)''' |
58 success = [] | 58 success = [] |
59 missing = [] | 59 missing = [] |
60 ui = self.ui | 60 ui = self.ui |
61 | 61 |
62 util.makedirs(lfutil.storepath(self.repo, '')) | |
63 | |
64 at = 0 | 62 at = 0 |
65 available = self.exists(set(hash for (_filename, hash) in files)) | 63 available = self.exists(set(hash for (_filename, hash) in files)) |
66 for filename, hash in files: | 64 for filename, hash in files: |
67 ui.progress(_('getting largefiles'), at, unit='lfile', | 65 ui.progress(_('getting largefiles'), at, unit='lfile', |
68 total=len(files)) | 66 total=len(files)) |
73 ui.warn(_('%s: largefile %s not available from %s\n') | 71 ui.warn(_('%s: largefile %s not available from %s\n') |
74 % (filename, hash, self.url)) | 72 % (filename, hash, self.url)) |
75 missing.append(filename) | 73 missing.append(filename) |
76 continue | 74 continue |
77 | 75 |
78 storefilename = lfutil.storepath(self.repo, hash) | 76 if self._gethash(filename, hash): |
79 tmpfile = util.atomictempfile(storefilename + '.tmp', | 77 success.append((filename, hash)) |
80 createmode=self.repo.store.createmode) | 78 else: |
81 | |
82 try: | |
83 hhash = self._getfile(tmpfile, filename, hash) | |
84 except StoreError, err: | |
85 ui.warn(err.longmessage()) | |
86 hhash = "" | |
87 tmpfile.close() | |
88 | |
89 if hhash != hash: | |
90 if hhash != "": | |
91 ui.warn(_('%s: data corruption (expected %s, got %s)\n') | |
92 % (filename, hash, hhash)) | |
93 util.unlink(storefilename + '.tmp') | |
94 missing.append(filename) | 79 missing.append(filename) |
95 continue | |
96 | |
97 util.rename(storefilename + '.tmp', storefilename) | |
98 lfutil.linktousercache(self.repo, hash) | |
99 success.append((filename, hhash)) | |
100 | 80 |
101 ui.progress(_('getting largefiles'), None) | 81 ui.progress(_('getting largefiles'), None) |
102 return (success, missing) | 82 return (success, missing) |
83 | |
84 def _gethash(self, filename, hash): | |
85 """Get file with the provided hash and store it in the local repo's | |
86 store and in the usercache. | |
87 filename is for informational messages only. | |
88 """ | |
89 util.makedirs(lfutil.storepath(self.repo, '')) | |
90 storefilename = lfutil.storepath(self.repo, hash) | |
91 | |
92 tmpname = storefilename + '.tmp' | |
93 tmpfile = util.atomictempfile(tmpname, | |
94 createmode=self.repo.store.createmode) | |
95 | |
96 try: | |
97 gothash = self._getfile(tmpfile, filename, hash) | |
98 except StoreError, err: | |
99 self.ui.warn(err.longmessage()) | |
100 gothash = "" | |
101 tmpfile.close() | |
102 | |
103 if gothash != hash: | |
104 if gothash != "": | |
105 self.ui.warn(_('%s: data corruption (expected %s, got %s)\n') | |
106 % (filename, hash, gothash)) | |
107 util.unlink(tmpname) | |
108 return False | |
109 | |
110 util.rename(tmpname, storefilename) | |
111 lfutil.linktousercache(self.repo, hash) | |
112 return True | |
103 | 113 |
104 def verify(self, revs, contents=False): | 114 def verify(self, revs, contents=False): |
105 '''Verify the existence (and, optionally, contents) of every big | 115 '''Verify the existence (and, optionally, contents) of every big |
106 file revision referenced by every changeset in revs. | 116 file revision referenced by every changeset in revs. |
107 Return 0 if all is well, non-zero on any errors.''' | 117 Return 0 if all is well, non-zero on any errors.''' |