diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 356d2a350f..8982d44d8b 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -85,6 +85,6 @@ jobs: if: "matrix.os == 'windows-latest'" - name: Run mypy run: | - python -m pip install mypy types-PyYAML types-paramiko types-setuptools + python -m pip install mypy types-PyYAML types-paramiko types-setuptools typing-extensions python -m mypy breezy if: "matrix.python-version != 'pypy3'" diff --git a/breezy/git/filegraph.py b/breezy/git/filegraph.py index 54fde7478d..51bb3d0874 100644 --- a/breezy/git/filegraph.py +++ b/breezy/git/filegraph.py @@ -40,6 +40,13 @@ def find_last_change_revision(self, path, commit_id): store = self.store while True: commit = store[commit_id] + if path == b"": + # For the root directory, use the tree itself + # TODO: dulwich >= 0.24.0 supports passing b"" to tree_lookup_path() + # This workaround can be removed when the minimum dulwich version is >= 0.24.0 + target_mode = stat.S_IFDIR + target_sha = commit.tree + break try: target_mode, target_sha = tree_lookup_path( store.__getitem__, commit.tree, path @@ -52,8 +59,6 @@ def find_last_change_revision(self, path, commit_id): path = posixpath.relpath(path, e.path) else: break - if path == b"": - target_mode = stat.S_IFDIR if target_mode is None: raise AssertionError(f"sha {target_sha!r} for {path!r} in {commit_id!r}") while True: @@ -61,15 +66,20 @@ def find_last_change_revision(self, path, commit_id): for parent_id in commit.parents: try: parent_commit = store[parent_id] - mode, sha = tree_lookup_path( - store.__getitem__, parent_commit.tree, path - ) + if path == b"": + # For the root directory, use the tree itself + # TODO: dulwich >= 0.24.0 supports passing b"" to tree_lookup_path() + # This workaround can be removed when the minimum dulwich version is >= 0.24.0 + mode = stat.S_IFDIR + sha = parent_commit.tree + else: + mode, sha = tree_lookup_path( + store.__getitem__, parent_commit.tree, path + ) except (KeyError, NotTreeError): continue else: parent_commits.append(parent_commit) - if path == b"": - mode = stat.S_IFDIR # Candidate found iff, mode or text changed, # or is a directory that didn't previously exist. if mode != target_mode or ( diff --git a/breezy/git/transportgit.py b/breezy/git/transportgit.py index 00de59efd0..8a97a0bbf4 100644 --- a/breezy/git/transportgit.py +++ b/breezy/git/transportgit.py @@ -731,6 +731,13 @@ def _remove_loose_object(self, sha): path = osutils.joinpath(self._split_loose_object(sha)) self.transport.delete(urlutils.quote(path)) + def delete_loose_object(self, sha): + """Delete a loose object. + + This method is called by dulwich's pack_loose_objects method. + """ + self._remove_loose_object(sha) + def _get_loose_object(self, sha): path = osutils.joinpath(self._split_loose_object(sha)) try: