Skip to content
Snippets Groups Projects
Commit 4d2699f8 authored by Dan Villiom Podlaski Christiansen's avatar Dan Villiom Podlaski Christiansen
Browse files

gitrepo: move discovery & exchange related logic

parent cc35f26b
No related branches found
Tags 0.4.0
1 merge request!107Refactor __init__.py to many modules; use exthelper
......@@ -131,6 +131,5 @@
from . import revsets
from . import schemes
from . import templates
from . import util
from mercurial import (
......@@ -135,4 +134,3 @@
from mercurial import (
bundlerepo,
demandimport,
......@@ -138,7 +136,4 @@
demandimport,
discovery,
exchange,
extensions,
pycompat,
registrar,
)
......@@ -182,85 +177,3 @@
gitdirstate.reposetup(ui, repo)
hgrepo.reposetup(ui, repo)
def findcommonoutgoing(orig, repo, other, *args, **kwargs):
if isinstance(other, gitrepo.gitrepo):
heads = repo.githandler.get_refs(other.path)[0]
kw = {}
kw.update(kwargs)
for val, k in zip(args,
('onlyheads', 'force', 'commoninc', 'portable')):
kw[k] = val
force = kw.get('force', False)
commoninc = kw.get('commoninc', None)
if commoninc is None:
commoninc = discovery.findcommonincoming(repo, other, heads=heads,
force=force)
kw['commoninc'] = commoninc
return orig(repo, other, **kw)
return orig(repo, other, *args, **kwargs)
extensions.wrapfunction(discovery, b'findcommonoutgoing', findcommonoutgoing)
def getremotechanges(orig, ui, repo, other, *args, **opts):
if isinstance(other, gitrepo.gitrepo):
if args:
revs = args[0]
else:
revs = opts.get('onlyheads', opts.get('revs'))
r, c, cleanup = repo.githandler.getremotechanges(other, revs)
# ugh. This is ugly even by mercurial API compatibility standards
if 'onlyheads' not in orig.__code__.co_varnames:
cleanup = None
return r, c, cleanup
return orig(ui, repo, other, *args, **opts)
extensions.wrapfunction(bundlerepo, b'getremotechanges', getremotechanges)
@util.transform_notgit
def exchangepull(orig, repo, remote, heads=None, force=False, bookmarks=(),
**kwargs):
if isinstance(remote, gitrepo.gitrepo):
pullop = exchange.pulloperation(repo, remote, heads, force,
bookmarks=bookmarks)
pullop.trmanager = exchange.transactionmanager(repo, b'pull',
remote.url())
wlock = repo.wlock()
lock = repo.lock()
try:
pullop.cgresult = repo.githandler.fetch(remote.path, heads)
pullop.trmanager.close()
return pullop
finally:
pullop.trmanager.release()
lock.release()
wlock.release()
else:
return orig(repo, remote, heads, force, bookmarks=bookmarks, **kwargs)
extensions.wrapfunction(exchange, b'pull', exchangepull)
# TODO figure out something useful to do with the newbranch param
@util.transform_notgit
def exchangepush(orig, repo, remote, force=False, revs=None, newbranch=False,
bookmarks=(), opargs=None, **kwargs):
if isinstance(remote, gitrepo.gitrepo):
pushop = exchange.pushoperation(repo, remote, force, revs, newbranch,
bookmarks,
**pycompat.strkwargs(opargs or {}))
pushop.cgresult = repo.githandler.push(remote.path, revs, force)
return pushop
else:
return orig(repo, remote, force, revs, newbranch, bookmarks=bookmarks,
opargs=None, **kwargs)
extensions.wrapfunction(exchange, b'push', exchangepush)
......@@ -3,4 +3,6 @@
from . import util
from . import compat
from mercurial import (
bundlerepo,
discovery,
error,
......@@ -6,3 +8,4 @@
error,
exchange,
extensions,
hg,
......@@ -7,5 +10,6 @@
extensions,
hg,
pycompat,
)
from mercurial.wireprotov1peer import (
batchable,
......@@ -162,5 +166,103 @@
return revs, co
def findcommonoutgoing(orig, repo, other, *args, **kwargs):
if isinstance(other, gitrepo):
heads = repo.githandler.get_refs(other.path)[0]
kw = {}
kw.update(kwargs)
for val, k in zip(
args, ('onlyheads', 'force', 'commoninc', 'portable')
):
kw[k] = val
force = kw.get('force', False)
commoninc = kw.get('commoninc', None)
if commoninc is None:
commoninc = discovery.findcommonincoming(
repo, other, heads=heads, force=force
)
kw['commoninc'] = commoninc
return orig(repo, other, **kw)
return orig(repo, other, *args, **kwargs)
def getremotechanges(orig, ui, repo, other, *args, **opts):
if isinstance(other, gitrepo):
if args:
revs = args[0]
else:
revs = opts.get('onlyheads', opts.get('revs'))
r, c, cleanup = repo.githandler.getremotechanges(other, revs)
# ugh. This is ugly even by mercurial API compatibility standards
if 'onlyheads' not in orig.__code__.co_varnames:
cleanup = None
return r, c, cleanup
return orig(ui, repo, other, *args, **opts)
@util.transform_notgit
def exchangepull(
orig, repo, remote, heads=None, force=False, bookmarks=(), **kwargs
):
if isinstance(remote, gitrepo):
pullop = exchange.pulloperation(
repo, remote, heads, force, bookmarks=bookmarks
)
pullop.trmanager = exchange.transactionmanager(
repo, b'pull', remote.url()
)
wlock = repo.wlock()
lock = repo.lock()
try:
pullop.cgresult = repo.githandler.fetch(remote.path, heads)
pullop.trmanager.close()
return pullop
finally:
pullop.trmanager.release()
lock.release()
wlock.release()
else:
return orig(repo, remote, heads, force, bookmarks=bookmarks, **kwargs)
# TODO figure out something useful to do with the newbranch param
@util.transform_notgit
def exchangepush(
orig,
repo,
remote,
force=False,
revs=None,
newbranch=False,
bookmarks=(),
opargs=None,
**kwargs
):
if isinstance(remote, gitrepo):
pushop = exchange.pushoperation(
repo,
remote,
force,
revs,
newbranch,
bookmarks,
**pycompat.strkwargs(opargs or {}),
)
pushop.cgresult = repo.githandler.push(remote.path, revs, force)
return pushop
else:
return orig(
repo,
remote,
force,
revs,
newbranch,
bookmarks=bookmarks,
opargs=None,
**kwargs,
)
def extsetup(ui):
extensions.wrapfunction(hg, b'addbranchrevs', safebranchrevs)
......@@ -165,2 +267,6 @@
def extsetup(ui):
extensions.wrapfunction(hg, b'addbranchrevs', safebranchrevs)
extensions.wrapfunction(discovery, b'findcommonoutgoing', findcommonoutgoing)
extensions.wrapfunction(bundlerepo, b'getremotechanges', getremotechanges)
extensions.wrapfunction(exchange, b'pull', exchangepull)
extensions.wrapfunction(exchange, b'push', exchangepush)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment