7aeaa2fc0a
Currently the remote helper infrastructure is only used by the curl helper, which does not give a good impression of how remote helpers can be used to interact with foreign repositories. Since implementing such a helper is non-trivial it would be good to have at least one easy-to-follow example demonstrating how to implement a helper that interacts with a foreign vcs using fast-import/fast-export. The testgit helper can be used to interact with remote git repositories by prefixing the url with "testgit::". Signed-off-by: Junio C Hamano <gitster@pobox.com>
39 lines
1006 B
Python
39 lines
1006 B
Python
import os
|
|
import subprocess
|
|
|
|
|
|
class GitImporter(object):
|
|
"""An importer for testgit repositories.
|
|
|
|
This importer simply delegates to git fast-import.
|
|
"""
|
|
|
|
def __init__(self, repo):
|
|
"""Creates a new importer for the specified repo.
|
|
"""
|
|
|
|
self.repo = repo
|
|
|
|
def do_import(self, base):
|
|
"""Imports a fast-import stream to the given directory.
|
|
|
|
Simply delegates to git fast-import.
|
|
"""
|
|
|
|
dirname = self.repo.get_base_path(base)
|
|
if self.repo.local:
|
|
gitdir = self.repo.gitpath
|
|
else:
|
|
gitdir = os.path.abspath(os.path.join(dirname, '.git'))
|
|
path = os.path.abspath(os.path.join(dirname, 'git.marks'))
|
|
|
|
if not os.path.exists(dirname):
|
|
os.makedirs(dirname)
|
|
|
|
args = ["git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path]
|
|
|
|
if os.path.exists(path):
|
|
args.append("--import-marks=" + path)
|
|
|
|
subprocess.check_call(args)
|