2010-12-21 07:37:07 +03:00
|
|
|
import os
|
|
|
|
|
2009-08-10 19:07:13 +04:00
|
|
|
from mercurial.node import bin
|
2014-02-20 02:12:03 +04:00
|
|
|
from mercurial import util
|
2009-06-02 01:57:19 +04:00
|
|
|
|
2009-06-04 00:15:43 +04:00
|
|
|
from git_handler import GitHandler
|
|
|
|
from gitrepo import gitrepo
|
|
|
|
|
2014-08-23 20:35:57 +04:00
|
|
|
from dulwich import errors
|
|
|
|
|
|
|
|
def _transform_notgit(f):
|
|
|
|
def inner(*args, **kwargs):
|
|
|
|
try:
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
except errors.NotGitRepository:
|
|
|
|
raise util.Abort('not a git repository')
|
|
|
|
return inner
|
|
|
|
|
2009-06-04 00:15:43 +04:00
|
|
|
|
2009-07-02 00:31:35 +04:00
|
|
|
def generate_repo_subclass(baseclass):
|
|
|
|
class hgrepo(baseclass):
|
2014-08-23 20:35:57 +04:00
|
|
|
@_transform_notgit
|
2009-07-02 00:31:35 +04:00
|
|
|
def pull(self, remote, heads=None, force=False):
|
|
|
|
if isinstance(remote, gitrepo):
|
2014-02-20 02:12:38 +04:00
|
|
|
return self.githandler.fetch(remote.path, heads)
|
2009-07-07 20:46:14 +04:00
|
|
|
else: #pragma: no cover
|
2009-07-16 22:42:45 +04:00
|
|
|
return super(hgrepo, self).pull(remote, heads, force)
|
2009-07-02 00:31:35 +04:00
|
|
|
|
2010-06-13 06:12:21 +04:00
|
|
|
# TODO figure out something useful to do with the newbranch param
|
2014-08-23 20:35:57 +04:00
|
|
|
@_transform_notgit
|
2014-02-20 03:55:45 +04:00
|
|
|
def push(self, remote, force=False, revs=None, newbranch=False):
|
2009-07-02 00:31:35 +04:00
|
|
|
if isinstance(remote, gitrepo):
|
2014-02-20 02:14:01 +04:00
|
|
|
return self.githandler.push(remote.path, revs, force)
|
2009-07-07 20:46:14 +04:00
|
|
|
else: #pragma: no cover
|
2014-02-20 03:55:45 +04:00
|
|
|
return super(hgrepo, self).push(remote, force, revs, newbranch)
|
2009-07-02 00:31:35 +04:00
|
|
|
|
2014-08-23 20:35:57 +04:00
|
|
|
@_transform_notgit
|
2009-07-31 21:15:02 +04:00
|
|
|
def findoutgoing(self, remote, base=None, heads=None, force=False):
|
|
|
|
if isinstance(remote, gitrepo):
|
2014-02-20 02:14:54 +04:00
|
|
|
base, heads = self.githandler.get_refs(remote.path)
|
2009-07-31 21:15:02 +04:00
|
|
|
out, h = super(hgrepo, self).findoutgoing(remote, base, heads, force)
|
|
|
|
return out
|
|
|
|
else: #pragma: no cover
|
|
|
|
return super(hgrepo, self).findoutgoing(remote, base, heads, force)
|
|
|
|
|
2009-08-04 21:39:02 +04:00
|
|
|
def _findtags(self):
|
|
|
|
(tags, tagtypes) = super(hgrepo, self)._findtags()
|
|
|
|
|
2014-02-20 02:15:33 +04:00
|
|
|
for tag, rev in self.githandler.tags.iteritems():
|
2009-08-04 21:39:02 +04:00
|
|
|
tags[tag] = bin(rev)
|
|
|
|
tagtypes[tag] = 'git'
|
|
|
|
|
2012-07-08 11:10:23 +04:00
|
|
|
tags.update(self.gitrefs())
|
2009-08-04 21:39:02 +04:00
|
|
|
return (tags, tagtypes)
|
|
|
|
|
2014-02-20 02:12:03 +04:00
|
|
|
@util.propertycache
|
|
|
|
def githandler(self):
|
|
|
|
'''get the GitHandler for an hg repo
|
|
|
|
|
|
|
|
This only makes sense if the repo talks to at least one git remote.
|
|
|
|
'''
|
|
|
|
return GitHandler(self, self.ui)
|
|
|
|
|
2010-12-21 07:37:07 +03:00
|
|
|
def gitrefs(self):
|
2014-09-03 20:48:16 +04:00
|
|
|
tagfile = self.join(GitHandler.remote_refs_file)
|
2010-12-21 07:37:07 +03:00
|
|
|
if os.path.exists(tagfile):
|
|
|
|
tf = open(tagfile, 'rb')
|
|
|
|
tagdata = tf.read().split('\n')
|
|
|
|
td = [line.split(' ', 1) for line in tagdata if line]
|
|
|
|
return dict([(name, bin(sha)) for sha, name in td])
|
|
|
|
return {}
|
|
|
|
|
2009-07-02 00:31:35 +04:00
|
|
|
def tags(self):
|
2014-02-20 04:09:23 +04:00
|
|
|
# TODO consider using self._tagscache
|
2009-07-02 00:31:35 +04:00
|
|
|
tagscache = super(hgrepo, self).tags()
|
2011-05-21 09:36:06 +04:00
|
|
|
tagscache.update(self.gitrefs())
|
2014-02-20 02:16:40 +04:00
|
|
|
for tag, rev in self.githandler.tags.iteritems():
|
2009-08-04 21:39:02 +04:00
|
|
|
if tag in tagscache:
|
|
|
|
continue
|
|
|
|
|
|
|
|
tagscache[tag] = bin(rev)
|
|
|
|
|
2009-07-02 00:31:35 +04:00
|
|
|
return tagscache
|
2009-06-19 01:38:09 +04:00
|
|
|
|
2009-07-02 00:31:35 +04:00
|
|
|
return hgrepo
|