summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-09-05 17:12:26 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-09-05 17:12:26 +0000
commitb9488584415d94fc28c2e064b917183b851af07b (patch)
treeebdb4f647c43afd633fcc5243e26ef24c6096628
parent083fd4de011e0fcf4a445b38a7fa6ef8964a5ccb (diff)
downloadmorph-b9488584415d94fc28c2e064b917183b851af07b.tar.gz
Resolve tree SHA1 along with commit SHA1 when resolving refs
Adjust all other parts and the tests to work with this.
-rwxr-xr-xmorphlib/app.py18
-rw-r--r--morphlib/artifact_tests.py2
-rw-r--r--morphlib/artifactresolver_tests.py86
-rw-r--r--morphlib/cachedrepo.py34
-rw-r--r--morphlib/cachedrepo_tests.py23
-rw-r--r--morphlib/cachekeycomputer_tests.py4
-rw-r--r--morphlib/localartifactcache_tests.py2
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py2
-rw-r--r--morphlib/plugins/update_gits_plugin.py2
-rw-r--r--morphlib/remoteartifactcache_tests.py2
-rw-r--r--morphlib/remoterepocache.py2
-rw-r--r--morphlib/source.py5
-rw-r--r--morphlib/source_tests.py9
13 files changed, 109 insertions, 82 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index 9135e440..b60a11a7 100755
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -179,8 +179,8 @@ class Morph(cliapp.Application):
def create_source_pool(self, lrc, rrc, triplet):
pool = morphlib.sourcepool.SourcePool()
- def add_to_pool(reponame, ref, filename, absref, morphology):
- source = morphlib.source.Source(reponame, ref, absref,
+ def add_to_pool(reponame, ref, filename, absref, tree, morphology):
+ source = morphlib.source.Source(reponame, ref, absref, tree,
morphology, filename)
pool.add(source)
@@ -196,7 +196,7 @@ class Morph(cliapp.Application):
return self.create_source_pool(*args)
def _resolveref(self, lrc, rrc, reponame, ref, update=True):
- '''Resolves the sha1 of the ref in reponame and returns it.
+ '''Resolves commit and tree sha1s of the ref in a repo and returns it.
If update is True then this has the side-effect of updating
or cloning the repository into the local repo cache.
@@ -209,10 +209,10 @@ class Morph(cliapp.Application):
self.status(msg='Updating cached git repository %(reponame)s',
reponame=reponame)
repo.update()
- absref = repo.resolve_ref(ref)
+ absref, tree = repo.resolve_ref(ref)
elif rrc is not None:
try:
- absref = rrc.resolve_ref(reponame, ref)
+ absref, tree = rrc.resolve_ref(reponame, ref)
except:
pass
if absref is None:
@@ -223,8 +223,8 @@ class Morph(cliapp.Application):
repo.update()
else:
repo = lrc.get_repo(reponame)
- absref = repo.resolve_ref(ref)
- return absref
+ absref, tree = repo.resolve_ref(ref)
+ return absref, tree
def traverse_morphs(self, triplets, lrc, rrc, update=True,
visit=lambda rn, rf, fn, arf, m: None):
@@ -233,10 +233,10 @@ class Morph(cliapp.Application):
while queue:
reponame, ref, filename = queue.popleft()
- absref = self._resolveref(lrc, rrc, reponame, ref, update)
+ absref, tree = self._resolveref(lrc, rrc, reponame, ref, update)
morphology = morph_factory.get_morphology(
reponame, absref, filename)
- visit(reponame, ref, filename, absref, morphology)
+ visit(reponame, ref, filename, absref, tree, morphology)
if morphology['kind'] == 'system':
queue.extend((s['repo'], s['ref'], '%s.morph' % s['morph'])
for s in morphology['strata'])
diff --git a/morphlib/artifact_tests.py b/morphlib/artifact_tests.py
index a8637fd0..1d9e6cca 100644
--- a/morphlib/artifact_tests.py
+++ b/morphlib/artifact_tests.py
@@ -41,7 +41,7 @@ class ArtifactTests(unittest.TestCase):
}
''')
self.source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
self.artifact_name = 'chunk-runtime'
self.artifact = morphlib.artifact.Artifact(
self.source, self.artifact_name)
diff --git a/morphlib/artifactresolver_tests.py b/morphlib/artifactresolver_tests.py
index 1371162c..5510b1cf 100644
--- a/morphlib/artifactresolver_tests.py
+++ b/morphlib/artifactresolver_tests.py
@@ -109,7 +109,7 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk')
source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
pool.add(source)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -126,7 +126,7 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk', ['chunk-runtime'])
source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
pool.add(source)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -142,7 +142,7 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk', ['chunk-runtime', 'chunk-devel'])
source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
pool.add(source)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -172,7 +172,7 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['foo']
stratum = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'foo.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'foo.morph')
pool.add(stratum)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -194,7 +194,7 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['foo-rootfs']
system = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'foo.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'foo.morph')
pool.add(system)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -217,7 +217,7 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['foo-rootfs', 'foo-kernel']
system = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'foo.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'foo.morph')
pool.add(system)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -234,13 +234,13 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk')
chunk = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
pool.add(chunk)
morph = FakeStratumMorphology(
'stratum', chunks=[('chunk', 'chunk', 'repo', 'ref')])
stratum = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'stratum.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph')
pool.add(stratum)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -262,7 +262,7 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk', ['chunk-devel', 'chunk-runtime'])
chunk = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
pool.add(chunk)
morph = FakeStratumMorphology(
@@ -272,7 +272,7 @@ class ArtifactResolverTests(unittest.TestCase):
('chunk-runtime', 'chunk', 'repo', 'ref')
])
stratum = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'stratum.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph')
pool.add(stratum)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -300,14 +300,14 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk', ['chunk-devel', 'chunk-runtime'])
chunk = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
pool.add(chunk)
morph = FakeStratumMorphology(
'stratum',
chunks=[('chunk-runtime', 'chunk', 'repo', 'ref')])
stratum = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'stratum.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph')
pool.add(stratum)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -329,12 +329,12 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('foo')
foo_chunk = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'foo.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'foo.morph')
pool.add(foo_chunk)
morph = FakeChunkMorphology('bar')
bar_chunk = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'bar.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'bar.morph')
pool.add(bar_chunk)
morph = FakeStratumMorphology(
@@ -344,7 +344,7 @@ class ArtifactResolverTests(unittest.TestCase):
('bar', 'bar', 'repo', 'ref')
])
stratum = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'stratum.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph')
pool.add(stratum)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -372,7 +372,7 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeStratumMorphology('stratum1')
stratum1 = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'stratum1.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'stratum1.morph')
pool.add(stratum1)
morph = FakeStratumMorphology(
@@ -380,7 +380,7 @@ class ArtifactResolverTests(unittest.TestCase):
chunks=[],
build_depends=[('stratum1', 'repo', 'ref')])
stratum2 = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'stratum2.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'stratum2.morph')
pool.add(stratum2)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -402,7 +402,7 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeStratumMorphology('stratum1')
stratum1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum1.morph')
pool.add(stratum1)
morph = FakeStratumMorphology(
@@ -413,17 +413,17 @@ class ArtifactResolverTests(unittest.TestCase):
],
build_depends=[('stratum1', 'repo', 'original/ref')])
stratum2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum2.morph')
pool.add(stratum2)
morph = FakeChunkMorphology('chunk1')
chunk1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph')
pool.add(chunk1)
morph = FakeChunkMorphology('chunk2')
chunk2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph')
pool.add(chunk2)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -458,7 +458,7 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeStratumMorphology('stratum1')
stratum1 = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'stratum1.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'stratum1.morph')
pool.add(stratum1)
morph = morphlib.morph2.Morphology(
@@ -482,13 +482,13 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['system-rootfs']
system = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'system.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'system.morph')
pool.add(system)
morph = FakeStratumMorphology(
'stratum2', chunks=[], build_depends=[('stratum1', 'repo', 'ref')])
stratum2 = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'stratum2.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'stratum2.morph')
pool.add(stratum2)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -546,22 +546,22 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['stratum']
stratum = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph')
pool.add(stratum)
morph = FakeChunkMorphology('chunk1')
chunk1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph')
pool.add(chunk1)
morph = FakeChunkMorphology('chunk2')
chunk2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph')
pool.add(chunk2)
morph = FakeChunkMorphology('chunk3')
chunk3 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk3.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk3.morph')
pool.add(chunk3)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -596,14 +596,14 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk')
chunk = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
pool.add(chunk)
morph = FakeStratumMorphology(
'stratum',
chunks=[('chunk-runtime', 'chunk', 'repo', 'ref')])
stratum = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'stratum.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph')
pool.add(stratum)
self.assertRaises(
@@ -618,7 +618,7 @@ class ArtifactResolverTests(unittest.TestCase):
chunks=[],
build_depends=[('stratum2', 'repo', 'original/ref')])
stratum1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum1.morph')
pool.add(stratum1)
morph = FakeStratumMorphology(
@@ -626,7 +626,7 @@ class ArtifactResolverTests(unittest.TestCase):
chunks=[],
build_depends=[('stratum1', 'repo', 'original/ref')])
stratum2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum2.morph')
pool.add(stratum2)
self.assertRaises(morphlib.artifactresolver.MutualDependencyError,
@@ -642,7 +642,7 @@ class ArtifactResolverTests(unittest.TestCase):
('chunk2', 'chunk2', 'repo', 'original/ref')
])
stratum1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum1.morph')
pool.add(stratum1)
morph = FakeStratumMorphology(
@@ -653,17 +653,17 @@ class ArtifactResolverTests(unittest.TestCase):
],
build_depends=[('stratum1', 'repo', 'original/ref')])
stratum2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum2.morph')
pool.add(stratum2)
morph = FakeChunkMorphology('chunk1')
chunk1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph')
pool.add(chunk1)
morph = FakeChunkMorphology('chunk2')
chunk2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph')
pool.add(chunk2)
self.assertRaises(morphlib.artifactresolver.MutualDependencyError,
@@ -701,12 +701,12 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['stratum']
stratum = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph')
pool.add(stratum)
morph = FakeChunkMorphology('chunk')
chunk = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk.morph')
pool.add(chunk)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -750,17 +750,17 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['stratum']
stratum = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph')
pool.add(stratum)
morph = FakeChunkMorphology('chunk1')
chunk1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph')
pool.add(chunk1)
morph = FakeChunkMorphology('chunk2')
chunk2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph')
pool.add(chunk2)
self.assertRaises(morphlib.artifactresolver.DependencyOrderError,
@@ -786,12 +786,12 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['stratum']
stratum = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'stratum.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph')
pool.add(stratum)
morph = FakeChunkMorphology('chunk')
chunk = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk.morph')
pool.add(chunk)
self.assertRaises(morphlib.artifactresolver.DependencyFormatError,
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py
index f647102f..eef49ffb 100644
--- a/morphlib/cachedrepo.py
+++ b/morphlib/cachedrepo.py
@@ -91,27 +91,29 @@ class CachedRepo(object):
return len(ref) == 40 and all([x in valid_chars for x in ref])
def resolve_ref(self, ref):
- '''Attempts to resolve a Git ref into its corresponding SHA1.
+ '''Attempts to resolve a ref into its SHA1 and tree SHA1.
Raises an InvalidReferenceError if the ref is not found in the
repository.
'''
- try:
- refs = self._show_ref(ref).split('\n')
- # split each ref line into an array, drop non-origin branches
- refs = [x.split() for x in refs if 'origin' in x]
- return refs[0][0]
- except cliapp.AppException:
- pass
-
if not self.is_valid_sha1(ref):
- raise InvalidReferenceError(self, ref)
- try:
- return self._rev_list(ref).strip()
- except cliapp.AppException:
- raise InvalidReferenceError(self, ref)
+ try:
+ refs = self._show_ref(ref).split('\n')
+ # split each ref line into an array, drop non-origin branches
+ refs = [x.split() for x in refs if 'origin' in x]
+ absref = refs[0][0]
+ except cliapp.AppException:
+ raise InvalidReferenceError(self, ref)
+ else:
+ try:
+ absref = self._rev_list(ref).strip()
+ except cliapp.AppException:
+ raise InvalidReferenceError(self, ref)
+
+ tree = self._show_tree_hash(absref)
+ return absref, tree
def cat(self, ref, filename):
'''Attempts to read a file given a SHA1 ref.
@@ -197,6 +199,10 @@ class CachedRepo(object):
def _show_ref(self, ref): # pragma: no cover
return self._runcmd(['git', 'show-ref', ref])
+ def _show_tree_hash(self, absref): # pragma: no cover
+ return self._runcmd(
+ ['git', 'log', '-1', '--format=format:%T', absref]).strip()
+
def _rev_list(self, ref): # pragma: no cover
return self._runcmd(['git', 'rev-list', '--no-walk', ref])
diff --git a/morphlib/cachedrepo_tests.py b/morphlib/cachedrepo_tests.py
index fa660010..14c5daac 100644
--- a/morphlib/cachedrepo_tests.py
+++ b/morphlib/cachedrepo_tests.py
@@ -40,6 +40,19 @@ class CachedRepoTests(unittest.TestCase):
except:
raise cliapp.AppException('git show-ref %s' % ref)
+ def show_tree_hash(self, absref):
+ output = {
+ 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9':
+ 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
+ '8b780e2e6f102fcf400ff973396566d36d730501':
+ 'ffffffffffffffffffffffffffffffffffffffff'
+ }
+ try:
+ return output[absref]
+ except:
+ raise cliapp.AppException('git log -1 --format=format:%T %s' %
+ absref)
+
def rev_list(self, ref):
output = {
'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9':
@@ -102,6 +115,7 @@ class CachedRepoTests(unittest.TestCase):
self.repo = cachedrepo.CachedRepo(
object(), self.repo_name, self.repo_url, self.repo_path)
self.repo._show_ref = self.show_ref
+ self.repo._show_tree_hash = self.show_tree_hash
self.repo._rev_list = self.rev_list
self.repo._cat_file = self.cat_file
self.repo._copy_repository = self.copy_repository
@@ -118,21 +132,24 @@ class CachedRepoTests(unittest.TestCase):
self.assertEqual(self.repo.path, self.repo_path)
def test_resolve_named_ref_master(self):
- sha1 = self.repo.resolve_ref('master')
+ sha1, tree = self.repo.resolve_ref('master')
self.assertEqual(sha1, 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
+ self.assertEqual(tree, 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee')
def test_resolve_named_ref_baserock_morph(self):
- sha1 = self.repo.resolve_ref('baserock/morph')
+ sha1, tree = self.repo.resolve_ref('baserock/morph')
self.assertEqual(sha1, '8b780e2e6f102fcf400ff973396566d36d730501')
+ self.assertEqual(tree, 'ffffffffffffffffffffffffffffffffffffffff')
def test_fail_resolving_invalid_named_ref(self):
self.assertRaises(cachedrepo.InvalidReferenceError,
self.repo.resolve_ref, 'foo/bar')
def test_resolve_sha1_ref(self):
- sha1 = self.repo.resolve_ref(
+ sha1, tree = self.repo.resolve_ref(
'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
self.assertEqual(sha1, 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
+ self.assertEqual(tree, 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee')
def test_fail_resolving_an_invalid_sha1_ref(self):
self.assertRaises(cachedrepo.InvalidReferenceError,
diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py
index 7ace9c36..7077a313 100644
--- a/morphlib/cachekeycomputer_tests.py
+++ b/morphlib/cachekeycomputer_tests.py
@@ -91,7 +91,7 @@ class CacheKeyComputerTests(unittest.TestCase):
}''',
}.iteritems():
source = morphlib.source.Source(
- 'repo', 'original/ref', 'sha',
+ 'repo', 'original/ref', 'sha', 'tree',
morphlib.morph2.Morphology(text), name)
self.source_pool.add(source)
# FIXME: This should use MorphologyFactory
@@ -171,7 +171,7 @@ class CacheKeyComputerTests(unittest.TestCase):
old_artifact = self._find_artifact('system-rootfs')
morphology = old_artifact.source.morphology
new_source = morphlib.source.Source('repo', 'original/ref', 'newsha',
- morphology,
+ 'tree', morphology,
old_artifact.source.filename)
self.source_pool.add(new_source)
artifacts = self.artifact_resolver.resolve_artifacts(self.source_pool)
diff --git a/morphlib/localartifactcache_tests.py b/morphlib/localartifactcache_tests.py
index aacba8fb..c3deb9dc 100644
--- a/morphlib/localartifactcache_tests.py
+++ b/morphlib/localartifactcache_tests.py
@@ -43,7 +43,7 @@ class LocalArtifactCacheTests(unittest.TestCase):
}
''')
self.source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
self.runtime_artifact = morphlib.artifact.Artifact(
self.source, 'chunk-runtime')
self.devel_artifact = morphlib.artifact.Artifact(
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index e7294cc7..07f1a154 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -306,7 +306,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
ref=ref)
assert cache.has_repo(reponame)
repo = cache.get_repo(reponame)
- source['ref'] = repo.resolve_ref(ref)
+ source['ref'], tree = repo.resolve_ref(ref)
self.write_morphology(filename, morph)
diff --git a/morphlib/plugins/update_gits_plugin.py b/morphlib/plugins/update_gits_plugin.py
index ac7beaa8..92a687a3 100644
--- a/morphlib/plugins/update_gits_plugin.py
+++ b/morphlib/plugins/update_gits_plugin.py
@@ -51,7 +51,7 @@ class UpdateGitsPlugin(cliapp.Plugin):
subs_to_process = set()
- def visit(reponame, ref, filename, absref, morphology):
+ def visit(reponame, ref, filename, absref, tree, morphology):
app.status(msg='Updating %(repo_name)s %(ref)s %(filename)s',
repo_name=reponame, ref=ref, filename=filename)
assert cache.has_repo(reponame)
diff --git a/morphlib/remoteartifactcache_tests.py b/morphlib/remoteartifactcache_tests.py
index d77f8f53..a4ec9370 100644
--- a/morphlib/remoteartifactcache_tests.py
+++ b/morphlib/remoteartifactcache_tests.py
@@ -46,7 +46,7 @@ class RemoteArtifactCacheTests(unittest.TestCase):
}
''')
self.source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
self.runtime_artifact = morphlib.artifact.Artifact(
self.source, 'chunk-runtime')
self.runtime_artifact.cache_key = 'CHUNK-RUNTIME'
diff --git a/morphlib/remoterepocache.py b/morphlib/remoterepocache.py
index c40057b1..5c2017de 100644
--- a/morphlib/remoterepocache.py
+++ b/morphlib/remoterepocache.py
@@ -74,7 +74,7 @@ class RemoteRepoCache(object):
def _resolve_ref_for_repo_url(self, repo_url, ref): # pragma: no cover
data = self._make_request('sha1s?repo=%s&ref=%s' % (repo_url, ref))
info = json.loads(data)
- return info['sha1']
+ return info['sha1'], info['tree']
def _cat_file_for_repo_url(self, repo_url, ref,
filename): # pragma: no cover
diff --git a/morphlib/source.py b/morphlib/source.py
index fceed9ef..ed62ea4a 100644
--- a/morphlib/source.py
+++ b/morphlib/source.py
@@ -27,6 +27,7 @@ class Source(object):
* ``repo_name`` -- name of the git repository which contains the source
* ``original_ref`` -- the git ref provided by the user or a morphology
* ``sha1`` -- the absolute git commit id for the revision we use
+ * ``tree`` -- the SHA1 of the tree corresponding to the commit
* ``morphology`` -- the in-memory representation of the morphology we use
* ``filename`` -- basename of the morphology filename
* ``dependencies`` -- list of Sources for build dependencies for us
@@ -37,11 +38,13 @@ class Source(object):
'''
- def __init__(self, repo_name, original_ref, sha1, morphology, filename):
+ def __init__(self, repo_name, original_ref, sha1, tree, morphology,
+ filename):
self.repo = None
self.repo_name = repo_name
self.original_ref = original_ref
self.sha1 = sha1
+ self.tree = tree
self.morphology = morphology
self.filename = filename
diff --git a/morphlib/source_tests.py b/morphlib/source_tests.py
index 7ad5d370..6643f0fc 100644
--- a/morphlib/source_tests.py
+++ b/morphlib/source_tests.py
@@ -32,14 +32,15 @@ class SourceTests(unittest.TestCase):
self.repo_name = 'foo.repo'
self.original_ref = 'original/ref'
self.sha1 = 'CAFEF00D'
+ self.tree = 'F000000D'
self.morphology = morphlib.morph2.Morphology(self.morphology_text)
self.filename = 'foo.morph'
self.source = morphlib.source.Source(
- self.repo_name, self.original_ref, self.sha1, self.morphology,
- self.filename)
+ self.repo_name, self.original_ref, self.sha1, self.tree,
+ self.morphology, self.filename)
self.other = morphlib.source.Source(
- self.repo_name, self.original_ref, self.sha1, self.morphology,
- self.filename)
+ self.repo_name, self.original_ref, self.sha1, self.tree,
+ self.morphology, self.filename)
def test_sets_repo_name(self):
self.assertEqual(self.source.repo_name, self.repo_name)