diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d0b93d3ef3b7b668a3af55e06387d8e9621f979b..1c95e3d8dd307abb21417e98468a4654b1484014 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,9 +18,6 @@ repos: - id: codespell name: Check source code spelling stages: [commit] - - id: codespell - name: Check commit message spelling - stages: [commit-msg] - repo: local hooks: diff --git a/PKG-INFO b/PKG-INFO index e632705835d28ab0c69182917cc6434d1178dbd5..8b07a8646a12e0deea6602ffbc3799cffea8eba5 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: swh.model -Version: 6.1.0 +Version: 6.2.0 Summary: Software Heritage data model Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Author: Software Heritage developers diff --git a/swh.model.egg-info/PKG-INFO b/swh.model.egg-info/PKG-INFO index e632705835d28ab0c69182917cc6434d1178dbd5..8b07a8646a12e0deea6602ffbc3799cffea8eba5 100644 --- a/swh.model.egg-info/PKG-INFO +++ b/swh.model.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: swh.model -Version: 6.1.0 +Version: 6.2.0 Summary: Software Heritage data model Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Author: Software Heritage developers diff --git a/swh/model/git_objects.py b/swh/model/git_objects.py index d0f7bf8481d564729a989267386ee0aa295d4e3b..566aaa364b1823cbce01163d0f6dae9d7d891410 100644 --- a/swh/model/git_objects.py +++ b/swh/model/git_objects.py @@ -39,6 +39,19 @@ from .collections import ImmutableDict from .hashutil import git_object_header, hash_to_bytehex +def content_git_object(content: model.Content) -> bytes: + """Formats a content as a git blob. + + A content's identifier is the blob sha1 Ã la git of the tagged content. + """ + content = cast(model.Content, content) + + if content.data is None: + raise model.MissingData("Content data is None, cannot format.") + + return git_object_header("blob", len(content.data)) + content.data + + def directory_entry_sort_key(entry: model.DirectoryEntry): """The sorting key for tree entries""" if isinstance(entry, dict): diff --git a/swh/model/tests/test_model.py b/swh/model/tests/test_model.py index 8c058b91541d75fc302c48108133470e8c46ac32..590e4b4a2e59ec0c51f3766e10d64aabbdaff943 100644 --- a/swh/model/tests/test_model.py +++ b/swh/model/tests/test_model.py @@ -841,6 +841,14 @@ def test_content_naive_datetime(): ) +@given(strategies.present_contents().filter(lambda cnt: cnt.data is not None)) +def test_content_git_roundtrip(content): + assert content.data is not None + raw = swh.model.git_objects.content_git_object(content) + sha1_git = hashlib.new("sha1", raw).digest() + assert content.sha1_git == sha1_git + + # SkippedContent diff --git a/tox.ini b/tox.ini index cf034c9e30914754a2ec0851302d78be3d11e458..5198d08ec4aa86f42e1cc9780dce3c6349bb8ef8 100644 --- a/tox.ini +++ b/tox.ini @@ -40,7 +40,7 @@ commands = extras = testing deps = - mypy==0.920 + mypy==0.942 commands = mypy swh