Mercurial > hg
annotate hgext/largefiles/remotestore.py @ 15388:eb6c0d47c3d5 stable
setup: set whole env for running hg even if .hg doesn't exist (issue3073)
The issue was partially fixed by b357a972d6cd, but there were missing
variables to run build_hgextindex.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 31 Oct 2011 00:42:32 +0900 |
parents | 67d010779907 |
children | 9e1616307c4c |
rev | line source |
---|---|
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 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15188
diff
changeset
|
7 '''remote largefile store; the base class for servestore''' |
15168 | 8 |
9 import urllib2 | |
10 | |
11 from mercurial import util | |
12 from mercurial.i18n import _ | |
13 | |
14 import lfutil | |
15 import basestore | |
16 | |
17 class remotestore(basestore.basestore): | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15188
diff
changeset
|
18 '''a largefile store accessed over a network''' |
15168 | 19 def __init__(self, ui, repo, url): |
20 super(remotestore, self).__init__(ui, repo, url) | |
21 | |
22 def put(self, source, hash): | |
23 if self._verify(hash): | |
24 return | |
25 if self.sendfile(source, hash): | |
26 raise util.Abort( | |
27 _('remotestore: could not put %s to remote store %s') | |
28 % (source, self.url)) | |
29 self.ui.debug( | |
30 _('remotestore: put %s to remote store %s') % (source, self.url)) | |
31 | |
32 def exists(self, hash): | |
33 return self._verify(hash) | |
34 | |
35 def sendfile(self, filename, hash): | |
36 self.ui.debug('remotestore: sendfile(%s, %s)\n' % (filename, hash)) | |
37 fd = None | |
38 try: | |
39 try: | |
40 fd = lfutil.httpsendfile(self.ui, filename) | |
41 except IOError, e: | |
42 raise util.Abort( | |
43 _('remotestore: could not open file %s: %s') | |
44 % (filename, str(e))) | |
45 return self._put(hash, fd) | |
46 finally: | |
47 if fd: | |
48 fd.close() | |
49 | |
50 def _getfile(self, tmpfile, filename, hash): | |
51 # quit if the largefile isn't there | |
52 stat = self._stat(hash) | |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
53 if stat == 1: |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
54 raise util.Abort(_('remotestore: largefile %s is invalid') % hash) |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
55 elif stat == 2: |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
56 raise util.Abort(_('remotestore: largefile %s is missing') % hash) |
15168 | 57 |
58 try: | |
59 length, infile = self._get(hash) | |
15188
8e115063950d
largefiles: don't break existing tests (syntax error, bad imports)
Greg Ward <greg@gerg.ca>
parents:
15168
diff
changeset
|
60 except urllib2.HTTPError, e: |
15168 | 61 # 401s get converted to util.Aborts; everything else is fine being |
62 # turned into a StoreError | |
63 raise basestore.StoreError(filename, hash, self.url, str(e)) | |
64 except urllib2.URLError, e: | |
65 # This usually indicates a connection problem, so don't | |
66 # keep trying with the other files... they will probably | |
67 # all fail too. | |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
68 raise util.Abort('%s: %s' % (self.url, e.reason)) |
15168 | 69 except IOError, e: |
70 raise basestore.StoreError(filename, hash, self.url, str(e)) | |
71 | |
72 # Mercurial does not close its SSH connections after writing a stream | |
73 if length is not None: | |
74 infile = lfutil.limitreader(infile, length) | |
75 return lfutil.copyandhash(lfutil.blockstream(infile), tmpfile) | |
76 | |
77 def _verify(self, hash): | |
78 return not self._stat(hash) | |
79 | |
80 def _verifyfile(self, cctx, cset, contents, standin, verified): | |
81 filename = lfutil.splitstandin(standin) | |
82 if not filename: | |
83 return False | |
84 fctx = cctx[standin] | |
85 key = (filename, fctx.filenode()) | |
86 if key in verified: | |
87 return False | |
88 | |
89 verified.add(key) | |
90 | |
91 stat = self._stat(hash) | |
92 if not stat: | |
93 return False | |
94 elif stat == 1: | |
95 self.ui.warn( | |
96 _('changeset %s: %s: contents differ\n') | |
97 % (cset, filename)) | |
98 return True # failed | |
99 elif stat == 2: | |
100 self.ui.warn( | |
101 _('changeset %s: %s missing\n') | |
102 % (cset, filename)) | |
103 return True # failed | |
104 else: | |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
105 raise RuntimeError('verify failed: unexpected response from ' |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
106 'statlfile (%r)' % stat) |