sapling/mercurial/hg.py
mpm@selenic.com e175fdde9b Break apart hg.py
- move the various parts of hg.py into their own files
- create node.py to store node manipulation functions
2005-08-27 14:21:25 -07:00

60 lines
1.8 KiB
Python

# hg.py - repository classes for mercurial
#
# Copyright 2005 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
import os
import util
from node import *
from revlog import *
from repo import *
from demandload import *
demandload(globals(), "localrepo httprepo sshrepo")
# used to avoid circular references so destructors work
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
if mode[0] != "r":
try:
s = os.stat(f)
except OSError:
d = os.path.dirname(f)
if not os.path.isdir(d):
os.makedirs(d)
else:
if s.st_nlink > 1:
file(f + ".tmp", "wb").write(file(f, "rb").read())
util.rename(f+".tmp", f)
return file(f, mode)
return o
def repository(ui, path=None, create=0):
if path:
if path.startswith("http://"):
return httprepo.httprepository(ui, path)
if path.startswith("https://"):
return httprepo.httpsrepository(ui, path)
if path.startswith("hg://"):
return httprepo.httprepository(
ui, path.replace("hg://", "http://"))
if path.startswith("old-http://"):
return localrepo.localrepository(
ui, opener, path.replace("old-http://", "http://"))
if path.startswith("ssh://"):
return sshrepo.sshrepository(ui, path)
return localrepo.localrepository(ui, opener, path, create)