mercurial/statichttprepo.py
author Vadim Gelfer <vadim.gelfer@gmail.com>
Fri, 04 Nov 2005 11:51:01 -0800
changeset 1583 32a4e6802864
parent 1325 57220daf40e9
child 1598 14d1f1868bf6
child 1677 11d12bd6e1dc
permissions -rw-r--r--
make mercurial look in more places for config files. now it searches <install dir>/etc/mercurial, /etc/mercurial, and user hgrc. this allows site-wide configuration to be shared over automounted nfs partition, instead of chenging on every system. option of having local configuration on every system remains. old code for searching /etc/mercurial/hgrc.d never worked, this code is tested and works.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1101
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
     1
# statichttprepo.py - simple http repository class for mercurial
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
     2
#
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
     3
# This provides read-only repo access to repositories exported via static http
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
     4
#
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
     5
# Copyright 2005 Matt Mackall <mpm@selenic.com>
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
     6
#
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
     7
# This software may be used and distributed according to the terms
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
     8
# of the GNU General Public License, incorporated herein by reference.
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
     9
1325
57220daf40e9 Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1101
diff changeset
    10
from demandload import demandload
57220daf40e9 Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1101
diff changeset
    11
demandload(globals(), "changelog filelog httprangereader")
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(), "localrepo manifest os urllib urllib2")
57220daf40e9 Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1101
diff changeset
    13
57220daf40e9 Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1101
diff changeset
    14
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
    15
    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
    16
        try:
57220daf40e9 Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1101
diff changeset
    17
            return httprangereader.httprangereader.read(self, size)
57220daf40e9 Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1101
diff changeset
    18
        except urllib2.URLError, inst:
57220daf40e9 Move urllib error handling from revlog into statichttprepo, where it belongs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1101
diff changeset
    19
            raise IOError(None, str(inst))
1101
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    20
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    21
def opener(base):
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    22
    """return a function that opens files over http"""
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    23
    p = base
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    24
    def o(path, mode="r"):
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    25
        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
    26
        return rangereader(f)
1101
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    27
    return o
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    28
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    29
class statichttprepository(localrepo.localrepository):
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    30
    def __init__(self, ui, path):
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    31
        self.path = (path + "/.hg")
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    32
        self.ui = ui
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    33
        self.opener = opener(self.path)
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    34
        self.manifest = manifest.manifest(self.opener)
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    35
        self.changelog = changelog.changelog(self.opener)
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    36
        self.tagscache = None
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    37
        self.nodetagscache = None
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    38
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    39
    def dev(self):
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    40
        return -1
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    41
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    42
    def local(self):
2cf5c8a4eae5 Separate out old-http support
mpm@selenic.com
parents:
diff changeset
    43
        return False