2010-12-21 07:37:07 +03:00
|
|
|
import os
|
|
|
|
|
2009-08-10 19:07:13 +04:00
|
|
|
from mercurial.node import bin
|
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
|
|
|
|
|
|
|
|
|
2009-07-02 00:31:35 +04:00
|
|
|
def generate_repo_subclass(baseclass):
|
|
|
|
class hgrepo(baseclass):
|
|
|
|
def pull(self, remote, heads=None, force=False):
|
|
|
|
if isinstance(remote, gitrepo):
|
|
|
|
git = GitHandler(self, self.ui)
|
2011-05-19 02:12:32 +04:00
|
|
|
return git.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
|
|
|
|
def push(self, remote, force=False, revs=None, newbranch=None):
|
2009-07-02 00:31:35 +04:00
|
|
|
if isinstance(remote, gitrepo):
|
|
|
|
git = GitHandler(self, self.ui)
|
2009-07-31 01:09:53 +04:00
|
|
|
git.push(remote.path, revs, force)
|
2009-07-07 20:46:14 +04:00
|
|
|
else: #pragma: no cover
|
2010-08-15 18:45:00 +04:00
|
|
|
# newbranch was added in 1.6
|
|
|
|
if newbranch is None:
|
|
|
|
return super(hgrepo, self).push(remote, force, revs)
|
|
|
|
else:
|
|
|
|
return super(hgrepo, self).push(remote, force, revs,
|
|
|
|
newbranch)
|
2009-07-02 00:31:35 +04:00
|
|
|
|
2009-07-31 21:15:02 +04:00
|
|
|
def findoutgoing(self, remote, base=None, heads=None, force=False):
|
|
|
|
if isinstance(remote, gitrepo):
|
|
|
|
git = GitHandler(self, self.ui)
|
|
|
|
base, heads = git.get_refs(remote.path)
|
|
|
|
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()
|
|
|
|
|
|
|
|
git = GitHandler(self, self.ui)
|
|
|
|
for tag, rev in git.tags.iteritems():
|
|
|
|
tags[tag] = bin(rev)
|
|
|
|
tagtypes[tag] = 'git'
|
|
|
|
|
|
|
|
return (tags, tagtypes)
|
|
|
|
|
2010-12-21 07:37:07 +03:00
|
|
|
def gitrefs(self):
|
|
|
|
tagfile = self.join(os.path.join('git-remote-refs'))
|
|
|
|
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):
|
2011-05-21 09:36:06 +04:00
|
|
|
if hasattr(self, 'tagscache') and self.tagscache:
|
|
|
|
# Mercurial 1.4 and earlier.
|
2009-07-02 00:31:35 +04:00
|
|
|
return self.tagscache
|
2011-05-21 09:36:06 +04:00
|
|
|
elif hasattr(self, '_tags') and self._tags:
|
|
|
|
# Mercurial 1.5 and later.
|
|
|
|
return self._tags
|
2009-06-19 01:38:09 +04:00
|
|
|
|
2009-07-02 00:31:35 +04:00
|
|
|
git = GitHandler(self, self.ui)
|
|
|
|
tagscache = super(hgrepo, self).tags()
|
2011-05-21 09:36:06 +04:00
|
|
|
tagscache.update(self.gitrefs())
|
2009-08-04 21:39:02 +04:00
|
|
|
for tag, rev in git.tags.iteritems():
|
|
|
|
if tag in tagscache:
|
|
|
|
continue
|
|
|
|
|
|
|
|
tagscache[tag] = bin(rev)
|
2011-05-21 09:36:06 +04:00
|
|
|
if hasattr(self, '_tagstypecache'):
|
|
|
|
# Only present in Mercurial 1.3 and earlier.
|
|
|
|
self._tagstypecache[tag] = 'git'
|
2009-08-04 21:39:02 +04:00
|
|
|
|
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
|