author | Dan Villiom Podlaski Christiansen <dan@cabo.dk> |
Mon, 18 Jun 2012 11:16:24 +0200 | |
branch | stable |
changeset 17026 | f8af57c00a29 |
parent 15371 | f26ed4ea46d8 |
child 16928 | 73b9286e667c |
permissions | -rw-r--r-- |
15168 | 1 |
# Copyright 2009-2010 Gregory P. Ward |
2 |
# Copyright 2009-2010 Intelerad Medical Systems Incorporated |
|
3 |
# Copyright 2010-2011 Fog Creek Software |
|
4 |
# Copyright 2010-2011 Unity Technologies |
|
5 |
# |
|
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. |
|
8 |
||
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15168
diff
changeset
|
9 |
'''store class for local filesystem''' |
15168 | 10 |
|
11 |
import os |
|
12 |
||
13 |
from mercurial import util |
|
14 |
from mercurial.i18n import _ |
|
15 |
||
16 |
import lfutil |
|
17 |
import basestore |
|
18 |
||
19 |
class localstore(basestore.basestore): |
|
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
20 |
'''localstore first attempts to grab files out of the store in the remote |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
21 |
Mercurial repository. Failling that, it attempts to grab the files from |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
22 |
the user cache.''' |
15168 | 23 |
|
24 |
def __init__(self, ui, repo, remote): |
|
25 |
url = os.path.join(remote.path, '.hg', lfutil.longname) |
|
26 |
super(localstore, self).__init__(ui, repo, util.expandpath(url)) |
|
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
27 |
self.remote = remote |
15168 | 28 |
|
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
29 |
def put(self, source, hash): |
15371
f26ed4ea46d8
largefiles: remove lfutil.createdir, replace calls with util.makedirs
Hao Lian <hao@fogcreek.com>
parents:
15317
diff
changeset
|
30 |
util.makedirs(os.path.dirname(lfutil.storepath(self.remote, hash))) |
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
31 |
if lfutil.instore(self.remote, hash): |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
32 |
return |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
33 |
lfutil.link(lfutil.storepath(self.repo, hash), |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
34 |
lfutil.storepath(self.remote, hash)) |
15168 | 35 |
|
36 |
def exists(self, hash): |
|
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
37 |
return lfutil.instore(self.remote, hash) |
15168 | 38 |
|
39 |
def _getfile(self, tmpfile, filename, hash): |
|
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
40 |
if lfutil.instore(self.remote, hash): |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
41 |
path = lfutil.storepath(self.remote, hash) |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
42 |
elif lfutil.inusercache(self.ui, hash): |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
43 |
path = lfutil.usercachepath(self.ui, hash) |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
44 |
else: |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
45 |
raise basestore.StoreError(filename, hash, '', |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
46 |
_("Can't get file locally")) |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
47 |
fd = open(path, 'rb') |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
48 |
try: |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
49 |
return lfutil.copyandhash(fd, tmpfile) |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
50 |
finally: |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
51 |
fd.close() |
15168 | 52 |
|
53 |
def _verifyfile(self, cctx, cset, contents, standin, verified): |
|
54 |
filename = lfutil.splitstandin(standin) |
|
55 |
if not filename: |
|
56 |
return False |
|
57 |
fctx = cctx[standin] |
|
58 |
key = (filename, fctx.filenode()) |
|
59 |
if key in verified: |
|
60 |
return False |
|
61 |
||
62 |
expecthash = fctx.data()[0:40] |
|
63 |
verified.add(key) |
|
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
64 |
if not lfutil.instore(self.remote, expecthash): |
15168 | 65 |
self.ui.warn( |
66 |
_('changeset %s: %s missing\n' |
|
67 |
' (looked for hash %s)\n') |
|
68 |
% (cset, filename, expecthash)) |
|
69 |
return True # failed |
|
70 |
||
71 |
if contents: |
|
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
72 |
storepath = lfutil.storepath(self.remote, expecthash) |
15168 | 73 |
actualhash = lfutil.hashfile(storepath) |
74 |
if actualhash != expecthash: |
|
75 |
self.ui.warn( |
|
76 |
_('changeset %s: %s: contents differ\n' |
|
77 |
' (%s:\n' |
|
78 |
' expected hash %s,\n' |
|
79 |
' but got %s)\n') |
|
80 |
% (cset, filename, storepath, expecthash, actualhash)) |
|
81 |
return True # failed |
|
82 |
return False |