##// 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 # statichttprepo.py - simple http repository class for mercurial
1 # statichttprepo.py - simple http repository class for mercurial
2 #
2 #
3 # This provides read-only repo access to repositories exported via static http
3 # This provides read-only repo access to repositories exported via static http
4 #
4 #
5 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
5 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
6 #
6 #
7 # This software may be used and distributed according to the terms
7 # This software may be used and distributed according to the terms
8 # of the GNU General Public License, incorporated herein by reference.
8 # of the GNU General Public License, incorporated herein by reference.
9
9
10 from i18n import _
10 from i18n import _
11 import changelog, httprangereader
11 import changelog, httprangereader
12 import repo, localrepo, manifest, util, store
12 import repo, localrepo, manifest, util, store
13 import urllib, urllib2, errno
13 import urllib, urllib2, errno
14
14
15 class rangereader(httprangereader.httprangereader):
15 class rangereader(httprangereader.httprangereader):
16 def read(self, size=None):
16 def read(self, size=None):
17 try:
17 try:
18 return httprangereader.httprangereader.read(self, size)
18 return httprangereader.httprangereader.read(self, size)
19 except urllib2.HTTPError, inst:
19 except urllib2.HTTPError, inst:
20 num = inst.code == 404 and errno.ENOENT or None
20 num = inst.code == 404 and errno.ENOENT or None
21 raise IOError(num, inst)
21 raise IOError(num, inst)
22 except urllib2.URLError, inst:
22 except urllib2.URLError, inst:
23 raise IOError(None, inst.reason[1])
23 raise IOError(None, inst.reason[1])
24
24
25 def opener(base):
25 def opener(base):
26 """return a function that opens files over http"""
26 """return a function that opens files over http"""
27 p = base
27 p = base
28 def o(path, mode="r"):
28 def o(path, mode="r"):
29 f = "/".join((p, urllib.quote(path)))
29 f = "/".join((p, urllib.quote(path)))
30 return rangereader(f)
30 return rangereader(f)
31 return o
31 return o
32
32
33 class statichttprepository(localrepo.localrepository):
33 class statichttprepository(localrepo.localrepository):
34 def __init__(self, ui, path):
34 def __init__(self, ui, path):
35 self._url = path
35 self._url = path
36 self.ui = ui
36 self.ui = ui
37
37
38 self.path = path.rstrip('/') + "/.hg"
38 self.path = path.rstrip('/') + "/.hg"
39 self.opener = opener(self.path)
39 self.opener = opener(self.path)
40
40
41 # find requirements
41 # find requirements
42 try:
42 try:
43 requirements = self.opener("requires").read().splitlines()
43 requirements = self.opener("requires").read().splitlines()
44 except IOError, inst:
44 except IOError, inst:
45 if inst.errno == errno.ENOENT:
45 if inst.errno == errno.ENOENT:
46 msg = _("'%s' does not appear to be an hg repository") % path
46 msg = _("'%s' does not appear to be an hg repository") % path
47 raise repo.RepoError(msg)
47 raise repo.RepoError(msg)
48 else:
48 else:
49 requirements = []
49 requirements = []
50
50
51 # check them
51 # check them
52 for r in requirements:
52 for r in requirements:
53 if r not in self.supported:
53 if r not in self.supported:
54 raise repo.RepoError(_("requirement '%s' not supported") % r)
54 raise repo.RepoError(_("requirement '%s' not supported") % r)
55
55
56 # setup store
56 # setup store
57 def pjoin(a, b):
57 def pjoin(a, b):
58 return a + '/' + b
58 return a + '/' + b
59 self.store = store.store(requirements, self.path, opener, pjoin)
59 self.store = store.store(requirements, self.path, opener, pjoin)
60 self.spath = self.store.path
60 self.spath = self.store.path
61 self.sopener = self.store.opener
61 self.sopener = self.store.opener
62 self.sjoin = self.store.join
62 self.sjoin = self.store.join
63
63
64 self.manifest = manifest.manifest(self.sopener)
64 self.manifest = manifest.manifest(self.sopener)
65 self.changelog = changelog.changelog(self.sopener)
65 self.changelog = changelog.changelog(self.sopener)
66 self.tagscache = None
66 self.tagscache = None
67 self.nodetagscache = None
67 self.nodetagscache = None
68 self.encodepats = None
68 self.encodepats = None
69 self.decodepats = None
69 self.decodepats = None
70
70
71 def url(self):
71 def url(self):
72 return 'static-' + self._url
72 return 'static-' + self._url
73
73
74 def local(self):
74 def local(self):
75 return False
75 return False
76
76
77 def lock(self, wait=True):
78 raise util.Abort(_('cannot lock static-http repository'))
79
77 def instance(ui, path, create):
80 def instance(ui, path, create):
78 if create:
81 if create:
79 raise util.Abort(_('cannot create new static-http repository'))
82 raise util.Abort(_('cannot create new static-http repository'))
80 return statichttprepository(ui, path[7:])
83 return statichttprepository(ui, path[7:])
@@ -1,81 +1,87
1 #!/bin/sh
1 #!/bin/sh
2
2
3 cp "$TESTDIR"/printenv.py .
3 cp "$TESTDIR"/printenv.py .
4
4
5 http_proxy= hg clone static-http://localhost:$HGPORT/ copy
5 http_proxy= hg clone static-http://localhost:$HGPORT/ copy
6 echo $?
6 echo $?
7 test -d copy || echo copy: No such file or directory
7 test -d copy || echo copy: No such file or directory
8
8
9 # This server doesn't do range requests so it's basically only good for
9 # This server doesn't do range requests so it's basically only good for
10 # one pull
10 # one pull
11 cat > dumb.py <<EOF
11 cat > dumb.py <<EOF
12 import BaseHTTPServer, SimpleHTTPServer, os, signal
12 import BaseHTTPServer, SimpleHTTPServer, os, signal
13
13
14 def run(server_class=BaseHTTPServer.HTTPServer,
14 def run(server_class=BaseHTTPServer.HTTPServer,
15 handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler):
15 handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler):
16 server_address = ('localhost', int(os.environ['HGPORT']))
16 server_address = ('localhost', int(os.environ['HGPORT']))
17 httpd = server_class(server_address, handler_class)
17 httpd = server_class(server_address, handler_class)
18 httpd.serve_forever()
18 httpd.serve_forever()
19
19
20 signal.signal(signal.SIGTERM, lambda x: sys.exit(0))
20 signal.signal(signal.SIGTERM, lambda x: sys.exit(0))
21 run()
21 run()
22 EOF
22 EOF
23
23
24 python dumb.py 2>/dev/null &
24 python dumb.py 2>/dev/null &
25 echo $! >> $DAEMON_PIDS
25 echo $! >> $DAEMON_PIDS
26
26
27 mkdir remote
27 mkdir remote
28 cd remote
28 cd remote
29 hg init
29 hg init
30 echo foo > bar
30 echo foo > bar
31 hg add bar
31 hg add bar
32 hg commit -m"test" -d "1000000 0"
32 hg commit -m"test" -d "1000000 0"
33 hg tip
33 hg tip
34
34
35 cd ..
35 cd ..
36
36
37 http_proxy= hg clone static-http://localhost:$HGPORT/remote local | sed -e 's,:[0-9][0-9]*/,/,'
37 http_proxy= hg clone static-http://localhost:$HGPORT/remote local | sed -e 's,:[0-9][0-9]*/,/,'
38
38
39 cd local
39 cd local
40 hg verify
40 hg verify
41 cat bar
41 cat bar
42
42
43 cd ../remote
43 cd ../remote
44 echo baz > quux
44 echo baz > quux
45 hg commit -A -mtest2 -d '100000000 0'
45 hg commit -A -mtest2 -d '100000000 0'
46
46
47 cd ../local
47 cd ../local
48 echo '[hooks]' >> .hg/hgrc
48 echo '[hooks]' >> .hg/hgrc
49 echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
49 echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
50 http_proxy= hg pull | sed -e 's,:[0-9][0-9]*/,/,'
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 echo '% test with "/" URI (issue 747)'
58 echo '% test with "/" URI (issue 747)'
53 cd ..
59 cd ..
54 hg init
60 hg init
55 echo a > a
61 echo a > a
56 hg add a
62 hg add a
57 hg ci -ma
63 hg ci -ma
58
64
59 http_proxy= hg clone static-http://localhost:$HGPORT/ local2 | sed -e 's,:[0-9][0-9]*/,/,'
65 http_proxy= hg clone static-http://localhost:$HGPORT/ local2 | sed -e 's,:[0-9][0-9]*/,/,'
60
66
61 cd local2
67 cd local2
62 hg verify
68 hg verify
63 cat a
69 cat a
64 hg paths | sed -e 's,:[0-9][0-9]*/,/,'
70 hg paths | sed -e 's,:[0-9][0-9]*/,/,'
65
71
66 echo '% test with empty repo (issue965)'
72 echo '% test with empty repo (issue965)'
67 cd ..
73 cd ..
68 hg init remotempty
74 hg init remotempty
69
75
70 http_proxy= hg clone static-http://localhost:$HGPORT/remotempty local3 | sed -e 's,:[0-9][0-9]*/,/,'
76 http_proxy= hg clone static-http://localhost:$HGPORT/remotempty local3 | sed -e 's,:[0-9][0-9]*/,/,'
71
77
72 cd local3
78 cd local3
73 hg verify
79 hg verify
74 hg paths | sed -e 's,:[0-9][0-9]*/,/,'
80 hg paths | sed -e 's,:[0-9][0-9]*/,/,'
75
81
76 echo '% test with non-repo'
82 echo '% test with non-repo'
77 cd ..
83 cd ..
78 mkdir notarepo
84 mkdir notarepo
79 http_proxy= hg clone static-http://localhost:$HGPORT/notarepo local3 2>&1 | sed -e 's,:[0-9][0-9]*/,/,'
85 http_proxy= hg clone static-http://localhost:$HGPORT/notarepo local3 2>&1 | sed -e 's,:[0-9][0-9]*/,/,'
80
86
81 kill $!
87 kill $!
@@ -1,58 +1,62
1 abort: Connection refused
1 abort: Connection refused
2 255
2 255
3 copy: No such file or directory
3 copy: No such file or directory
4 changeset: 0:53e17d176ae6
4 changeset: 0:53e17d176ae6
5 tag: tip
5 tag: tip
6 user: test
6 user: test
7 date: Mon Jan 12 13:46:40 1970 +0000
7 date: Mon Jan 12 13:46:40 1970 +0000
8 summary: test
8 summary: test
9
9
10 requesting all changes
10 requesting all changes
11 adding changesets
11 adding changesets
12 adding manifests
12 adding manifests
13 adding file changes
13 adding file changes
14 added 1 changesets with 1 changes to 1 files
14 added 1 changesets with 1 changes to 1 files
15 updating working directory
15 updating working directory
16 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
16 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
17 checking changesets
17 checking changesets
18 checking manifests
18 checking manifests
19 crosschecking files in changesets and manifests
19 crosschecking files in changesets and manifests
20 checking files
20 checking files
21 1 files, 1 changesets, 1 total revisions
21 1 files, 1 changesets, 1 total revisions
22 foo
22 foo
23 adding quux
23 adding quux
24 changegroup hook: HG_NODE=34401e0e9971e9720b613d9089ffa9a6eefb3d2d HG_SOURCE=pull HG_URL=static-http://localhost/remote
24 changegroup hook: HG_NODE=34401e0e9971e9720b613d9089ffa9a6eefb3d2d HG_SOURCE=pull HG_URL=static-http://localhost/remote
25 pulling from static-http://localhost/remote
25 pulling from static-http://localhost/remote
26 searching for changes
26 searching for changes
27 adding changesets
27 adding changesets
28 adding manifests
28 adding manifests
29 adding file changes
29 adding file changes
30 added 1 changesets with 1 changes to 1 files
30 added 1 changesets with 1 changes to 1 files
31 (run 'hg update' to get a working copy)
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 % test with "/" URI (issue 747)
36 % test with "/" URI (issue 747)
33 requesting all changes
37 requesting all changes
34 adding changesets
38 adding changesets
35 adding manifests
39 adding manifests
36 adding file changes
40 adding file changes
37 added 1 changesets with 1 changes to 1 files
41 added 1 changesets with 1 changes to 1 files
38 updating working directory
42 updating working directory
39 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
43 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
40 checking changesets
44 checking changesets
41 checking manifests
45 checking manifests
42 crosschecking files in changesets and manifests
46 crosschecking files in changesets and manifests
43 checking files
47 checking files
44 1 files, 1 changesets, 1 total revisions
48 1 files, 1 changesets, 1 total revisions
45 a
49 a
46 default = static-http://localhost/
50 default = static-http://localhost/
47 % test with empty repo (issue965)
51 % test with empty repo (issue965)
48 no changes found
52 no changes found
49 updating working directory
53 updating working directory
50 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
54 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
51 checking changesets
55 checking changesets
52 checking manifests
56 checking manifests
53 crosschecking files in changesets and manifests
57 crosschecking files in changesets and manifests
54 checking files
58 checking files
55 0 files, 0 changesets, 0 total revisions
59 0 files, 0 changesets, 0 total revisions
56 default = static-http://localhost/remotempty
60 default = static-http://localhost/remotempty
57 % test with non-repo
61 % test with non-repo
58 abort: 'http://localhost/notarepo' does not appear to be an hg repository!
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