summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/cachekeycomputer.py8
-rw-r--r--morphlib/cachekeycomputer_tests.py18
-rw-r--r--morphlib/sourcepool.py5
3 files changed, 27 insertions, 4 deletions
diff --git a/morphlib/cachekeycomputer.py b/morphlib/cachekeycomputer.py
index a11334e3..a4ea10ed 100644
--- a/morphlib/cachekeycomputer.py
+++ b/morphlib/cachekeycomputer.py
@@ -91,6 +91,14 @@ class CacheKeyComputer(object):
elif kind in ('system', 'stratum'):
morphology = artifact.source.morphology
le_dict = dict((k, morphology[k]) for k in morphology.keys())
+
+ # Disregard all fields of a morphology that aren't important
+ ignored_fields = ('strata', 'build-depends', 'description',
+ 'chunks')
+ for ignored_field in ignored_fields:
+ if ignored_field in le_dict:
+ del le_dict[ignored_field]
+
checksum = hashlib.sha1()
self._hash_thing(checksum, le_dict)
keys['morphology-sha1'] = checksum.hexdigest()
diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py
index 7077a313..411ad3f5 100644
--- a/morphlib/cachekeycomputer_tests.py
+++ b/morphlib/cachekeycomputer_tests.py
@@ -173,8 +173,13 @@ class CacheKeyComputerTests(unittest.TestCase):
new_source = morphlib.source.Source('repo', 'original/ref', 'newsha',
'tree', morphology,
old_artifact.source.filename)
- self.source_pool.add(new_source)
- artifacts = self.artifact_resolver.resolve_artifacts(self.source_pool)
+ sp = morphlib.sourcepool.SourcePool()
+ for source in self.source_pool:
+ if source == old_artifact.source:
+ sp.add(new_source)
+ else:
+ sp.add(source)
+ artifacts = self.artifact_resolver.resolve_artifacts(sp)
for new_artifact in artifacts:
if new_artifact.source == new_source:
break
@@ -184,3 +189,12 @@ class CacheKeyComputerTests(unittest.TestCase):
old_sha = self.ckc.compute_key(old_artifact)
new_sha = self.ckc.compute_key(new_artifact)
self.assertEqual(old_sha, new_sha)
+
+ def test_same_morphology_added_to_source_pool_only_appears_once(self):
+ src = morphlib.source.Source('repo', 'original/ref', 'sha', 'tree',
+ '{"name": "chunk", "kind": "chunk"}',
+ 'chunk.morph')
+ sp = morphlib.sourcepool.SourcePool()
+ sp.add(src)
+ sp.add(src)
+ self.assertEqual(1, len([s for s in sp if s == src]))
diff --git a/morphlib/sourcepool.py b/morphlib/sourcepool.py
index ef21ba5a..ec134c0a 100644
--- a/morphlib/sourcepool.py
+++ b/morphlib/sourcepool.py
@@ -30,8 +30,9 @@ class SourcePool(object):
key = self._key(source.repo_name,
source.original_ref,
source.filename)
- self._sources[key] = source
- self._order.append(source)
+ if key not in self._sources:
+ self._sources[key] = source
+ self._order.append(source)
def lookup(self, repo_name, original_ref, filename):
'''Find a source in the pool.