git-remote-hg: add the helper

The helper uses the previously added infrastructure.
This commit is contained in:
Sverre Rabbelier
2011-07-24 12:38:57 +02:00
committed by Johannes Schindelin
parent a5cc7703e7
commit 2ec3a3e945
4 changed files with 104 additions and 1 deletions

1
.gitignore vendored
View File

@@ -119,6 +119,7 @@
/git-remote-fd
/git-remote-ext
/git-remote-testgit
/git-remote-hg
/git-repack
/git-replace
/git-repo-config

View File

@@ -443,6 +443,7 @@ SCRIPT_PERL += git-send-email.perl
SCRIPT_PERL += git-svn.perl
SCRIPT_PYTHON += git-remote-testgit.py
SCRIPT_PYTHON += git-remote-hg.py
SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
$(patsubst %.perl,%,$(SCRIPT_PERL)) \

101
git-remote-hg.py Normal file
View File

@@ -0,0 +1,101 @@
#!/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.revs = 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.revs = repo.revs
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.revs:
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))

View File

@@ -14,5 +14,5 @@ setup(
url = 'http://www.git-scm.com/',
package_dir = {'git_remote_helpers': ''},
packages = ['git_remote_helpers', 'git_remote_helpers.git',
'git_remote_helpers.fastimport'],
'git_remote_helpers.fastimport', 'git_remote_helpers.hg'],
)