diff options
author | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2015-11-20 13:57:31 +0000 |
---|---|---|
committer | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2016-03-25 21:02:33 +0000 |
commit | ddb8b27d5056074013a89d8ab277e39fdc1f069d (patch) | |
tree | 5ecf61560608dbea1ec1895e5cff2622959556b7 /morphlib/git.py | |
parent | 9404317020ff0455cbfd3ca7976d546af823759b (diff) | |
download | morph-ddb8b27d5056074013a89d8ab277e39fdc1f069d.tar.gz |
WIP Add support for multiple sources per chunk
TODO:
- Add API to the cache server to retrieve a submodule commit from a
given path.
- Fix cross-bootstrap command.
Change-Id: I3475c2bcb648a272fee33bc878a521f79d4e6581
Diffstat (limited to 'morphlib/git.py')
-rw-r--r-- | morphlib/git.py | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/morphlib/git.py b/morphlib/git.py index cab551ef..12c24b0e 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -34,11 +34,17 @@ class NoModulesFileError(cliapp.AppException): class Submodule(object): - def __init__(self, name, url, path): + def __init__(self, name, url, sha1, path): self.name = name self.url = url + self.commit = sha1 self.path = path + def __str__(self): + return "{name}|{url}|{path}".format(name=self.name, + url=self.url, + path=self.path) + class InvalidSectionError(cliapp.AppException): @@ -48,14 +54,6 @@ class InvalidSectionError(cliapp.AppException): 'title: [%s]' % (repo, ref, section)) -class MissingSubmoduleCommitError(cliapp.AppException): - - def __init__(self, repo, ref, submodule): - Exception.__init__(self, - '%s:%s:.gitmodules: No commit object found for ' - 'submodule "%s"' % (repo, ref, submodule)) - - class Submodules(object): def __init__(self, repo, ref, runcmd_cb=cliapp.runcmd): @@ -87,6 +85,7 @@ class Submodules(object): raise NoModulesFileError(self.repo, self.ref) def _validate_and_read_entries(self, parser): + gd = morphlib.gitdir.GitDirectory(self.repo) for section in parser.sections(): # validate section name against the 'section "foo"' pattern section_pattern = r'submodule "(.*)"' @@ -97,33 +96,9 @@ class Submodules(object): path = parser.get(section, 'path') # create a submodule object - submodule = Submodule(name, url, path) - try: - # list objects in the parent repo tree to find the commit - # object that corresponds to the submodule - commit = gitcmd(self.runcmd_cb, 'ls-tree', self.ref, - submodule.path, cwd=self.repo) - - # read the commit hash from the output - fields = commit.split() - if len(fields) >= 2 and fields[1] == 'commit': - submodule.commit = commit.split()[2] - - # fail if the commit hash is invalid - if len(submodule.commit) != 40: - raise MissingSubmoduleCommitError(self.repo, - self.ref, - submodule.name) - - # add a submodule object to the list - self.submodules.append(submodule) - else: - logging.warning('Skipping submodule "%s" as %s:%s has ' - 'a non-commit object for it' % - (submodule.name, self.repo, self.ref)) - except cliapp.AppException: - raise MissingSubmoduleCommitError(self.repo, self.ref, - submodule.name) + sha1 = gd.get_submodule_commit(self.ref, path) + submodule = Submodule(name, url, sha1, path) + self.submodules.append(submodule) else: raise InvalidSectionError(self.repo, self.ref, section) |