diff --git a/swh/model/identifiers.py b/swh/model/identifiers.py index 1317bd427079993d0245a6ed31764d560ffd010d..6351074abd64e9b229c18abb9cb94c3d1bd6b72d 100644 --- a/swh/model/identifiers.py +++ b/swh/model/identifiers.py @@ -269,11 +269,21 @@ def revision_identifier(revision): return hashutil.hash_git_data(b''.join(components), 'commit') +def target_type_to_git(target_type): + """Convert a software heritage target type to a git object type""" + return { + 'content': b'blob', + 'directory': b'tree', + 'revision': b'commit', + 'release': b'tag', + }[target_type] + + def release_identifier(release): """Return the intrinsic identifier for a release.""" components = [ - b'object ', identifier_to_str(release['revision']).encode(), b'\n', - b'type commit\n', + b'object ', identifier_to_str(release['target']).encode(), b'\n', + b'type ', target_type_to_git(release['target_type']), b'\n', b'tag ', release['name'].encode('utf-8'), b'\n', ] diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py index 4770fb4ff01b44519c125a1095bfaaa31ebd49d6..bd3e874f929b382e28c6c940c4fd50d5c2007fc2 100644 --- a/swh/model/tests/test_identifiers.py +++ b/swh/model/tests/test_identifiers.py @@ -291,7 +291,8 @@ class ReleaseIdentifier(unittest.TestCase): self.release = { 'id': '2b10839e32c4c476e9d94492756bb1a3e1ec4aa8', - 'revision': b't\x1b"R\xa5\xe1Ml`\xa9\x13\xc7z`\x99\xab\xe7:\x85J', + 'target': b't\x1b"R\xa5\xe1Ml`\xa9\x13\xc7z`\x99\xab\xe7:\x85J', + 'target_type': 'revision', 'name': 'v2.6.14', 'author': { 'name': b'Linus Torvalds', @@ -314,7 +315,8 @@ wdLOnvj91G4wxYqrvThthbE= self.release_no_author = { 'id': b'&y\x1a\x8b\xcf\x0em3\xf4:\xefv\x82\xbd\xb5U#mV\xde', - 'revision': '9ee1c939d1cb936b1f98e8d81aeffab57bae46ab', + 'target': '9ee1c939d1cb936b1f98e8d81aeffab57bae46ab', + 'target_type': 'revision', 'name': 'v2.6.12', 'message': b'''\ This is the final 2.6.12 release