sapling/hggit/gitrepo.py

59 lines
1.6 KiB
Python
Raw Normal View History

2015-06-27 02:27:11 +03:00
from util import isgitsshuri
from mercurial import util
2015-12-31 23:54:33 +03:00
from mercurial.error import RepoError
from mercurial.peer import peerrepository
class gitrepo(peerrepository):
2009-08-01 20:55:54 +04:00
capabilities = ['lookup']
2010-07-05 20:54:06 +04:00
def _capabilities(self):
return self.capabilities
def __init__(self, ui, path, create):
2015-04-23 02:25:04 +03:00
if create: # pragma: no cover
raise util.Abort('Cannot create a git repository.')
self.ui = ui
self.path = path
self.localrepo = None
2010-07-05 20:54:06 +04:00
def url(self):
return self.path
2009-08-01 20:55:54 +04:00
def lookup(self, key):
if isinstance(key, str):
return key
2010-07-05 20:54:06 +04:00
def local(self):
if not self.path:
raise RepoError
2010-07-05 20:54:06 +04:00
def heads(self):
return []
2010-07-05 20:54:06 +04:00
def listkeys(self, namespace):
if namespace == 'namespaces':
2015-04-23 02:25:04 +03:00
return {'bookmarks': ''}
elif namespace == 'bookmarks':
if self.localrepo is not None:
handler = self.localrepo.githandler
refs = handler.fetch_pack(self.path, heads=[])
# map any git shas that exist in hg to hg shas
stripped_refs = dict([
(ref[11:], handler.map_hg_get(refs[ref]) or refs[ref])
2015-04-23 02:25:04 +03:00
for ref in refs.keys() if ref.startswith('refs/heads/')
])
return stripped_refs
2010-07-05 20:54:06 +04:00
return {}
def pushkey(self, namespace, key, old, new):
return False
instance = gitrepo
def islocal(path):
2015-06-27 02:27:11 +03:00
if isgitsshuri(path):
return True
u = util.url(path)
return not u.scheme or u.scheme == 'file'