Show More
@@ -1,82 +1,82 | |||||
1 | # Copyright 2009-2010 Gregory P. Ward |
|
1 | # Copyright 2009-2010 Gregory P. Ward | |
2 | # Copyright 2009-2010 Intelerad Medical Systems Incorporated |
|
2 | # Copyright 2009-2010 Intelerad Medical Systems Incorporated | |
3 | # Copyright 2010-2011 Fog Creek Software |
|
3 | # Copyright 2010-2011 Fog Creek Software | |
4 | # Copyright 2010-2011 Unity Technologies |
|
4 | # Copyright 2010-2011 Unity Technologies | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 | '''store class for local filesystem''' |
|
9 | '''store class for local filesystem''' | |
10 |
|
10 | |||
11 | import os |
|
11 | import os | |
12 |
|
12 | |||
13 | from mercurial import util |
|
13 | from mercurial import util | |
14 | from mercurial.i18n import _ |
|
14 | from mercurial.i18n import _ | |
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 | '''localstore first attempts to grab files out of the store in the remote |
|
20 | '''localstore first attempts to grab files out of the store in the remote | |
21 |
Mercurial repository. Fail |
|
21 | Mercurial repository. Failing that, it attempts to grab the files from | |
22 | the user cache.''' |
|
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.local().path, '.hg', lfutil.longname) |
|
25 | url = os.path.join(remote.local().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.local() |
|
27 | self.remote = remote.local() | |
28 |
|
28 | |||
29 | def put(self, source, hash): |
|
29 | def put(self, source, hash): | |
30 | util.makedirs(os.path.dirname(lfutil.storepath(self.remote, hash))) |
|
30 | util.makedirs(os.path.dirname(lfutil.storepath(self.remote, hash))) | |
31 | if lfutil.instore(self.remote, hash): |
|
31 | if lfutil.instore(self.remote, hash): | |
32 | return |
|
32 | return | |
33 | lfutil.link(lfutil.storepath(self.repo, hash), |
|
33 | lfutil.link(lfutil.storepath(self.repo, hash), | |
34 | lfutil.storepath(self.remote, hash)) |
|
34 | lfutil.storepath(self.remote, hash)) | |
35 |
|
35 | |||
36 | def exists(self, hash): |
|
36 | def exists(self, hash): | |
37 | return lfutil.instore(self.remote, hash) |
|
37 | return lfutil.instore(self.remote, hash) | |
38 |
|
38 | |||
39 | def _getfile(self, tmpfile, filename, hash): |
|
39 | def _getfile(self, tmpfile, filename, hash): | |
40 | if lfutil.instore(self.remote, hash): |
|
40 | if lfutil.instore(self.remote, hash): | |
41 | path = lfutil.storepath(self.remote, hash) |
|
41 | path = lfutil.storepath(self.remote, hash) | |
42 | elif lfutil.inusercache(self.ui, hash): |
|
42 | elif lfutil.inusercache(self.ui, hash): | |
43 | path = lfutil.usercachepath(self.ui, hash) |
|
43 | path = lfutil.usercachepath(self.ui, hash) | |
44 | else: |
|
44 | else: | |
45 | raise basestore.StoreError(filename, hash, '', |
|
45 | raise basestore.StoreError(filename, hash, '', | |
46 | _("can't get file locally")) |
|
46 | _("can't get file locally")) | |
47 | fd = open(path, 'rb') |
|
47 | fd = open(path, 'rb') | |
48 | try: |
|
48 | try: | |
49 | return lfutil.copyandhash(fd, tmpfile) |
|
49 | return lfutil.copyandhash(fd, tmpfile) | |
50 | finally: |
|
50 | finally: | |
51 | fd.close() |
|
51 | fd.close() | |
52 |
|
52 | |||
53 | def _verifyfile(self, cctx, cset, contents, standin, verified): |
|
53 | def _verifyfile(self, cctx, cset, contents, standin, verified): | |
54 | filename = lfutil.splitstandin(standin) |
|
54 | filename = lfutil.splitstandin(standin) | |
55 | if not filename: |
|
55 | if not filename: | |
56 | return False |
|
56 | return False | |
57 | fctx = cctx[standin] |
|
57 | fctx = cctx[standin] | |
58 | key = (filename, fctx.filenode()) |
|
58 | key = (filename, fctx.filenode()) | |
59 | if key in verified: |
|
59 | if key in verified: | |
60 | return False |
|
60 | return False | |
61 |
|
61 | |||
62 | expecthash = fctx.data()[0:40] |
|
62 | expecthash = fctx.data()[0:40] | |
63 | verified.add(key) |
|
63 | verified.add(key) | |
64 | if not lfutil.instore(self.remote, expecthash): |
|
64 | if not lfutil.instore(self.remote, expecthash): | |
65 | self.ui.warn( |
|
65 | self.ui.warn( | |
66 | _('changeset %s: %s missing\n' |
|
66 | _('changeset %s: %s missing\n' | |
67 | ' (looked for hash %s)\n') |
|
67 | ' (looked for hash %s)\n') | |
68 | % (cset, filename, expecthash)) |
|
68 | % (cset, filename, expecthash)) | |
69 | return True # failed |
|
69 | return True # failed | |
70 |
|
70 | |||
71 | if contents: |
|
71 | if contents: | |
72 | storepath = lfutil.storepath(self.remote, expecthash) |
|
72 | storepath = lfutil.storepath(self.remote, expecthash) | |
73 | actualhash = lfutil.hashfile(storepath) |
|
73 | actualhash = lfutil.hashfile(storepath) | |
74 | if actualhash != expecthash: |
|
74 | if actualhash != expecthash: | |
75 | self.ui.warn( |
|
75 | self.ui.warn( | |
76 | _('changeset %s: %s: contents differ\n' |
|
76 | _('changeset %s: %s: contents differ\n' | |
77 | ' (%s:\n' |
|
77 | ' (%s:\n' | |
78 | ' expected hash %s,\n' |
|
78 | ' expected hash %s,\n' | |
79 | ' but got %s)\n') |
|
79 | ' but got %s)\n') | |
80 | % (cset, filename, storepath, expecthash, actualhash)) |
|
80 | % (cset, filename, storepath, expecthash, actualhash)) | |
81 | return True # failed |
|
81 | return True # failed | |
82 | return False |
|
82 | return False |
General Comments 0
You need to be logged in to leave comments.
Login now