comparison hgext/largefiles/basestore.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents 566daffc607d
children 687b865b95ad
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
13 13
14 from mercurial import node, util 14 from mercurial import node, util
15 15
16 from . import lfutil 16 from . import lfutil
17 17
18
18 class StoreError(Exception): 19 class StoreError(Exception):
19 '''Raised when there is a problem getting files from or putting 20 '''Raised when there is a problem getting files from or putting
20 files to a central store.''' 21 files to a central store.'''
22
21 def __init__(self, filename, hash, url, detail): 23 def __init__(self, filename, hash, url, detail):
22 self.filename = filename 24 self.filename = filename
23 self.hash = hash 25 self.hash = hash
24 self.url = url 26 self.url = url
25 self.detail = detail 27 self.detail = detail
26 28
27 def longmessage(self): 29 def longmessage(self):
28 return (_("error getting id %s from url %s for file %s: %s\n") % 30 return _("error getting id %s from url %s for file %s: %s\n") % (
29 (self.hash, util.hidepassword(self.url), self.filename, 31 self.hash,
30 self.detail)) 32 util.hidepassword(self.url),
33 self.filename,
34 self.detail,
35 )
31 36
32 def __str__(self): 37 def __str__(self):
33 return "%s: %s" % (util.hidepassword(self.url), self.detail) 38 return "%s: %s" % (util.hidepassword(self.url), self.detail)
39
34 40
35 class basestore(object): 41 class basestore(object):
36 def __init__(self, ui, repo, url): 42 def __init__(self, ui, repo, url):
37 self.ui = ui 43 self.ui = ui
38 self.repo = repo 44 self.repo = repo
60 missing = [] 66 missing = []
61 ui = self.ui 67 ui = self.ui
62 68
63 at = 0 69 at = 0
64 available = self.exists(set(hash for (_filename, hash) in files)) 70 available = self.exists(set(hash for (_filename, hash) in files))
65 with ui.makeprogress(_('getting largefiles'), unit=_('files'), 71 with ui.makeprogress(
66 total=len(files)) as progress: 72 _('getting largefiles'), unit=_('files'), total=len(files)
73 ) as progress:
67 for filename, hash in files: 74 for filename, hash in files:
68 progress.update(at) 75 progress.update(at)
69 at += 1 76 at += 1
70 ui.note(_('getting %s:%s\n') % (filename, hash)) 77 ui.note(_('getting %s:%s\n') % (filename, hash))
71 78
72 if not available.get(hash): 79 if not available.get(hash):
73 ui.warn(_('%s: largefile %s not available from %s\n') 80 ui.warn(
74 % (filename, hash, util.hidepassword(self.url))) 81 _('%s: largefile %s not available from %s\n')
82 % (filename, hash, util.hidepassword(self.url))
83 )
75 missing.append(filename) 84 missing.append(filename)
76 continue 85 continue
77 86
78 if self._gethash(filename, hash): 87 if self._gethash(filename, hash):
79 success.append((filename, hash)) 88 success.append((filename, hash))
89 """ 98 """
90 util.makedirs(lfutil.storepath(self.repo, '')) 99 util.makedirs(lfutil.storepath(self.repo, ''))
91 storefilename = lfutil.storepath(self.repo, hash) 100 storefilename = lfutil.storepath(self.repo, hash)
92 101
93 tmpname = storefilename + '.tmp' 102 tmpname = storefilename + '.tmp'
94 with util.atomictempfile(tmpname, 103 with util.atomictempfile(
95 createmode=self.repo.store.createmode) as tmpfile: 104 tmpname, createmode=self.repo.store.createmode
105 ) as tmpfile:
96 try: 106 try:
97 gothash = self._getfile(tmpfile, filename, hash) 107 gothash = self._getfile(tmpfile, filename, hash)
98 except StoreError as err: 108 except StoreError as err:
99 self.ui.warn(err.longmessage()) 109 self.ui.warn(err.longmessage())
100 gothash = "" 110 gothash = ""
101 111
102 if gothash != hash: 112 if gothash != hash:
103 if gothash != "": 113 if gothash != "":
104 self.ui.warn(_('%s: data corruption (expected %s, got %s)\n') 114 self.ui.warn(
105 % (filename, hash, gothash)) 115 _('%s: data corruption (expected %s, got %s)\n')
116 % (filename, hash, gothash)
117 )
106 util.unlink(tmpname) 118 util.unlink(tmpname)
107 return False 119 return False
108 120
109 util.rename(tmpname, storefilename) 121 util.rename(tmpname, storefilename)
110 lfutil.linktousercache(self.repo, hash) 122 lfutil.linktousercache(self.repo, hash)
113 def verify(self, revs, contents=False): 125 def verify(self, revs, contents=False):
114 '''Verify the existence (and, optionally, contents) of every big 126 '''Verify the existence (and, optionally, contents) of every big
115 file revision referenced by every changeset in revs. 127 file revision referenced by every changeset in revs.
116 Return 0 if all is well, non-zero on any errors.''' 128 Return 0 if all is well, non-zero on any errors.'''
117 129
118 self.ui.status(_('searching %d changesets for largefiles\n') % 130 self.ui.status(
119 len(revs)) 131 _('searching %d changesets for largefiles\n') % len(revs)
120 verified = set() # set of (filename, filenode) tuples 132 )
121 filestocheck = [] # list of (cset, filename, expectedhash) 133 verified = set() # set of (filename, filenode) tuples
134 filestocheck = [] # list of (cset, filename, expectedhash)
122 for rev in revs: 135 for rev in revs:
123 cctx = self.repo[rev] 136 cctx = self.repo[rev]
124 cset = "%d:%s" % (cctx.rev(), node.short(cctx.node())) 137 cset = "%d:%s" % (cctx.rev(), node.short(cctx.node()))
125 138
126 for standin in cctx: 139 for standin in cctx:
138 numrevs = len(verified) 151 numrevs = len(verified)
139 numlfiles = len({fname for (fname, fnode) in verified}) 152 numlfiles = len({fname for (fname, fnode) in verified})
140 if contents: 153 if contents:
141 self.ui.status( 154 self.ui.status(
142 _('verified contents of %d revisions of %d largefiles\n') 155 _('verified contents of %d revisions of %d largefiles\n')
143 % (numrevs, numlfiles)) 156 % (numrevs, numlfiles)
157 )
144 else: 158 else:
145 self.ui.status( 159 self.ui.status(
146 _('verified existence of %d revisions of %d largefiles\n') 160 _('verified existence of %d revisions of %d largefiles\n')
147 % (numrevs, numlfiles)) 161 % (numrevs, numlfiles)
162 )
148 return int(failed) 163 return int(failed)
149 164
150 def _getfile(self, tmpfile, filename, hash): 165 def _getfile(self, tmpfile, filename, hash):
151 '''Fetch one revision of one file from the store and write it 166 '''Fetch one revision of one file from the store and write it
152 to tmpfile. Compute the hash of the file on-the-fly as it 167 to tmpfile. Compute the hash of the file on-the-fly as it