Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
50 changes: 45 additions & 5 deletions xandikos/store/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down