2015-06-27 02:27:11 +03:00
|
|
|
from util import isgitsshuri
|
2012-07-19 00:16:43 +04:00
|
|
|
from mercurial import util
|
2015-12-31 23:54:33 +03:00
|
|
|
from mercurial.error import RepoError
|
|
|
|
from mercurial.peer import peerrepository
|
2012-07-19 00:16:43 +04:00
|
|
|
|
2012-07-20 04:36:57 +04:00
|
|
|
class gitrepo(peerrepository):
|
2009-08-01 20:55:54 +04:00
|
|
|
capabilities = ['lookup']
|
2010-07-05 20:54:06 +04:00
|
|
|
|
2012-07-27 03:58:18 +04:00
|
|
|
def _capabilities(self):
|
|
|
|
return self.capabilities
|
|
|
|
|
2009-06-04 00:15:43 +04:00
|
|
|
def __init__(self, ui, path, create):
|
2015-04-23 02:25:04 +03:00
|
|
|
if create: # pragma: no cover
|
2009-06-04 00:15:43 +04:00
|
|
|
raise util.Abort('Cannot create a git repository.')
|
2009-10-08 22:50:09 +04:00
|
|
|
self.ui = ui
|
2009-06-04 00:15:43 +04:00
|
|
|
self.path = path
|
2012-10-26 03:54:05 +04:00
|
|
|
self.localrepo = None
|
2010-07-05 20:54:06 +04:00
|
|
|
|
2012-05-12 12:33:19 +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
|
|
|
|
2009-10-08 22:50:09 +04:00
|
|
|
def local(self):
|
|
|
|
if not self.path:
|
|
|
|
raise RepoError
|
2010-07-05 20:54:06 +04:00
|
|
|
|
2010-06-13 06:49:14 +04:00
|
|
|
def heads(self):
|
|
|
|
return []
|
2009-10-08 22:50:09 +04:00
|
|
|
|
2010-07-05 20:54:06 +04:00
|
|
|
def listkeys(self, namespace):
|
2012-10-26 04:49:08 +04:00
|
|
|
if namespace == 'namespaces':
|
2015-04-23 02:25:04 +03:00
|
|
|
return {'bookmarks': ''}
|
2012-10-26 04:49:08 +04:00
|
|
|
elif namespace == 'bookmarks':
|
2014-02-20 03:07:19 +04:00
|
|
|
if self.localrepo is not None:
|
|
|
|
handler = self.localrepo.githandler
|
2014-05-09 07:18:06 +04:00
|
|
|
refs = handler.fetch_pack(self.path, heads=[])
|
|
|
|
# map any git shas that exist in hg to hg shas
|
2012-10-26 04:49:08 +04:00
|
|
|
stripped_refs = dict([
|
2014-05-09 07:18:06 +04:00
|
|
|
(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/')
|
|
|
|
])
|
2012-10-26 04:49:08 +04:00
|
|
|
return stripped_refs
|
2010-07-05 20:54:06 +04:00
|
|
|
return {}
|
|
|
|
|
|
|
|
def pushkey(self, namespace, key, old, new):
|
|
|
|
return False
|
|
|
|
|
2009-04-29 11:54:13 +04:00
|
|
|
instance = gitrepo
|
2011-05-23 21:32:38 +04:00
|
|
|
|
|
|
|
def islocal(path):
|
2015-06-27 02:27:11 +03:00
|
|
|
if isgitsshuri(path):
|
|
|
|
return True
|
|
|
|
|
2011-05-23 21:32:38 +04:00
|
|
|
u = util.url(path)
|
|
|
|
return not u.scheme or u.scheme == 'file'
|