# HG changeset patch # User mpm@selenic.com # Date 2005-08-27 23:28:53 # Node ID 2cf5c8a4eae5dc70c375fe56cddf9d764934495a # Parent d6b6a15cc7c6860f4877ff222cbc76e68f9452a4 Separate out old-http support - create new statichttprepo class - pull remote bits out of localrepo - pull remote bits out of util.opener - switch hg.repository to use statichttprepo diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -9,7 +9,7 @@ import util from node import * from repo import * from demandload import * -demandload(globals(), "localrepo httprepo sshrepo") +demandload(globals(), "localrepo httprepo sshrepo statichttprepo") def repository(ui, path=None, create=0): if path: @@ -21,8 +21,8 @@ def repository(ui, path=None, create=0): return httprepo.httprepository( ui, path.replace("hg://", "http://")) if path.startswith("old-http://"): - return localrepo.localrepository( - ui, util.opener, path.replace("old-http://", "http://")) + return statichttprepo.statichttprepository( + ui, path.replace("old-http://", "http://")) if path.startswith("ssh://"): return sshrepo.sshrepository(ui, path) diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -13,22 +13,17 @@ demandload(globals(), "re lock transacti class localrepository: def __init__(self, ui, opener, path=None, create=0): - self.remote = 0 - if path and path.startswith("http://"): - self.remote = 1 - self.path = path - else: - if not path: - p = os.getcwd() - while not os.path.isdir(os.path.join(p, ".hg")): - oldp = p - p = os.path.dirname(p) - if p == oldp: raise repo.RepoError("no repo found") - path = p - self.path = os.path.join(path, ".hg") + if not path: + p = os.getcwd() + while not os.path.isdir(os.path.join(p, ".hg")): + oldp = p + p = os.path.dirname(p) + if p == oldp: raise repo.RepoError("no repo found") + path = p + self.path = os.path.join(path, ".hg") - if not create and not os.path.isdir(self.path): - raise repo.RepoError("repository %s not found" % self.path) + if not create and not os.path.isdir(self.path): + raise repo.RepoError("repository %s not found" % self.path) self.root = os.path.abspath(path) self.ui = ui @@ -44,11 +39,10 @@ class localrepository: self.tagscache = None self.nodetagscache = None - if not self.remote: - self.dirstate = dirstate.dirstate(self.opener, ui, self.root) - try: - self.ui.readconfig(self.opener("hgrc")) - except IOError: pass + self.dirstate = dirstate.dirstate(self.opener, ui, self.root) + try: + self.ui.readconfig(self.opener("hgrc")) + except IOError: pass def hook(self, name, **args): s = self.ui.config("hooks", name) @@ -142,11 +136,10 @@ class localrepository: raise repo.RepoError("unknown revision '%s'" % key) def dev(self): - if self.remote: return -1 return os.stat(self.path).st_dev def local(self): - return not self.remote + return True def join(self, f): return os.path.join(self.path, f) diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py new file mode 100644 --- /dev/null +++ b/mercurial/statichttprepo.py @@ -0,0 +1,35 @@ +# statichttprepo.py - simple http repository class for mercurial +# +# This provides read-only repo access to repositories exported via static http +# +# Copyright 2005 Matt Mackall +# +# This software may be used and distributed according to the terms +# of the GNU General Public License, incorporated herein by reference. + +import os, urllib +import localrepo, httprangereader, filelog, manifest, changelog + +def opener(base): + """return a function that opens files over http""" + p = base + def o(path, mode="r"): + f = os.path.join(p, urllib.quote(path)) + return httprangereader.httprangereader(f) + return o + +class statichttprepository(localrepo.localrepository): + def __init__(self, ui, path): + self.path = (path + "/.hg") + self.ui = ui + self.opener = opener(self.path) + self.manifest = manifest.manifest(self.opener) + self.changelog = changelog.changelog(self.opener) + self.tagscache = None + self.nodetagscache = None + + def dev(self): + return -1 + + def local(self): + return False diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -243,10 +243,6 @@ def opener(base): """ p = base def o(path, mode="r"): - if p.startswith("http://"): - f = os.path.join(p, urllib.quote(path)) - return httprangereader.httprangereader(f) - f = os.path.join(p, path) mode += "b" # for that other OS