mirror of
https://github.com/git/git.git
synced 2026-02-22 15:51:29 +00:00
Matt Mackall introduced a revs() method to the localrepo class on Wed Nov 2 13:37:34 2011 in the commit 'localrepo: add revs helper method'. It is used when constructing a commit in memory. If we store the set of revs we want to handle under the same name, it overrides that method, resulting in an unpleasant 'TypeError: 'set' object is not callable' whenever we want to push (as we are constructing commits in memory, then). So let's work around that by renaming our field to 'revs2' and hope that upstream Mercurial does not introduce a field of that name, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
102 lines
2.6 KiB
Python
102 lines
2.6 KiB
Python
#!/usr/bin/env python
|
|
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.getenv("GITPYTHONLIB","."))
|
|
|
|
from git_remote_helpers.helper import RemoteHelper
|
|
from git_remote_helpers.util import debug, die, warn
|
|
from git_remote_helpers.hg import util
|
|
from git_remote_helpers.hg.hg import GitHg
|
|
from git_remote_helpers.hg.exporter import GitExporter
|
|
from git_remote_helpers.hg.importer import GitImporter
|
|
from git_remote_helpers.hg.non_local import NonLocalHg
|
|
|
|
|
|
class HgRemoteHelper(RemoteHelper):
|
|
def get_repo(self, alias, url):
|
|
"""Returns a hg.repository object initialized for usage.
|
|
"""
|
|
|
|
try:
|
|
from mercurial import hg, ui
|
|
except ImportError:
|
|
die("Mercurial python libraries not installed")
|
|
|
|
remote = False
|
|
|
|
if url.startswith("remote://"):
|
|
remote = True
|
|
url = "file://%s" % url[9:]
|
|
|
|
ui = ui.ui()
|
|
source, revs, checkout = util.parseurl(ui.expandpath(url), ['default'])
|
|
repo = hg.repository(ui, source)
|
|
if repo.capable('branchmap'):
|
|
revs += repo.branchmap().keys()
|
|
revs = set(revs)
|
|
|
|
prefix = 'refs/hg/%s/' % alias
|
|
debug("prefix: '%s'", prefix)
|
|
|
|
repo.marksfile = 'git.marks'
|
|
repo.hg = hg
|
|
repo.prefix = prefix
|
|
repo.revs2 = revs # must not override repo.revs()
|
|
|
|
self.setup_repo(repo, alias)
|
|
|
|
repo.git_hg = GitHg(warn)
|
|
repo.exporter = GitExporter(repo)
|
|
repo.importer = GitImporter(repo)
|
|
repo.non_local = NonLocalHg(repo)
|
|
|
|
repo.is_local = not remote and repo.local()
|
|
|
|
return repo
|
|
|
|
def local_repo(self, repo, path):
|
|
"""Returns a hg.repository object initalized for usage.
|
|
"""
|
|
|
|
local = repo.hg.repository(repo.ui, path)
|
|
|
|
self.setup_local_repo(local, repo)
|
|
|
|
local.git_hg = repo.git_hg
|
|
local.hg = repo.hg
|
|
local.revs2 = repo.revs2
|
|
local.exporter = GitExporter(local)
|
|
local.importer = GitImporter(local)
|
|
local.is_local = repo.is_local
|
|
|
|
return local
|
|
|
|
def do_list(self, repo, args):
|
|
"""Lists all known references.
|
|
"""
|
|
|
|
for ref in repo.revs2:
|
|
debug("? refs/heads/%s", ref)
|
|
print "? refs/heads/%s" % ref
|
|
|
|
debug("@refs/heads/default HEAD")
|
|
print "@refs/heads/default HEAD"
|
|
|
|
print # end list
|
|
|
|
def sanitize(self, value):
|
|
"""Cleans up the url.
|
|
"""
|
|
|
|
if value.startswith('hg::'):
|
|
value = value[4:]
|
|
|
|
return value
|
|
|
|
def get_refs(self, repo, gitdir):
|
|
return repo.branchmap()
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(HgRemoteHelper().main(sys.argv))
|