From 72402366dc3634bd5828945d005ec8353e9d16c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Sun, 18 Jan 2026 00:32:00 +0000 Subject: [PATCH] Fix compatibility with Dulwich 1 --- pyproject.toml | 2 +- tests/test_store.py | 2 +- xandikos/store/git.py | 50 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c4fd3daa..bad18bf6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ requires-python = ">=3.10" dependencies = [ "aiohttp", "icalendar>=5.0.4,<7.0", - "dulwich>=0.21.6,<0.26.0", + "dulwich>=0.21.6,<2", "defusedxml", "jinja2", "multidict", diff --git a/tests/test_store.py b/tests/test_store.py index 4dda864a..942ec316 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -469,7 +469,7 @@ def create_store(self): def add_blob(self, gc, name, contents): with open(os.path.join(gc.repo.path, name), "wb") as f: f.write(contents) - gc.repo.stage(name.encode("utf-8")) + gc.repo.get_worktree().stage(name.encode("utf-8")) return Blob.from_string(contents).id.decode("ascii") diff --git a/xandikos/store/git.py b/xandikos/store/git.py index 7ae250a6..2d279f18 100644 --- a/xandikos/store/git.py +++ b/xandikos/store/git.py @@ -34,7 +34,7 @@ import dulwich.repo from dulwich.file import FileLocked from dulwich.index import IndexEntry, index_entry_from_stat, locked_index -from dulwich.objects import Blob, Tree +from dulwich.objects import Blob, Commit, Tree from . import ( DEFAULT_MIME_TYPE, @@ -624,9 +624,47 @@ def create_memory(cls) -> "GitStore": return cls(repo) def _commit_tree(self, tree_id, message, author=None): - return self.repo.do_commit( - message=message, tree=tree_id, ref=self.ref, author=author - ) + """Create a commit for the given tree. + + Args: + tree_id: Tree object ID + message: Commit message (bytes) + author: Optional author (bytes) + + Returns: + Commit SHA + """ + import time + from dulwich.porcelain import get_user_identity + + c = Commit() + c.tree = tree_id + + if author is None: + author = get_user_identity(self.repo.get_config_stack()) + + c.author = author + c.committer = author + c.author_time = int(time.time()) + c.commit_time = c.author_time + c.author_timezone = 0 + c.commit_timezone = 0 + c.encoding = b"UTF-8" + c.message = message + + # Get parent commits + try: + c.parents = [self.repo.refs[self.ref]] + except KeyError: + c.parents = [] + + # Add commit to object store + self.repo.object_store.add_object(c) + + # Update ref + self.repo.refs[self.ref] = c.id + + return c.id def _import_one( self, @@ -728,7 +766,9 @@ def _get_etag(self, name): def _commit_tree(self, index, message, author=None): tree = index.commit(self.repo.object_store) - return self.repo.do_commit(message=message, author=author, tree=tree) + return self.repo.get_worktree().commit( + message=message, author=author, tree=tree + ) def _import_one( self,