mirror of
https://github.com/mnauw/git-remote-hg.git
synced 2025-10-26 06:06:06 +01:00
Update loading source file as module
This commit is contained in:
@@ -97,11 +97,27 @@ def debug(msg, *args):
|
|||||||
def log(msg, *args):
|
def log(msg, *args):
|
||||||
logger.log(logging.LOG, msg, *args)
|
logger.log(logging.LOG, msg, *args)
|
||||||
|
|
||||||
|
# new style way to import a source file
|
||||||
|
def _imp_load_source(module_name, file_path):
|
||||||
|
import importlib.util
|
||||||
|
loader = importlib.machinery.SourceFileLoader(module_name, file_path)
|
||||||
|
spec = importlib.util.spec_from_loader(module_name, loader)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
sys.modules[module_name] = module
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
|
||||||
def import_sibling(mod, filename):
|
def import_sibling(mod, filename):
|
||||||
import imp
|
|
||||||
mydir = os.path.dirname(__file__)
|
mydir = os.path.dirname(__file__)
|
||||||
sys.dont_write_bytecode = True
|
sys.dont_write_bytecode = True
|
||||||
return imp.load_source(mod, os.path.join(mydir, filename))
|
vi = sys.version_info
|
||||||
|
ff = os.path.join(mydir, filename)
|
||||||
|
if vi.major >= 3 and vi.minor >= 5:
|
||||||
|
return _imp_load_source(mod, ff)
|
||||||
|
else:
|
||||||
|
import imp
|
||||||
|
return imp.load_source(mod, ff)
|
||||||
|
|
||||||
|
|
||||||
class GitHgRepo:
|
class GitHgRepo:
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,27 @@ else:
|
|||||||
urlparse = staticmethod(_urlparse)
|
urlparse = staticmethod(_urlparse)
|
||||||
urljoin = staticmethod(_urljoin)
|
urljoin = staticmethod(_urljoin)
|
||||||
|
|
||||||
|
# new style way to import a source file
|
||||||
|
def _imp_load_source(module_name, file_path):
|
||||||
|
import importlib.util
|
||||||
|
loader = importlib.machinery.SourceFileLoader(module_name, file_path)
|
||||||
|
spec = importlib.util.spec_from_loader(module_name, loader)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
sys.modules[module_name] = module
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
|
||||||
|
def import_sibling(mod, filename):
|
||||||
|
mydir = os.path.dirname(__file__)
|
||||||
|
sys.dont_write_bytecode = True
|
||||||
|
vi = sys.version_info
|
||||||
|
ff = os.path.join(mydir, filename)
|
||||||
|
if vi.major >= 3 and vi.minor >= 5:
|
||||||
|
return _imp_load_source(mod, ff)
|
||||||
|
else:
|
||||||
|
import imp
|
||||||
|
return imp.load_source(mod, ff)
|
||||||
|
|
||||||
#
|
#
|
||||||
# If you want to see Mercurial revisions as Git commit notes:
|
# If you want to see Mercurial revisions as Git commit notes:
|
||||||
# git config core.notesRef refs/notes/hg
|
# git config core.notesRef refs/notes/hg
|
||||||
@@ -1609,10 +1630,7 @@ def do_push_refspec(parser, refspec, revs):
|
|||||||
tmpfastexport = open(os.path.join(marksdir, b'git-fast-export-%d' % (os.getpid())), 'w+b')
|
tmpfastexport = open(os.path.join(marksdir, b'git-fast-export-%d' % (os.getpid())), 'w+b')
|
||||||
subprocess.check_call(cmd, stdin=None, stdout=tmpfastexport)
|
subprocess.check_call(cmd, stdin=None, stdout=tmpfastexport)
|
||||||
try:
|
try:
|
||||||
import imp
|
ctx.hghelper = import_sibling('hghelper', 'git-hg-helper')
|
||||||
sys.dont_write_bytecode = True
|
|
||||||
ctx.hghelper = imp.load_source('hghelper', \
|
|
||||||
os.path.join(os.path.dirname(__file__), 'git-hg-helper'))
|
|
||||||
ctx.hghelper.init_git(gitdir)
|
ctx.hghelper.init_git(gitdir)
|
||||||
ctx.gitmarks = ctx.hghelper.GitMarks(tmpmarks)
|
ctx.gitmarks = ctx.hghelper.GitMarks(tmpmarks)
|
||||||
# let processing know it should not bother pushing if not requested
|
# let processing know it should not bother pushing if not requested
|
||||||
|
|||||||
Reference in New Issue
Block a user