##// END OF EJS Templates
do not pretend to lock static-http repositories (issue994)
Martin Geisler -
r7005:7739b618 default
parent child Browse files
Show More
@@ -1,80 +1,83
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 45 if inst.errno == errno.ENOENT:
46 46 msg = _("'%s' does not appear to be an hg repository") % path
47 47 raise repo.RepoError(msg)
48 48 else:
49 49 requirements = []
50 50
51 51 # check them
52 52 for r in requirements:
53 53 if r not in self.supported:
54 54 raise repo.RepoError(_("requirement '%s' not supported") % r)
55 55
56 56 # setup store
57 57 def pjoin(a, b):
58 58 return a + '/' + b
59 59 self.store = store.store(requirements, self.path, opener, pjoin)
60 60 self.spath = self.store.path
61 61 self.sopener = self.store.opener
62 62 self.sjoin = self.store.join
63 63
64 64 self.manifest = manifest.manifest(self.sopener)
65 65 self.changelog = changelog.changelog(self.sopener)
66 66 self.tagscache = None
67 67 self.nodetagscache = None
68 68 self.encodepats = None
69 69 self.decodepats = None
70 70
71 71 def url(self):
72 72 return 'static-' + self._url
73 73
74 74 def local(self):
75 75 return False
76 76
77 def lock(self, wait=True):
78 raise util.Abort(_('cannot lock static-http repository'))
79
77 80 def instance(ui, path, create):
78 81 if create:
79 82 raise util.Abort(_('cannot create new static-http repository'))
80 83 return statichttprepository(ui, path[7:])
@@ -1,81 +1,87
1 1 #!/bin/sh
2 2
3 3 cp "$TESTDIR"/printenv.py .
4 4
5 5 http_proxy= hg clone static-http://localhost:$HGPORT/ copy
6 6 echo $?
7 7 test -d copy || echo copy: No such file or directory
8 8
9 9 # This server doesn't do range requests so it's basically only good for
10 10 # one pull
11 11 cat > dumb.py <<EOF
12 12 import BaseHTTPServer, SimpleHTTPServer, os, signal
13 13
14 14 def run(server_class=BaseHTTPServer.HTTPServer,
15 15 handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler):
16 16 server_address = ('localhost', int(os.environ['HGPORT']))
17 17 httpd = server_class(server_address, handler_class)
18 18 httpd.serve_forever()
19 19
20 20 signal.signal(signal.SIGTERM, lambda x: sys.exit(0))
21 21 run()
22 22 EOF
23 23
24 24 python dumb.py 2>/dev/null &
25 25 echo $! >> $DAEMON_PIDS
26 26
27 27 mkdir remote
28 28 cd remote
29 29 hg init
30 30 echo foo > bar
31 31 hg add bar
32 32 hg commit -m"test" -d "1000000 0"
33 33 hg tip
34 34
35 35 cd ..
36 36
37 37 http_proxy= hg clone static-http://localhost:$HGPORT/remote local | sed -e 's,:[0-9][0-9]*/,/,'
38 38
39 39 cd local
40 40 hg verify
41 41 cat bar
42 42
43 43 cd ../remote
44 44 echo baz > quux
45 45 hg commit -A -mtest2 -d '100000000 0'
46 46
47 47 cd ../local
48 48 echo '[hooks]' >> .hg/hgrc
49 49 echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
50 50 http_proxy= hg pull | sed -e 's,:[0-9][0-9]*/,/,'
51 51
52 echo '% trying to push'
53 hg update
54 echo more foo >> bar
55 hg commit -m"test" -d "100000000 0"
56 http_proxy= hg push | sed -e 's,:[0-9][0-9]*/,/,'
57
52 58 echo '% test with "/" URI (issue 747)'
53 59 cd ..
54 60 hg init
55 61 echo a > a
56 62 hg add a
57 63 hg ci -ma
58 64
59 65 http_proxy= hg clone static-http://localhost:$HGPORT/ local2 | sed -e 's,:[0-9][0-9]*/,/,'
60 66
61 67 cd local2
62 68 hg verify
63 69 cat a
64 70 hg paths | sed -e 's,:[0-9][0-9]*/,/,'
65 71
66 72 echo '% test with empty repo (issue965)'
67 73 cd ..
68 74 hg init remotempty
69 75
70 76 http_proxy= hg clone static-http://localhost:$HGPORT/remotempty local3 | sed -e 's,:[0-9][0-9]*/,/,'
71 77
72 78 cd local3
73 79 hg verify
74 80 hg paths | sed -e 's,:[0-9][0-9]*/,/,'
75 81
76 82 echo '% test with non-repo'
77 83 cd ..
78 84 mkdir notarepo
79 85 http_proxy= hg clone static-http://localhost:$HGPORT/notarepo local3 2>&1 | sed -e 's,:[0-9][0-9]*/,/,'
80 86
81 87 kill $!
@@ -1,58 +1,62
1 1 abort: Connection refused
2 2 255
3 3 copy: No such file or directory
4 4 changeset: 0:53e17d176ae6
5 5 tag: tip
6 6 user: test
7 7 date: Mon Jan 12 13:46:40 1970 +0000
8 8 summary: test
9 9
10 10 requesting all changes
11 11 adding changesets
12 12 adding manifests
13 13 adding file changes
14 14 added 1 changesets with 1 changes to 1 files
15 15 updating working directory
16 16 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
17 17 checking changesets
18 18 checking manifests
19 19 crosschecking files in changesets and manifests
20 20 checking files
21 21 1 files, 1 changesets, 1 total revisions
22 22 foo
23 23 adding quux
24 24 changegroup hook: HG_NODE=34401e0e9971e9720b613d9089ffa9a6eefb3d2d HG_SOURCE=pull HG_URL=static-http://localhost/remote
25 25 pulling from static-http://localhost/remote
26 26 searching for changes
27 27 adding changesets
28 28 adding manifests
29 29 adding file changes
30 30 added 1 changesets with 1 changes to 1 files
31 31 (run 'hg update' to get a working copy)
32 % trying to push
33 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
34 abort: cannot lock static-http repository
35 pushing to static-http://localhost/remote
32 36 % test with "/" URI (issue 747)
33 37 requesting all changes
34 38 adding changesets
35 39 adding manifests
36 40 adding file changes
37 41 added 1 changesets with 1 changes to 1 files
38 42 updating working directory
39 43 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
40 44 checking changesets
41 45 checking manifests
42 46 crosschecking files in changesets and manifests
43 47 checking files
44 48 1 files, 1 changesets, 1 total revisions
45 49 a
46 50 default = static-http://localhost/
47 51 % test with empty repo (issue965)
48 52 no changes found
49 53 updating working directory
50 54 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
51 55 checking changesets
52 56 checking manifests
53 57 crosschecking files in changesets and manifests
54 58 checking files
55 59 0 files, 0 changesets, 0 total revisions
56 60 default = static-http://localhost/remotempty
57 61 % test with non-repo
58 62 abort: 'http://localhost/notarepo' does not appear to be an hg repository!
General Comments 0
You need to be logged in to leave comments. Login now