Mercurial > hg
annotate mercurial/statichttprepo.py @ 3392:17894d1d9eea
hgweb: fix parent/child links across renames
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sat, 14 Oct 2006 16:03:23 -0700 |
parents | 345bac2bc4ec |
children | ff06fe0703ef |
rev | line source |
---|---|
1101 | 1 # statichttprepo.py - simple http repository class for mercurial |
2 # | |
3 # This provides read-only repo access to repositories exported via static http | |
4 # | |
2859 | 5 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
1101 | 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 | |
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
10 from demandload import * |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
11 from i18n import gettext as _ |
1325
57220daf40e9
Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1101
diff
changeset
|
12 demandload(globals(), "changelog filelog httprangereader") |
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
13 demandload(globals(), "localrepo manifest os urllib urllib2 util") |
1325
57220daf40e9
Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1101
diff
changeset
|
14 |
57220daf40e9
Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1101
diff
changeset
|
15 class rangereader(httprangereader.httprangereader): |
57220daf40e9
Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1101
diff
changeset
|
16 def read(self, size=None): |
57220daf40e9
Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1101
diff
changeset
|
17 try: |
57220daf40e9
Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1101
diff
changeset
|
18 return httprangereader.httprangereader.read(self, size) |
1821
0b3f4be5c5bf
Catch urllib errors for old-http in a nicer way.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1598
diff
changeset
|
19 except urllib2.HTTPError, inst: |
0b3f4be5c5bf
Catch urllib errors for old-http in a nicer way.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1598
diff
changeset
|
20 raise IOError(None, inst) |
1325
57220daf40e9
Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1101
diff
changeset
|
21 except urllib2.URLError, inst: |
1821
0b3f4be5c5bf
Catch urllib errors for old-http in a nicer way.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1598
diff
changeset
|
22 raise IOError(None, inst.reason[1]) |
1101 | 23 |
24 def opener(base): | |
25 """return a function that opens files over http""" | |
26 p = base | |
27 def o(path, mode="r"): | |
28 f = os.path.join(p, urllib.quote(path)) | |
1325
57220daf40e9
Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1101
diff
changeset
|
29 return rangereader(f) |
1101 | 30 return o |
31 | |
32 class statichttprepository(localrepo.localrepository): | |
33 def __init__(self, ui, path): | |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2072
diff
changeset
|
34 self._url = path |
1101 | 35 self.path = (path + "/.hg") |
36 self.ui = ui | |
2072 | 37 self.revlogversion = 0 |
1101 | 38 self.opener = opener(self.path) |
39 self.manifest = manifest.manifest(self.opener) | |
40 self.changelog = changelog.changelog(self.opener) | |
41 self.tagscache = None | |
42 self.nodetagscache = None | |
1598
14d1f1868bf6
cleanup of revlog.group when repository is local
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1325
diff
changeset
|
43 self.encodepats = None |
14d1f1868bf6
cleanup of revlog.group when repository is local
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1325
diff
changeset
|
44 self.decodepats = None |
1101 | 45 |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2072
diff
changeset
|
46 def url(self): |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2072
diff
changeset
|
47 return 'static-' + self._url |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2072
diff
changeset
|
48 |
1101 | 49 def dev(self): |
50 return -1 | |
51 | |
52 def local(self): | |
53 return False | |
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
54 |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
55 def instance(ui, path, create): |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
56 if create: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
57 raise util.Abort(_('cannot create new static-http repository')) |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
58 if path.startswith('old-http:'): |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
59 ui.warn(_("old-http:// syntax is deprecated, " |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
60 "please use static-http:// instead\n")) |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
61 path = path[4:] |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
62 else: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
63 path = path[7:] |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
64 return statichttprepository(ui, path) |