author | Augie Fackler <raf@durin42.com> |
Wed, 12 Mar 2014 13:31:27 -0400 | |
changeset 20688 | a61ed1c2d7a7 |
parent 19950 | cce7ab960312 |
child 21084 | 70252bdfd39c |
permissions | -rw-r--r-- |
15168 | 1 |
# Copyright 2010-2011 Fog Creek Software |
2 |
# Copyright 2010-2011 Unity Technologies |
|
3 |
# |
|
4 |
# This software may be used and distributed according to the terms of the |
|
5 |
# GNU General Public License version 2 or any later version. |
|
6 |
||
17425
e95ec38f86b0
fix wording and not-completely-trivial spelling errors and bad docstrings
Mads Kiilerich <mads@kiilerich.com>
parents:
17127
diff
changeset
|
7 |
'''remote largefile store; the base class for wirestore''' |
15168 | 8 |
|
9 |
import urllib2 |
|
10 |
||
11 |
from mercurial import util |
|
12 |
from mercurial.i18n import _ |
|
17127
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15253
diff
changeset
|
13 |
from mercurial.wireproto import remotebatch |
15168 | 14 |
|
15 |
import lfutil |
|
16 |
import basestore |
|
17 |
||
18 |
class remotestore(basestore.basestore): |
|
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15188
diff
changeset
|
19 |
'''a largefile store accessed over a network''' |
15168 | 20 |
def __init__(self, ui, repo, url): |
21 |
super(remotestore, self).__init__(ui, repo, url) |
|
22 |
||
23 |
def put(self, source, hash): |
|
24 |
if self.sendfile(source, hash): |
|
25 |
raise util.Abort( |
|
26 |
_('remotestore: could not put %s to remote store %s') |
|
19950
cce7ab960312
largefiles: hide passwords in URLs in ui messages
Mads Kiilerich <madski@unity3d.com>
parents:
19948
diff
changeset
|
27 |
% (source, util.hidepassword(self.url))) |
15168 | 28 |
self.ui.debug( |
19950
cce7ab960312
largefiles: hide passwords in URLs in ui messages
Mads Kiilerich <madski@unity3d.com>
parents:
19948
diff
changeset
|
29 |
_('remotestore: put %s to remote store %s\n') |
cce7ab960312
largefiles: hide passwords in URLs in ui messages
Mads Kiilerich <madski@unity3d.com>
parents:
19948
diff
changeset
|
30 |
% (source, util.hidepassword(self.url))) |
15168 | 31 |
|
17127
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15253
diff
changeset
|
32 |
def exists(self, hashes): |
20688
a61ed1c2d7a7
check-code: disallow use of dict(key=value) construction
Augie Fackler <raf@durin42.com>
parents:
19950
diff
changeset
|
33 |
return dict((h, s == 0) for (h, s) in # dict-from-generator |
a61ed1c2d7a7
check-code: disallow use of dict(key=value) construction
Augie Fackler <raf@durin42.com>
parents:
19950
diff
changeset
|
34 |
self._stat(hashes).iteritems()) |
15168 | 35 |
|
36 |
def sendfile(self, filename, hash): |
|
37 |
self.ui.debug('remotestore: sendfile(%s, %s)\n' % (filename, hash)) |
|
38 |
fd = None |
|
39 |
try: |
|
40 |
try: |
|
41 |
fd = lfutil.httpsendfile(self.ui, filename) |
|
42 |
except IOError, e: |
|
43 |
raise util.Abort( |
|
44 |
_('remotestore: could not open file %s: %s') |
|
45 |
% (filename, str(e))) |
|
46 |
return self._put(hash, fd) |
|
47 |
finally: |
|
48 |
if fd: |
|
49 |
fd.close() |
|
50 |
||
51 |
def _getfile(self, tmpfile, filename, hash): |
|
52 |
try: |
|
19004
6614e5e24e66
largefiles: move protocol conversion into getlfile and make it an iterable
Mads Kiilerich <madski@unity3d.com>
parents:
19003
diff
changeset
|
53 |
chunks = self._get(hash) |
15188
8e115063950d
largefiles: don't break existing tests (syntax error, bad imports)
Greg Ward <greg@gerg.ca>
parents:
15168
diff
changeset
|
54 |
except urllib2.HTTPError, e: |
15168 | 55 |
# 401s get converted to util.Aborts; everything else is fine being |
56 |
# turned into a StoreError |
|
57 |
raise basestore.StoreError(filename, hash, self.url, str(e)) |
|
58 |
except urllib2.URLError, e: |
|
59 |
# This usually indicates a connection problem, so don't |
|
60 |
# keep trying with the other files... they will probably |
|
61 |
# all fail too. |
|
19950
cce7ab960312
largefiles: hide passwords in URLs in ui messages
Mads Kiilerich <madski@unity3d.com>
parents:
19948
diff
changeset
|
62 |
raise util.Abort('%s: %s' % |
cce7ab960312
largefiles: hide passwords in URLs in ui messages
Mads Kiilerich <madski@unity3d.com>
parents:
19948
diff
changeset
|
63 |
(util.hidepassword(self.url), e.reason)) |
15168 | 64 |
except IOError, e: |
65 |
raise basestore.StoreError(filename, hash, self.url, str(e)) |
|
66 |
||
19004
6614e5e24e66
largefiles: move protocol conversion into getlfile and make it an iterable
Mads Kiilerich <madski@unity3d.com>
parents:
19003
diff
changeset
|
67 |
return lfutil.copyandhash(chunks, tmpfile) |
15168 | 68 |
|
69 |
def _verifyfile(self, cctx, cset, contents, standin, verified): |
|
70 |
filename = lfutil.splitstandin(standin) |
|
71 |
if not filename: |
|
72 |
return False |
|
73 |
fctx = cctx[standin] |
|
74 |
key = (filename, fctx.filenode()) |
|
75 |
if key in verified: |
|
76 |
return False |
|
77 |
||
78 |
verified.add(key) |
|
79 |
||
18482
6f219eb83435
largefiles: adapt verify to batched remote statlfile (issue3780)
Mads Kiilerich <madski@unity3d.com>
parents:
18481
diff
changeset
|
80 |
expecthash = fctx.data()[0:40] |
6f219eb83435
largefiles: adapt verify to batched remote statlfile (issue3780)
Mads Kiilerich <madski@unity3d.com>
parents:
18481
diff
changeset
|
81 |
stat = self._stat([expecthash])[expecthash] |
15168 | 82 |
if not stat: |
83 |
return False |
|
84 |
elif stat == 1: |
|
85 |
self.ui.warn( |
|
86 |
_('changeset %s: %s: contents differ\n') |
|
87 |
% (cset, filename)) |
|
88 |
return True # failed |
|
89 |
elif stat == 2: |
|
90 |
self.ui.warn( |
|
91 |
_('changeset %s: %s missing\n') |
|
92 |
% (cset, filename)) |
|
93 |
return True # failed |
|
94 |
else: |
|
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
95 |
raise RuntimeError('verify failed: unexpected response from ' |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
96 |
'statlfile (%r)' % stat) |
17127
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15253
diff
changeset
|
97 |
|
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15253
diff
changeset
|
98 |
def batch(self): |
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15253
diff
changeset
|
99 |
'''Support for remote batching.''' |
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15253
diff
changeset
|
100 |
return remotebatch(self) |