Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop relying on index locking. #159

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
25 changes: 15 additions & 10 deletions xandikos/store/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,8 @@ def _get_etag(self, name):
name = name.encode(DEFAULT_ENCODING)
return index[name].sha.decode("ascii")

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)
def _commit_tree(self, message, author=None):
return self.repo.do_commit(message=message, author=author)

def _import_one(self, name, data, message, author=None):
"""Import a single object.
Expand All @@ -680,6 +679,7 @@ def _import_one(self, name, data, message, author=None):
:param author: Optional author
:return: etag
"""
# TODO(jelmer): Take branch lock
try:
with locked_index(self.repo.index_path()) as index:
p = os.path.join(self.repo.path, name)
Expand All @@ -693,10 +693,14 @@ def _import_one(self, name, data, message, author=None):
index[encoded_name] = IndexEntry(
*index_entry_from_stat(st, blob.id, 0)
)
self._commit_tree(
index, message.encode(DEFAULT_ENCODING), author=author
)
return blob.id
commit_id = self._commit_tree(
message.encode(DEFAULT_ENCODING), author=author
)
# refresh blob.id in case one of the hooks changed it
tree_id = self.repo.object_store[commit_id].tree
unused_mode, blob_id = self.repo.object_store[tree_id](
self.repo.object_store.__getitem__, name)
return blob_id
except OSError as e:
if e.errno == errno.ENOSPC:
raise OutOfSpaceError()
Expand Down Expand Up @@ -727,12 +731,13 @@ def delete_one(self, name, message=None, author=None, etag=None):
if etag.encode("ascii") != current_etag:
raise InvalidETag(name, etag, current_etag.decode("ascii"))
try:
# TODO(jelmer): Lock ref
with locked_index(self.repo.index_path()) as index:
os.unlink(p)
del index[name.encode(DEFAULT_ENCODING)]
self._commit_tree(
index, message.encode(DEFAULT_ENCODING), author=author
)
self._commit_tree(
index, message.encode(DEFAULT_ENCODING), author=author
)
except FileLocked:
raise LockedError(name)

Expand Down