15 |
15 |
16 import lfutil |
16 import lfutil |
17 import basestore |
17 import basestore |
18 |
18 |
19 class localstore(basestore.basestore): |
19 class localstore(basestore.basestore): |
20 '''Because there is a system-wide cache, the local store always |
20 '''localstore first attempts to grab files out of the store in the remote |
21 uses that cache. Since the cache is updated elsewhere, we can |
21 Mercurial repository. Failling that, it attempts to grab the files from |
22 just read from it here as if it were the store.''' |
22 the user cache.''' |
23 |
23 |
24 def __init__(self, ui, repo, remote): |
24 def __init__(self, ui, repo, remote): |
25 url = os.path.join(remote.path, '.hg', lfutil.longname) |
25 url = os.path.join(remote.path, '.hg', lfutil.longname) |
26 super(localstore, self).__init__(ui, repo, util.expandpath(url)) |
26 super(localstore, self).__init__(ui, repo, util.expandpath(url)) |
|
27 self.remote = remote |
27 |
28 |
28 def put(self, source, filename, hash): |
29 def put(self, source, hash): |
29 '''Any file that is put must already be in the system-wide |
30 lfutil.createdir(os.path.dirname(lfutil.storepath(self.remote, hash))) |
30 cache so do nothing.''' |
31 if lfutil.instore(self.remote, hash): |
31 return |
32 return |
|
33 lfutil.link(lfutil.storepath(self.repo, hash), |
|
34 lfutil.storepath(self.remote, hash)) |
32 |
35 |
33 def exists(self, hash): |
36 def exists(self, hash): |
34 return lfutil.inusercache(self.repo.ui, hash) |
37 return lfutil.instore(self.remote, hash) |
35 |
38 |
36 def _getfile(self, tmpfile, filename, hash): |
39 def _getfile(self, tmpfile, filename, hash): |
37 if lfutil.inusercache(self.ui, hash): |
40 if lfutil.instore(self.remote, hash): |
38 return lfutil.usercachepath(self.ui, hash) |
41 path = lfutil.storepath(self.remote, hash) |
39 raise basestore.StoreError(filename, hash, '', |
42 elif lfutil.inusercache(self.ui, hash): |
40 _("Can't get file locally")) |
43 path = lfutil.usercachepath(self.ui, hash) |
|
44 else: |
|
45 raise basestore.StoreError(filename, hash, '', |
|
46 _("Can't get file locally")) |
|
47 fd = open(path, 'rb') |
|
48 try: |
|
49 return lfutil.copyandhash(fd, tmpfile) |
|
50 finally: |
|
51 fd.close() |
41 |
52 |
42 def _verifyfile(self, cctx, cset, contents, standin, verified): |
53 def _verifyfile(self, cctx, cset, contents, standin, verified): |
43 filename = lfutil.splitstandin(standin) |
54 filename = lfutil.splitstandin(standin) |
44 if not filename: |
55 if not filename: |
45 return False |
56 return False |
48 if key in verified: |
59 if key in verified: |
49 return False |
60 return False |
50 |
61 |
51 expecthash = fctx.data()[0:40] |
62 expecthash = fctx.data()[0:40] |
52 verified.add(key) |
63 verified.add(key) |
53 if not lfutil.inusercache(self.ui, expecthash): |
64 if not lfutil.instore(self.remote, expecthash): |
54 self.ui.warn( |
65 self.ui.warn( |
55 _('changeset %s: %s missing\n' |
66 _('changeset %s: %s missing\n' |
56 ' (looked for hash %s)\n') |
67 ' (looked for hash %s)\n') |
57 % (cset, filename, expecthash)) |
68 % (cset, filename, expecthash)) |
58 return True # failed |
69 return True # failed |
59 |
70 |
60 if contents: |
71 if contents: |
61 storepath = lfutil.usercachepath(self.ui, expecthash) |
72 storepath = lfutil.storepath(self.remote, expecthash) |
62 actualhash = lfutil.hashfile(storepath) |
73 actualhash = lfutil.hashfile(storepath) |
63 if actualhash != expecthash: |
74 if actualhash != expecthash: |
64 self.ui.warn( |
75 self.ui.warn( |
65 _('changeset %s: %s: contents differ\n' |
76 _('changeset %s: %s: contents differ\n' |
66 ' (%s:\n' |
77 ' (%s:\n' |