Skip to content

Separate Borg 1.x legacy code into borg.legacy package #9556

@mr-raj12

Description

@mr-raj12

Problem

Borg 2.x code is tangled with 1.x legacy code across ~15 files. manifest.py has 15+ if not self.legacy: branches in the Archives class alone. legacyrepository.py and legacyremote.py already have "legacy" in the name but sit at the package root. src/borg/legacy/ exists but is empty.

What this does

Move the bulk of 1.x code into src/borg/legacy/. The goal is to eliminate almost every last # legacy comment , some one-liner branches are worse to extract than to keep. But the major classes and branch-heavy code (LegacyRepository, LegacyRemoteRepository, RepoObj1, the 4 legacy key types, the entire Archives legacy path) all move out.

After this:

  • v2 core modules are mostly free of legacy code
  • borg transfer --from-borg1 keeps working via borg.legacy
  • Dropping v1 support later = delete borg.legacy + remove a handful of scattered one-liners

Plan (7 phases)

Each phase is a separate PR.

Phase What happens
1 git mv of legacyrepository.py + legacyremote.py into legacy/
2 Extract RepoObj1, move legacy key types (KeyfileKey, RepoKey, etc.) into legacy/ with imported base classes
3 Extract LegacyArchives from Archives, remove all self.legacy branches in manifest.py
4 Switch remote.py to lazy-import LegacyRepository only inside RepositoryServer.open()
5 git mv of upgrade.py into legacy/
6 Inventory remaining scattered legacy markers, split what can be split, document what stays
7 Audit and expand test coverage for the borg1 compatibility path — borg transfer --from-borg1, upgrade from borg1, and borg serve with v1 clients; there are some transfer tests already but coverage of the upgrade path is thin

done:

in review:

Target structure

src/borg/legacy/
├── __init__.py
├── repository.py      ← LegacyRepository
├── remote.py          ← LegacyRemoteRepository
├── repoobj.py         ← RepoObj1
├── archives.py        ← LegacyArchives
├── upgrade.py         ← UpgraderFrom12To20, UpgraderNoOp
└── crypto/
    ├── __init__.py
    └── key.py         ← Legacy AES-CTR key types (imports bases from crypto/key.py)

Some scattered one-liners can't be moved like version == 1 checks in archive.py, legacy exit codes in helpers/errors.py, repository.version == 1 in cache.py. As extracting those would mean duplicating entire methods for one branch. They go away when v1 support is dropped.

Constraints

Testing

python -m pytest src/borg/testsuite/ -x -v
python -m pytest src/borg/testsuite/ -x -v -k "transfer"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions