Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7124023
D7202.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D7202.diff
View Options
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
@@ -78,11 +78,6 @@
expected_repository_format = b"Bazaar repository format 2a (needs bzr 1.16 or later)\n"
-class RepositoryNeedsUpgrade(Exception):
- """The repository we're trying to load is using an old format.
- We only support format 2a (the most recent), see `brz help upgrade`"""
-
-
class UnknownRepositoryFormat(Exception):
"""The repository we're trying to load is using an unknown format.
It's possible (though unlikely) that a new format has come out, we should
@@ -269,6 +264,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 +304,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):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Dec 20 2024, 9:42 AM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221228
Attached To
D7202: loader: Upgrade repository with old formats prior loading
Event Timeline
Log In to Comment