diff --git a/swh/loader/pypi/loader.py b/swh/loader/pypi/loader.py --- a/swh/loader/pypi/loader.py +++ b/swh/loader/pypi/loader.py @@ -236,12 +236,15 @@ def generate_and_load_snapshot(self): branches = {} for release, artifacts in self.project.all_release_artifacts().items(): + default_release = self.project.default_release() if len(artifacts) == 1: # Only one artifact for this release, generate a single branch branch_name = 'refs/tags/%s' % release filename, sha256 = artifacts[0] target = self.target_from_artifact(filename, sha256) branches[branch_name.encode('utf-8')] = target + if release == default_release: + branches[b'HEAD'] = target else: # Several artifacts for this release, generate a separate # pointer for each of them diff --git a/swh/loader/pypi/tests/test_loader.py b/swh/loader/pypi/tests/test_loader.py --- a/swh/loader/pypi/tests/test_loader.py +++ b/swh/loader/pypi/tests/test_loader.py @@ -197,9 +197,13 @@ 'target': 'e445da4da22b31bfebb6ffc4383dbf839a074d21', 'target_type': 'revision', }, + 'HEAD': { + 'target': 'e445da4da22b31bfebb6ffc4383dbf839a074d21', + 'target_type': 'revision', + }, } - self.assertSnapshotOk('c111b9a5f46e68e5017b04383281cfd932ab3fb8', + self.assertSnapshotOk('5c99339508de5eea67eecd3e0ba1efa8e804b96e', expected_branches) @@ -211,7 +215,7 @@ def _last_snapshot(self): """Return last visited snapshot""" return { - 'id': b'\xc1\x11\xb9\xa5\xf4nh\xe5\x01{\x0482\x81\xcf\xd92\xab?\xb8', # noqa + 'id': b'\\\x993\x95\x08\xde^\xeag\xee\xcd>\x0b\xa1\xef\xa8\xe8\x04\xb9n', # noqa 'branches': { b'refs/tags/1.1.0': { 'target': b'L\x99\x89\x1f\x93\xb8\x14P' @@ -224,6 +228,12 @@ b'\x9a\x07M!', 'target_type': 'revision' }, + b'HEAD': { + 'target': b'\xe4E\xdaM\xa2+1\xbf' + b'\xeb\xb6\xff\xc48=\xbf\x83' + b'\x9a\x07M!', + 'target_type': 'revision' + }, }, } @@ -273,7 +283,7 @@ self.assertDirectoriesOk([]) self.assertRevisionsOk(expected_revisions={}) - expected_snapshot_id = 'c111b9a5f46e68e5017b04383281cfd932ab3fb8' + expected_snapshot_id = '5c99339508de5eea67eecd3e0ba1efa8e804b96e' expected_branches = { 'refs/tags/1.1.0': { 'target': '4c99891f93b81450385777235a37b5e966dd1571', @@ -283,6 +293,10 @@ 'target': 'e445da4da22b31bfebb6ffc4383dbf839a074d21', 'target_type': 'revision', }, + 'HEAD': { + 'target': 'e445da4da22b31bfebb6ffc4383dbf839a074d21', + 'target_type': 'revision', + }, } self.assertSnapshotOk(expected_snapshot_id, expected_branches) @@ -358,7 +372,7 @@ for rev, dir_id in old_revisions.items(): expected_revisions[rev] = dir_id - expected_snapshot_id = '78fe3367ba98ed8b679b91ca70d3f68130fa0694' + expected_snapshot_id = 'c1500c9fae5c275f5a772105c36884dd01bc26e7' expected_branches = { 'refs/tags/1.1.0': { 'target': '4c99891f93b81450385777235a37b5e966dd1571', @@ -372,6 +386,10 @@ 'target': 'fb46e49605b0bbe69f8c53d315e89370e7c6cb5d', 'target_type': 'revision', }, + 'HEAD': { + 'target': 'fb46e49605b0bbe69f8c53d315e89370e7c6cb5d', + 'target_type': 'revision', + }, } self.assertSnapshotOk(expected_snapshot_id, expected_branches) @@ -388,7 +406,7 @@ def _last_snapshot(self): """Return last visited snapshot""" return { - 'id': b'x\xfe3g\xba\x98\xed\x8bg\x9b\x91\xcap\xd3\xf6\x810\xfa\x06\x94', # noqa + 'id': b"\xc1P\x0c\x9f\xae\\'_Zw!\x05\xc3h\x84\xdd\x01\xbc&\xe7", # noqa 'branches': { b'refs/tags/1.1.0': { 'target': b'L\x99\x89\x1f\x93\xb8\x14P8Ww#Z7\xb5\xe9f\xdd\x15q', # noqa @@ -401,7 +419,11 @@ b'refs/tags/1.3.0': { 'target': b'\xfbF\xe4\x96\x05\xb0\xbb\xe6\x9f\x8cS\xd3\x15\xe8\x93p\xe7\xc6\xcb]', # noqa 'target_type': 'revision' - } + }, + b'HEAD': { + 'target': b'\xfbF\xe4\x96\x05\xb0\xbb\xe6\x9f\x8cS\xd3\x15\xe8\x93p\xe7\xc6\xcb]', # noqa + 'target_type': 'revision' + }, } } @@ -487,7 +509,7 @@ } self.assertRevisionsOk(expected_revisions) - expected_snapshot_id = '388083a9bb675812c6cc7124e1f8af8128df6917' + expected_snapshot_id = 'ddc940677eda1ca270c8b7e8d7796f8f98428522' expected_branches = { 'refs/tags/1.2.0': { 'target': 'e445da4da22b31bfebb6ffc4383dbf839a074d21', @@ -501,6 +523,10 @@ 'target': '5e91875f096ac48c98d74acf307439a3490f2827', 'target_type': 'revision', }, + 'HEAD': { + 'target': '5e91875f096ac48c98d74acf307439a3490f2827', + 'target_type': 'revision', + }, } self.assertSnapshotOk(expected_snapshot_id, expected_branches)