Show More
@@ -1,83 +1,90 b'' | |||
|
1 | 1 | # statichttprepo.py - simple http repository class for mercurial |
|
2 | 2 | # |
|
3 | 3 | # This provides read-only repo access to repositories exported via static http |
|
4 | 4 | # |
|
5 | 5 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
6 | 6 | # |
|
7 | 7 | # This software may be used and distributed according to the terms |
|
8 | 8 | # of the GNU General Public License, incorporated herein by reference. |
|
9 | 9 | |
|
10 | 10 | from i18n import _ |
|
11 | 11 | import changelog, httprangereader |
|
12 | 12 | import repo, localrepo, manifest, util, store |
|
13 | 13 | import urllib, urllib2, errno |
|
14 | 14 | |
|
15 | 15 | class rangereader(httprangereader.httprangereader): |
|
16 | 16 | def read(self, size=None): |
|
17 | 17 | try: |
|
18 | 18 | return httprangereader.httprangereader.read(self, size) |
|
19 | 19 | except urllib2.HTTPError, inst: |
|
20 | 20 | num = inst.code == 404 and errno.ENOENT or None |
|
21 | 21 | raise IOError(num, inst) |
|
22 | 22 | except urllib2.URLError, inst: |
|
23 | 23 | raise IOError(None, inst.reason[1]) |
|
24 | 24 | |
|
25 | 25 | def opener(base): |
|
26 | 26 | """return a function that opens files over http""" |
|
27 | 27 | p = base |
|
28 | 28 | def o(path, mode="r"): |
|
29 | 29 | f = "/".join((p, urllib.quote(path))) |
|
30 | 30 | return rangereader(f) |
|
31 | 31 | return o |
|
32 | 32 | |
|
33 | 33 | class statichttprepository(localrepo.localrepository): |
|
34 | 34 | def __init__(self, ui, path): |
|
35 | 35 | self._url = path |
|
36 | 36 | self.ui = ui |
|
37 | 37 | |
|
38 | 38 | self.path = path.rstrip('/') + "/.hg" |
|
39 | 39 | self.opener = opener(self.path) |
|
40 | 40 | |
|
41 | 41 | # find requirements |
|
42 | 42 | try: |
|
43 | 43 | requirements = self.opener("requires").read().splitlines() |
|
44 | 44 | except IOError, inst: |
|
45 |
if inst.errno |
|
|
45 | if inst.errno != errno.ENOENT: | |
|
46 | raise | |
|
47 | # check if it is a non-empty old-style repository | |
|
48 | try: | |
|
49 | self.opener("00changelog.i").read(1) | |
|
50 | except IOError, inst: | |
|
51 | if inst.errno != errno.ENOENT: | |
|
52 | raise | |
|
53 | # we do not care about empty old-style repositories here | |
|
46 | 54 | msg = _("'%s' does not appear to be an hg repository") % path |
|
47 | 55 | raise repo.RepoError(msg) |
|
48 |
|
|
|
49 | requirements = [] | |
|
56 | requirements = [] | |
|
50 | 57 | |
|
51 | 58 | # check them |
|
52 | 59 | for r in requirements: |
|
53 | 60 | if r not in self.supported: |
|
54 | 61 | raise repo.RepoError(_("requirement '%s' not supported") % r) |
|
55 | 62 | |
|
56 | 63 | # setup store |
|
57 | 64 | def pjoin(a, b): |
|
58 | 65 | return a + '/' + b |
|
59 | 66 | self.store = store.store(requirements, self.path, opener, pjoin) |
|
60 | 67 | self.spath = self.store.path |
|
61 | 68 | self.sopener = self.store.opener |
|
62 | 69 | self.sjoin = self.store.join |
|
63 | 70 | |
|
64 | 71 | self.manifest = manifest.manifest(self.sopener) |
|
65 | 72 | self.changelog = changelog.changelog(self.sopener) |
|
66 | 73 | self.tagscache = None |
|
67 | 74 | self.nodetagscache = None |
|
68 | 75 | self.encodepats = None |
|
69 | 76 | self.decodepats = None |
|
70 | 77 | |
|
71 | 78 | def url(self): |
|
72 | 79 | return 'static-' + self._url |
|
73 | 80 | |
|
74 | 81 | def local(self): |
|
75 | 82 | return False |
|
76 | 83 | |
|
77 | 84 | def lock(self, wait=True): |
|
78 | 85 | raise util.Abort(_('cannot lock static-http repository')) |
|
79 | 86 | |
|
80 | 87 | def instance(ui, path, create): |
|
81 | 88 | if create: |
|
82 | 89 | raise util.Abort(_('cannot create new static-http repository')) |
|
83 | 90 | return statichttprepository(ui, path[7:]) |
General Comments 0
You need to be logged in to leave comments.
Login now