Mercurial > hg
annotate hgext/largefiles/localstore.py @ 17757:fec69c72e2b4
merge with durin42
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 12 Oct 2012 15:52:59 -0500 |
parents | fbb732a8f2b9 |
children | 5206af8894a3 |
rev | line source |
---|---|
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 |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17191
diff
changeset
|
21 Mercurial repository. Failing that, it attempts to grab the files from |
15317
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): | |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
16928
diff
changeset
|
25 url = os.path.join(remote.local().path, '.hg', lfutil.longname) |
15168 | 26 super(localstore, self).__init__(ui, repo, util.expandpath(url)) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
16928
diff
changeset
|
27 self.remote = remote.local() |
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 |
17411
a02e36568e88
largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents:
17191
diff
changeset
|
36 def exists(self, hashes): |
a02e36568e88
largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents:
17191
diff
changeset
|
37 retval = {} |
a02e36568e88
largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents:
17191
diff
changeset
|
38 for hash in hashes: |
a02e36568e88
largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents:
17191
diff
changeset
|
39 retval[hash] = lfutil.instore(self.remote, hash) |
a02e36568e88
largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents:
17191
diff
changeset
|
40 return retval |
a02e36568e88
largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents:
17191
diff
changeset
|
41 |
15168 | 42 |
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 else: |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
49 raise basestore.StoreError(filename, hash, '', |
16928
73b9286e667c
largefiles: lowercase messages
Martin Geisler <mg@aragost.com>
parents:
15371
diff
changeset
|
50 _("can't get file locally")) |
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
51 fd = open(path, 'rb') |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
52 try: |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
53 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
|
54 finally: |
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
55 fd.close() |
15168 | 56 |
57 def _verifyfile(self, cctx, cset, contents, standin, verified): | |
58 filename = lfutil.splitstandin(standin) | |
59 if not filename: | |
60 return False | |
61 fctx = cctx[standin] | |
62 key = (filename, fctx.filenode()) | |
63 if key in verified: | |
64 return False | |
65 | |
66 expecthash = fctx.data()[0:40] | |
67 verified.add(key) | |
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
68 if not lfutil.instore(self.remote, expecthash): |
15168 | 69 self.ui.warn( |
70 _('changeset %s: %s missing\n' | |
71 ' (looked for hash %s)\n') | |
72 % (cset, filename, expecthash)) | |
73 return True # failed | |
74 | |
75 if contents: | |
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
76 storepath = lfutil.storepath(self.remote, expecthash) |
15168 | 77 actualhash = lfutil.hashfile(storepath) |
78 if actualhash != expecthash: | |
79 self.ui.warn( | |
80 _('changeset %s: %s: contents differ\n' | |
81 ' (%s:\n' | |
82 ' expected hash %s,\n' | |
83 ' but got %s)\n') | |
84 % (cset, filename, storepath, expecthash, actualhash)) | |
85 return True # failed | |
86 return False |