Page MenuHomeSoftware Heritage

D7208.id26135.diff
No OneTemporary

D7208.id26135.diff

diff --git a/swh/loader/bzr/loader.py b/swh/loader/bzr/loader.py
--- a/swh/loader/bzr/loader.py
+++ b/swh/loader/bzr/loader.py
@@ -264,11 +264,16 @@
if self.repo is not None:
self.repo.unlock()
- def get_repo(self):
- _, _, repo, _ = bzrdir.BzrDir.open_containing_tree_branch_or_repository(
+ def get_repo_and_branch(self) -> Tuple[repository.Repository, BzrBranch]:
+ _, branch, repo, _ = bzrdir.BzrDir.open_containing_tree_branch_or_repository(
self._repo_directory
)
- return repo
+ return repo, branch
+
+ def run_upgrade(self):
+ """Upgrade both repository and branch to the most recent supported version
+ to be compatible with the loader."""
+ cmd_upgrade().run(self._repo_directory, clean=True)
def fetch_data(self) -> bool:
"""Fetch the data from the source the loader is currently loading
@@ -304,19 +309,31 @@
self.log.debug("Using local directory '%s'", self.directory)
self._repo_directory = self.directory
- repo = self.get_repo()
+ repo, branch = self.get_repo_and_branch()
repository_format = repo._format.as_string() # lies about being a string
+
if not repository_format == expected_repository_format:
if repository_format in older_repository_formats:
self.log.debug(
"Upgrading repository from format '%s'",
repository_format.decode("ascii").strip("\n"),
)
- cmd_upgrade().run(self._repo_directory, clean=True)
- repo = self.get_repo()
+ self.run_upgrade()
+ repo, branch = self.get_repo_and_branch()
else:
raise UnknownRepositoryFormat()
+ if not branch.supports_tags():
+ # Some repos have the right format marker but their branches do not
+ # support tags
+ self.log.debug("Branch does not support tags, upgrading")
+ self.run_upgrade()
+ repo, branch = self.get_repo_and_branch()
+ # We could set the branch here directly, but we want to run the
+ # sanity checks in the `self.branch` property, so let's make sure
+ # we invalidate the "cache".
+ self._branch = None
+
self.repo = repo
self.repo.lock_read()
self.head_revision_id # set the property
@@ -681,7 +698,7 @@
@property
def tags(self) -> Optional[Dict[bytes, BzrRevisionId]]:
assert self.repo is not None
- if self._tags is None and self.branch.supports_tags():
+ if self._tags is None:
self._tags = {
n.encode(): r for n, r in self.branch.tags.get_tag_dict().items()
}
diff --git a/swh/loader/bzr/tests/data/does-not-support-tags.sh b/swh/loader/bzr/tests/data/does-not-support-tags.sh
new file mode 100644
--- /dev/null
+++ b/swh/loader/bzr/tests/data/does-not-support-tags.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+# Creates a repository with the correct recent format but an old branch
+# format that does not support tags
+
+set -euo pipefail
+bzr init-shared-repo does-not-support-tags-repo
+cd does-not-support-tags-repo
+bzr init --knit does-not-support-tags-branch
+cd ..
\ No newline at end of file
diff --git a/swh/loader/bzr/tests/data/does-not-support-tags.tgz b/swh/loader/bzr/tests/data/does-not-support-tags.tgz
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
literal 0
Hc$@<O00001
diff --git a/swh/loader/bzr/tests/test_loader.py b/swh/loader/bzr/tests/test_loader.py
--- a/swh/loader/bzr/tests/test_loader.py
+++ b/swh/loader/bzr/tests/test_loader.py
@@ -39,6 +39,8 @@
# - Ghost revisions
# - broken-tags
# - Tags corruption
+# - does-not-support-tags
+# - Repo is recent but branch does not support tags, needs upgraded
# TODO tests:
# - Root path listed in changes (does that even happen?)
@@ -139,10 +141,27 @@
archive_path = Path(datadir, "needs-upgrade.tgz")
repo_url = prepare_repository_from_archive(archive_path, "needs-upgrade", tmp_path)
- res = BazaarLoader(swh_storage, repo_url, directory=repo_url).load()
+ loader = BazaarLoader(swh_storage, repo_url, directory=repo_url)
+ upgrade_spy = mocker.spy(loader, "run_upgrade")
+ res = loader.load()
+ upgrade_spy.assert_called()
assert res == {"status": "uneventful"} # needs-upgrade is an empty repo
+def test_does_not_support_tags(swh_storage, datadir, tmp_path, mocker):
+ """Repository format is correct, but the branch itself does not support tags
+ and should be upgraded to the latest format"""
+ archive_path = Path(datadir, "does-not-support-tags.tgz")
+ path = "does-not-support-tags-repo/does-not-support-tags-branch"
+ repo_url = prepare_repository_from_archive(archive_path, path, tmp_path,)
+
+ loader = BazaarLoader(swh_storage, repo_url, directory=repo_url)
+ upgrade_spy = mocker.spy(loader, "run_upgrade")
+ res = loader.load()
+ upgrade_spy.assert_called()
+ assert res == {"status": "uneventful"} # does-not-support-tags is an empty repo
+
+
def test_no_branch(swh_storage, datadir, tmp_path):
"""This should only happen with a broken clone, so the expected result is failure"""
archive_path = Path(datadir, "no-branch.tgz")

File Metadata

Mime Type
text/plain
Expires
Dec 20 2024, 7:01 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3224414

Event Timeline