mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
7168922e8f
This changeset adds test coverage for comparing "hg outgoing -B" in normal Mercurial usage with Hg-Git usage. This didn't match, since previously, gitrepo didn't provide a meaningful listkeys implementation. Now, it does. gitrepo now has access to a GitHandler when a localrepo is available. This handler is used to access the information needed to implement listkeys for namespaces (currently, only bookmarks) and bookmarks. A couple of other tests were testing "divergent bookmark" scenarios. These tests have been updated to filter out the divergent bookmark output, as it isn't consistent across the supported Mercurial versions.
83 lines
2.2 KiB
Python
83 lines
2.2 KiB
Python
import os
|
|
from mercurial import util
|
|
try:
|
|
from mercurial.error import RepoError
|
|
except ImportError:
|
|
from mercurial.repo import RepoError
|
|
|
|
try:
|
|
from mercurial.peer import peerrepository
|
|
except ImportError:
|
|
from mercurial.repo import repository as peerrepository
|
|
|
|
from git_handler import GitHandler
|
|
|
|
from overlay import overlayrepo
|
|
|
|
from mercurial.node import bin
|
|
|
|
class gitrepo(peerrepository):
|
|
capabilities = ['lookup']
|
|
|
|
def _capabilities(self):
|
|
return self.capabilities
|
|
|
|
def __init__(self, ui, path, create):
|
|
if create: # pragma: no cover
|
|
raise util.Abort('Cannot create a git repository.')
|
|
self.ui = ui
|
|
self.path = path
|
|
self.localrepo = None
|
|
self.handler = None
|
|
|
|
def _initializehandler(self):
|
|
if self.handler is None and self.localrepo is not None:
|
|
self.handler = GitHandler(self.localrepo, self.localrepo.ui)
|
|
return self.handler
|
|
|
|
def url(self):
|
|
return self.path
|
|
|
|
def lookup(self, key):
|
|
if isinstance(key, str):
|
|
return key
|
|
|
|
def local(self):
|
|
if not self.path:
|
|
raise RepoError
|
|
|
|
def heads(self):
|
|
return []
|
|
|
|
def listkeys(self, namespace):
|
|
if namespace == 'namespaces':
|
|
return {'bookmarks':''}
|
|
elif namespace == 'bookmarks':
|
|
handler = self._initializehandler()
|
|
if handler:
|
|
handler.export_commits()
|
|
refs = handler.fetch_pack(self.path)
|
|
reqrefs = refs
|
|
convertlist, commits = handler.getnewgitcommits(reqrefs)
|
|
newcommits = [bin(c) for c in commits]
|
|
b = overlayrepo(handler, newcommits, refs)
|
|
stripped_refs = dict([
|
|
(ref[ref.find('/', ref.find('/')+1)+1:], b.node(refs[ref]))
|
|
for ref in refs.keys()
|
|
if ref.find('/') != -1])
|
|
return stripped_refs
|
|
return {}
|
|
|
|
def pushkey(self, namespace, key, old, new):
|
|
return False
|
|
|
|
# used by incoming in hg <= 1.6
|
|
def branches(self, nodes):
|
|
return []
|
|
|
|
instance = gitrepo
|
|
|
|
def islocal(path):
|
|
u = util.url(path)
|
|
return not u.scheme or u.scheme == 'file'
|