##// END OF EJS Templates
use forward "/" for internal path and static http, fix issue437
Benoit Boissinot -
r3794:630caaf2 default
parent child Browse files
Show More
@@ -1,86 +1,86 b''
1 1 # filelog.py - file history class for mercurial
2 2 #
3 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from revlog import *
9 9 from demandload import *
10 10 demandload(globals(), "os")
11 11
12 12 class filelog(revlog):
13 13 def __init__(self, opener, path, defversion=REVLOG_DEFAULT_VERSION):
14 14 revlog.__init__(self, opener,
15 os.path.join("data", self.encodedir(path + ".i")),
16 os.path.join("data", self.encodedir(path + ".d")),
15 "/".join(("data", self.encodedir(path + ".i"))),
16 "/".join(("data", self.encodedir(path + ".d"))),
17 17 defversion)
18 18
19 19 # This avoids a collision between a file named foo and a dir named
20 20 # foo.i or foo.d
21 21 def encodedir(self, path):
22 22 return (path
23 23 .replace(".hg/", ".hg.hg/")
24 24 .replace(".i/", ".i.hg/")
25 25 .replace(".d/", ".d.hg/"))
26 26
27 27 def decodedir(self, path):
28 28 return (path
29 29 .replace(".d.hg/", ".d/")
30 30 .replace(".i.hg/", ".i/")
31 31 .replace(".hg.hg/", ".hg/"))
32 32
33 33 def read(self, node):
34 34 t = self.revision(node)
35 35 if not t.startswith('\1\n'):
36 36 return t
37 37 s = t.index('\1\n', 2)
38 38 return t[s+2:]
39 39
40 40 def _readmeta(self, node):
41 41 t = self.revision(node)
42 42 if not t.startswith('\1\n'):
43 43 return {}
44 44 s = t.index('\1\n', 2)
45 45 mt = t[2:s]
46 46 m = {}
47 47 for l in mt.splitlines():
48 48 k, v = l.split(": ", 1)
49 49 m[k] = v
50 50 return m
51 51
52 52 def add(self, text, meta, transaction, link, p1=None, p2=None):
53 53 if meta or text.startswith('\1\n'):
54 54 mt = ""
55 55 if meta:
56 56 mt = [ "%s: %s\n" % (k, v) for k,v in meta.items() ]
57 57 text = "\1\n%s\1\n%s" % ("".join(mt), text)
58 58 return self.addrevision(text, transaction, link, p1, p2)
59 59
60 60 def renamed(self, node):
61 61 if self.parents(node)[0] != nullid:
62 62 return False
63 63 m = self._readmeta(node)
64 64 if m and m.has_key("copy"):
65 65 return (m["copy"], bin(m["copyrev"]))
66 66 return False
67 67
68 68 def size(self, rev):
69 69 """return the size of a given revision"""
70 70
71 71 # for revisions with renames, we have to go the slow way
72 72 node = self.node(rev)
73 73 if self.renamed(node):
74 74 return len(self.read(node))
75 75
76 76 return revlog.size(self, rev)
77 77
78 78 def cmp(self, node, text):
79 79 """compare text with a given file revision"""
80 80
81 81 # for renames, we have to go the slow way
82 82 if self.renamed(node):
83 83 t2 = self.read(node)
84 84 return t2 != text
85 85
86 86 return revlog.cmp(self, node, text)
@@ -1,66 +1,66 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, 2006 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 demandload import *
11 11 from i18n import gettext as _
12 12 demandload(globals(), "changelog filelog httprangereader")
13 13 demandload(globals(), "localrepo manifest os urllib urllib2 util")
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 raise IOError(None, inst)
21 21 except urllib2.URLError, inst:
22 22 raise IOError(None, inst.reason[1])
23 23
24 24 def opener(base):
25 25 """return a function that opens files over http"""
26 26 p = base
27 27 def o(path, mode="r"):
28 f = os.path.join(p, urllib.quote(path))
28 f = "/".join((p, urllib.quote(path)))
29 29 return rangereader(f)
30 30 return o
31 31
32 32 class statichttprepository(localrepo.localrepository):
33 33 def __init__(self, ui, path):
34 34 self._url = path
35 35 self.path = (path + "/.hg")
36 36 self.spath = self.path
37 37 self.ui = ui
38 38 self.revlogversion = 0
39 39 self.opener = opener(self.path)
40 40 self.sopener = opener(self.spath)
41 41 self.manifest = manifest.manifest(self.sopener)
42 42 self.changelog = changelog.changelog(self.sopener)
43 43 self.tagscache = None
44 44 self.nodetagscache = None
45 45 self.encodepats = None
46 46 self.decodepats = None
47 47
48 48 def url(self):
49 49 return 'static-' + self._url
50 50
51 51 def dev(self):
52 52 return -1
53 53
54 54 def local(self):
55 55 return False
56 56
57 57 def instance(ui, path, create):
58 58 if create:
59 59 raise util.Abort(_('cannot create new static-http repository'))
60 60 if path.startswith('old-http:'):
61 61 ui.warn(_("old-http:// syntax is deprecated, "
62 62 "please use static-http:// instead\n"))
63 63 path = path[4:]
64 64 else:
65 65 path = path[7:]
66 66 return statichttprepository(ui, path)
General Comments 0
You need to be logged in to leave comments. Login now