mirror of
https://github.com/git/git.git
synced 2026-02-13 11:21:10 +00:00
git-remote-hg: add GitExporter/GitImporter/NonLocalGit
This is inftrastructure required to implement git-remote-hg.
This commit is contained in:
committed by
Pat Thoyts
parent
a364defb60
commit
64dd19ab54
0
git_remote_helpers/hg/__init__.py
Normal file
0
git_remote_helpers/hg/__init__.py
Normal file
29
git_remote_helpers/hg/exporter.py
Normal file
29
git_remote_helpers/hg/exporter.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import binascii
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
from git_remote_helpers.hg import hgexport
|
||||
|
||||
|
||||
class GitExporter(object):
|
||||
def __init__(self, repo):
|
||||
self.repo = repo
|
||||
|
||||
def export_repo(self, base, refs):
|
||||
gitmarksfile = os.path.join(self.repo.hash, 'git.marks')
|
||||
|
||||
exporter = hgexport.HgExportGenerator(self.repo)
|
||||
|
||||
exporter.feature_relative_marks()
|
||||
exporter.feature_export_marks(gitmarksfile)
|
||||
|
||||
dirname = self.repo.get_base_path(base)
|
||||
path = os.path.abspath(os.path.join(dirname, 'git.marks'))
|
||||
|
||||
if os.path.exists(path):
|
||||
exporter.feature_import_marks(gitmarksfile)
|
||||
exporter.read_marks(base)
|
||||
|
||||
exporter.export_repo(refs)
|
||||
|
||||
exporter.write_marks(base)
|
||||
29
git_remote_helpers/hg/importer.py
Normal file
29
git_remote_helpers/hg/importer.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
from git_remote_helpers.hg import hgimport
|
||||
from git_remote_helpers.fastimport import processor, parser
|
||||
|
||||
|
||||
class GitImporter(object):
|
||||
def __init__(self, repo):
|
||||
self.repo = repo
|
||||
|
||||
def do_import(self, base):
|
||||
sources = ["-"]
|
||||
|
||||
dirname = self.repo.get_base_path(base)
|
||||
|
||||
if not os.path.exists(dirname):
|
||||
os.makedirs(dirname)
|
||||
|
||||
procc = hgimport.HgImportProcessor(self.repo.ui, self.repo)
|
||||
|
||||
marks_file = os.path.abspath(os.path.join(dirname, 'hg.marks'))
|
||||
|
||||
if os.path.exists(marks_file):
|
||||
procc.load_marksfile(marks_file)
|
||||
|
||||
processor.parseMany(sources, parser.ImportParser, procc)
|
||||
|
||||
procc.write_marksfile(marks_file)
|
||||
51
git_remote_helpers/hg/non_local.py
Normal file
51
git_remote_helpers/hg/non_local.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
|
||||
from git_remote_helpers.util import die, warn
|
||||
|
||||
class NonLocalHg(object):
|
||||
def __init__(self, repo):
|
||||
self.repo = repo
|
||||
self.hg = repo.hg
|
||||
|
||||
def clone(self, base):
|
||||
path = self.repo.get_base_path(base)
|
||||
|
||||
# already cloned
|
||||
if os.path.exists(os.path.join(path, '.hg')):
|
||||
return path
|
||||
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
|
||||
if self.repo.path.endswith(".hg"):
|
||||
from_path = self.repo.path[:-3]
|
||||
else:
|
||||
from_path = self.repo.path
|
||||
|
||||
self.repo.ui.setconfig('ui', 'quiet', "true")
|
||||
self.hg.clone(self.repo.ui, from_path, path, update=False, pull=True)
|
||||
|
||||
return path
|
||||
|
||||
def update(self, base):
|
||||
path = self.repo.get_base_path(base)
|
||||
|
||||
if not os.path.exists(path):
|
||||
die("could not find repo at %s", path)
|
||||
|
||||
repo = self.hg.repository(self.repo.ui, path)
|
||||
|
||||
repo.ui.setconfig('ui', 'quiet', "true")
|
||||
repo.pull(self.repo, heads=self.repo.heads(), force=True)
|
||||
|
||||
def push(self, base):
|
||||
path = self.repo.get_base_path(base)
|
||||
|
||||
if not os.path.exists(path):
|
||||
die("could not find repo at %s", path)
|
||||
|
||||
repo = self.hg.repository(self.repo.ui, path)
|
||||
|
||||
self.repo.ui.setconfig('ui', 'quiet', "true")
|
||||
repo.ui.setconfig('ui', 'quiet', "true")
|
||||
repo.push(self.repo, force=False)
|
||||
14
git_remote_helpers/hg/util.py
Normal file
14
git_remote_helpers/hg/util.py
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from mercurial import hg
|
||||
|
||||
def parseurl(url, heads=[]):
|
||||
url, heads = hg.parseurl(url, heads)
|
||||
if isinstance(heads, tuple) and len(heads) == 2:
|
||||
# hg 1.6 or later
|
||||
_junk, heads = heads
|
||||
if heads:
|
||||
checkout = heads[0]
|
||||
else:
|
||||
checkout = None
|
||||
return url, heads, checkout
|
||||
Reference in New Issue
Block a user