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 @@ -15,7 +15,7 @@ from breezy import errors as bzr_errors from breezy import repository, tsort -from breezy.builtins import cmd_branch +from breezy.builtins import cmd_branch, cmd_upgrade from breezy.bzr import bzrdir from breezy.bzr.branch import Branch as BzrBranch from breezy.bzr.inventory import Inventory, InventoryEntry @@ -269,6 +269,12 @@ if self.repo is not None: self.repo.unlock() + def get_repo(self): + _, _, repo, _ = bzrdir.BzrDir.open_containing_tree_branch_or_repository( + self._repo_directory + ) + return repo + def fetch_data(self) -> bool: """Fetch the data from the source the loader is currently loading @@ -303,14 +309,16 @@ self.log.debug("Using local directory '%s'", self.directory) self._repo_directory = self.directory - res = bzrdir.BzrDir.open_containing_tree_branch_or_repository( - self._repo_directory - ) - (_tree, _branch, repo, _relpath) = res + repo = self.get_repo() 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: - raise RepositoryNeedsUpgrade() + 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() else: raise UnknownRepositoryFormat() 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 @@ -135,12 +135,12 @@ def test_needs_upgrade(swh_storage, datadir, tmp_path, mocker): - """Old bzr repository format should fail the ingestion (upgrade necessary)""" + """Old bzr repository format should be upgraded to latest format""" 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() - assert res == {"status": "failed"} + assert res == {"status": "uneventful"} # needs-upgrade is an empty repo def test_no_branch(swh_storage, datadir, tmp_path):