localstore.py
73 lines
| 2.4 KiB
| text/x-python
|
PythonLexer
various
|
r15168 | # Copyright 2009-2010 Gregory P. Ward | ||
# Copyright 2009-2010 Intelerad Medical Systems Incorporated | ||||
# Copyright 2010-2011 Fog Creek Software | ||||
# Copyright 2010-2011 Unity Technologies | ||||
# | ||||
# This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | ||||
Greg Ward
|
r15252 | '''store class for local filesystem''' | ||
various
|
r15168 | |||
from mercurial.i18n import _ | ||||
import lfutil | ||||
import basestore | ||||
class localstore(basestore.basestore): | ||||
Benjamin Pollack
|
r15317 | '''localstore first attempts to grab files out of the store in the remote | ||
Mads Kiilerich
|
r17424 | Mercurial repository. Failing that, it attempts to grab the files from | ||
Benjamin Pollack
|
r15317 | the user cache.''' | ||
various
|
r15168 | |||
def __init__(self, ui, repo, remote): | ||||
Sune Foldager
|
r17191 | self.remote = remote.local() | ||
Mads Kiilerich
|
r18155 | super(localstore, self).__init__(ui, repo, self.remote.url()) | ||
various
|
r15168 | |||
Benjamin Pollack
|
r15317 | def put(self, source, hash): | ||
if lfutil.instore(self.remote, hash): | ||||
return | ||||
Mads Kiilerich
|
r19007 | lfutil.link(source, lfutil.storepath(self.remote, hash)) | ||
various
|
r15168 | |||
Matt Harbison
|
r17411 | def exists(self, hashes): | ||
retval = {} | ||||
for hash in hashes: | ||||
retval[hash] = lfutil.instore(self.remote, hash) | ||||
return retval | ||||
various
|
r15168 | |||
def _getfile(self, tmpfile, filename, hash): | ||||
Mads Kiilerich
|
r19000 | path = lfutil.findfile(self.remote, hash) | ||
if not path: | ||||
Mads Kiilerich
|
r18155 | raise basestore.StoreError(filename, hash, self.url, | ||
Martin Geisler
|
r16928 | _("can't get file locally")) | ||
Benjamin Pollack
|
r15317 | fd = open(path, 'rb') | ||
try: | ||||
return lfutil.copyandhash(fd, tmpfile) | ||||
finally: | ||||
fd.close() | ||||
various
|
r15168 | |||
def _verifyfile(self, cctx, cset, contents, standin, verified): | ||||
filename = lfutil.splitstandin(standin) | ||||
if not filename: | ||||
return False | ||||
fctx = cctx[standin] | ||||
key = (filename, fctx.filenode()) | ||||
if key in verified: | ||||
return False | ||||
expecthash = fctx.data()[0:40] | ||||
Mads Kiilerich
|
r18545 | storepath = lfutil.storepath(self.remote, expecthash) | ||
various
|
r15168 | verified.add(key) | ||
Benjamin Pollack
|
r15317 | if not lfutil.instore(self.remote, expecthash): | ||
various
|
r15168 | self.ui.warn( | ||
Mads Kiilerich
|
r18545 | _('changeset %s: %s references missing %s\n') | ||
% (cset, filename, storepath)) | ||||
various
|
r15168 | return True # failed | ||
if contents: | ||||
actualhash = lfutil.hashfile(storepath) | ||||
if actualhash != expecthash: | ||||
self.ui.warn( | ||||
Mads Kiilerich
|
r18545 | _('changeset %s: %s references corrupted %s\n') | ||
% (cset, filename, storepath)) | ||||
various
|
r15168 | return True # failed | ||
return False | ||||