mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
f82134e252
hg pull calls listkeys for bookmarks. This would previously cause a pack with all refs to be fetched. For Mercurial mirrors of Git repositories where only some refs were mirrored, this would cause problems in a bunch of ways: - A larger pack would be fetched than necessary. - The final refs written out to the Git repo would only be the set of refs we were actually interested in. If a GC was subsequently run, unreferenced objects would be deleted. Those objects might be referred to on subsequent fetches, which could cause hg-git to crash. We replace all that logic with a simple null fetch. The tests introduced in the previous patch ensure no regressions.
68 lines
1.8 KiB
Python
68 lines
1.8 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 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
|
|
|
|
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':
|
|
if self.localrepo is not None:
|
|
handler = self.localrepo.githandler
|
|
handler.export_commits()
|
|
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])
|
|
for ref in refs.keys()
|
|
if ref.startswith('refs/heads/')])
|
|
return stripped_refs
|
|
return {}
|
|
|
|
def pushkey(self, namespace, key, old, new):
|
|
return False
|
|
|
|
instance = gitrepo
|
|
|
|
def islocal(path):
|
|
u = util.url(path)
|
|
return not u.scheme or u.scheme == 'file'
|