Commit 314e9a61 authored by Tristan Gingold's avatar Tristan Gingold

git.py: minor refactoring.

parent a2c8a6df
...@@ -38,20 +38,7 @@ class Git(Fetcher): ...@@ -38,20 +38,7 @@ class Git(Fetcher):
def __init__(self): def __init__(self):
self.submodule = False self.submodule = False
@staticmethod def get_submodule_commit(self, submodule_dir):
def get_git_toplevel(module):
"""Get the top level for the Git repository"""
cur_dir = os.getcwd()
try:
os.chdir(path_utils.rel2abs(module.path))
if not os.path.exists(".gitmodules"):
return None
return shell.run("git rev-parse --show-toplevel")
finally:
os.chdir(cur_dir)
@staticmethod
def get_submodule_commit(submodule_dir):
"""Get the commit for a repository if defined in Git submodules""" """Get the commit for a repository if defined in Git submodules"""
status_line = shell.run("git submodule status %s" % submodule_dir) status_line = shell.run("git submodule status %s" % submodule_dir)
status_line = status_line.split() status_line = status_line.split()
...@@ -99,8 +86,24 @@ class Git(Fetcher): ...@@ -99,8 +86,24 @@ class Git(Fetcher):
module.path = mod_path module.path = mod_path
return True return True
@staticmethod
def get_git_submodules(module): class GitSM(Git):
def __init__(self):
self.submodule = True
def get_git_toplevel(module):
"""Get the top level for the Git repository"""
cur_dir = os.getcwd()
try:
os.chdir(path_utils.rel2abs(module.path))
if not os.path.exists(".gitmodules"):
return None
return shell.run("git rev-parse --show-toplevel")
finally:
os.chdir(cur_dir)
def get_git_submodules(module):
"""Get a dictionary containing the git submodules """Get a dictionary containing the git submodules
that are listed in the module's path""" that are listed in the module's path"""
submodule_dir = path_utils.rel2abs(module.path) submodule_dir = path_utils.rel2abs(module.path)
...@@ -112,7 +115,6 @@ class Git(Fetcher): ...@@ -112,7 +115,6 @@ class Git(Fetcher):
cur_dir = os.getcwd() cur_dir = os.getcwd()
try: try:
os.chdir(submodule_dir) os.chdir(submodule_dir)
if not os.path.exists(".gitmodules"): if not os.path.exists(".gitmodules"):
return {} return {}
config_submodules = {} config_submodules = {}
...@@ -134,7 +136,6 @@ class Git(Fetcher): ...@@ -134,7 +136,6 @@ class Git(Fetcher):
if module_name not in config_submodules: if module_name not in config_submodules:
config_submodules[module_name] = {} config_submodules[module_name] = {}
config_submodules[module_name][lhs_split[-1]] = rhs config_submodules[module_name][lhs_split[-1]] = rhs
if len(list(config_submodules)) > 0: if len(list(config_submodules)) > 0:
logging.info("Found git submodules in %s: %s", logging.info("Found git submodules in %s: %s",
module.path, str(config_submodules)) module.path, str(config_submodules))
...@@ -142,8 +143,3 @@ class Git(Fetcher): ...@@ -142,8 +143,3 @@ class Git(Fetcher):
os.chdir(cur_dir) os.chdir(cur_dir)
return config_submodules return config_submodules
class GitSM(Git):
def __init__(self):
self.submodule = True
...@@ -34,7 +34,7 @@ import logging ...@@ -34,7 +34,7 @@ import logging
from ..util import path as path_mod from ..util import path as path_mod
from ..util import shell from ..util import shell
from ..fetch.git import Git from ..fetch import git
from ..manifest_parser.manifestparser import ManifestParser from ..manifest_parser.manifestparser import ManifestParser
import six import six
...@@ -264,8 +264,8 @@ class Module(object): ...@@ -264,8 +264,8 @@ class Module(object):
"""Get the submodules if found in the Manifest path""" """Get the submodules if found in the Manifest path"""
if not self.source == 'gitsm': if not self.source == 'gitsm':
return return
git_submodule_dict = Git.get_git_submodules(self) git_submodule_dict = git.get_git_submodules(self)
git_toplevel = Git.get_git_toplevel(self) git_toplevel = git.get_git_toplevel(self)
for submodule_key in git_submodule_dict.keys(): for submodule_key in git_submodule_dict.keys():
url = git_submodule_dict[submodule_key]["url"] url = git_submodule_dict[submodule_key]["url"]
path = git_submodule_dict[submodule_key]["path"] path = git_submodule_dict[submodule_key]["path"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment