##// END OF EJS Templates
Separate out old-http support...
mpm@selenic.com -
r1101:2cf5c8a4 default
parent child Browse files
Show More
@@ -0,0 +1,35 b''
1 # statichttprepo.py - simple http repository class for mercurial
2 #
3 # This provides read-only repo access to repositories exported via static http
4 #
5 # Copyright 2005 Matt Mackall <mpm@selenic.com>
6 #
7 # This software may be used and distributed according to the terms
8 # of the GNU General Public License, incorporated herein by reference.
9
10 import os, urllib
11 import localrepo, httprangereader, filelog, manifest, changelog
12
13 def opener(base):
14 """return a function that opens files over http"""
15 p = base
16 def o(path, mode="r"):
17 f = os.path.join(p, urllib.quote(path))
18 return httprangereader.httprangereader(f)
19 return o
20
21 class statichttprepository(localrepo.localrepository):
22 def __init__(self, ui, path):
23 self.path = (path + "/.hg")
24 self.ui = ui
25 self.opener = opener(self.path)
26 self.manifest = manifest.manifest(self.opener)
27 self.changelog = changelog.changelog(self.opener)
28 self.tagscache = None
29 self.nodetagscache = None
30
31 def dev(self):
32 return -1
33
34 def local(self):
35 return False
@@ -9,7 +9,7 b' import util'
9 from node import *
9 from node import *
10 from repo import *
10 from repo import *
11 from demandload import *
11 from demandload import *
12 demandload(globals(), "localrepo httprepo sshrepo")
12 demandload(globals(), "localrepo httprepo sshrepo statichttprepo")
13
13
14 def repository(ui, path=None, create=0):
14 def repository(ui, path=None, create=0):
15 if path:
15 if path:
@@ -21,8 +21,8 b' def repository(ui, path=None, create=0):'
21 return httprepo.httprepository(
21 return httprepo.httprepository(
22 ui, path.replace("hg://", "http://"))
22 ui, path.replace("hg://", "http://"))
23 if path.startswith("old-http://"):
23 if path.startswith("old-http://"):
24 return localrepo.localrepository(
24 return statichttprepo.statichttprepository(
25 ui, util.opener, path.replace("old-http://", "http://"))
25 ui, path.replace("old-http://", "http://"))
26 if path.startswith("ssh://"):
26 if path.startswith("ssh://"):
27 return sshrepo.sshrepository(ui, path)
27 return sshrepo.sshrepository(ui, path)
28
28
@@ -13,22 +13,17 b' demandload(globals(), "re lock transacti'
13
13
14 class localrepository:
14 class localrepository:
15 def __init__(self, ui, opener, path=None, create=0):
15 def __init__(self, ui, opener, path=None, create=0):
16 self.remote = 0
16 if not path:
17 if path and path.startswith("http://"):
17 p = os.getcwd()
18 self.remote = 1
18 while not os.path.isdir(os.path.join(p, ".hg")):
19 self.path = path
19 oldp = p
20 else:
20 p = os.path.dirname(p)
21 if not path:
21 if p == oldp: raise repo.RepoError("no repo found")
22 p = os.getcwd()
22 path = p
23 while not os.path.isdir(os.path.join(p, ".hg")):
23 self.path = os.path.join(path, ".hg")
24 oldp = p
25 p = os.path.dirname(p)
26 if p == oldp: raise repo.RepoError("no repo found")
27 path = p
28 self.path = os.path.join(path, ".hg")
29
24
30 if not create and not os.path.isdir(self.path):
25 if not create and not os.path.isdir(self.path):
31 raise repo.RepoError("repository %s not found" % self.path)
26 raise repo.RepoError("repository %s not found" % self.path)
32
27
33 self.root = os.path.abspath(path)
28 self.root = os.path.abspath(path)
34 self.ui = ui
29 self.ui = ui
@@ -44,11 +39,10 b' class localrepository:'
44 self.tagscache = None
39 self.tagscache = None
45 self.nodetagscache = None
40 self.nodetagscache = None
46
41
47 if not self.remote:
42 self.dirstate = dirstate.dirstate(self.opener, ui, self.root)
48 self.dirstate = dirstate.dirstate(self.opener, ui, self.root)
43 try:
49 try:
44 self.ui.readconfig(self.opener("hgrc"))
50 self.ui.readconfig(self.opener("hgrc"))
45 except IOError: pass
51 except IOError: pass
52
46
53 def hook(self, name, **args):
47 def hook(self, name, **args):
54 s = self.ui.config("hooks", name)
48 s = self.ui.config("hooks", name)
@@ -142,11 +136,10 b' class localrepository:'
142 raise repo.RepoError("unknown revision '%s'" % key)
136 raise repo.RepoError("unknown revision '%s'" % key)
143
137
144 def dev(self):
138 def dev(self):
145 if self.remote: return -1
146 return os.stat(self.path).st_dev
139 return os.stat(self.path).st_dev
147
140
148 def local(self):
141 def local(self):
149 return not self.remote
142 return True
150
143
151 def join(self, f):
144 def join(self, f):
152 return os.path.join(self.path, f)
145 return os.path.join(self.path, f)
@@ -243,10 +243,6 b' def opener(base):'
243 """
243 """
244 p = base
244 p = base
245 def o(path, mode="r"):
245 def o(path, mode="r"):
246 if p.startswith("http://"):
247 f = os.path.join(p, urllib.quote(path))
248 return httprangereader.httprangereader(f)
249
250 f = os.path.join(p, path)
246 f = os.path.join(p, path)
251
247
252 mode += "b" # for that other OS
248 mode += "b" # for that other OS
General Comments 0
You need to be logged in to leave comments. Login now