diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-15 00:32:05 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-15 00:45:36 +0200 |
commit | 06590aee389f4466e02407f39af1674366a74705 (patch) | |
tree | 37bbf23a276c569aefaa1f218e9b3a417f2dcf17 /lib/git/index | |
parent | c9dbf201b4f0b3c2b299464618cb4ecb624d272c (diff) | |
download | gitpython-06590aee389f4466e02407f39af1674366a74705.tar.gz |
Reimplemented Lock handling to be conforming to the git lock protocol, which is actually more efficient than the previous implementation
Index now locks its file for reading, and properly uses LockedFD when writing
Diffstat (limited to 'lib/git/index')
-rw-r--r-- | lib/git/index/base.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/git/index/base.py b/lib/git/index/base.py index 165ac09a..02ed78ea 100644 --- a/lib/git/index/base.py +++ b/lib/git/index/base.py @@ -43,7 +43,7 @@ from git.objects.utils import Serializable from git.utils import ( IndexFileSHA1Writer, LazyMixin, - ConcurrentWriteOperation, + LockedFD, join_path_native ) @@ -89,18 +89,18 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): if attr == "entries": # read the current index # try memory map for speed + lfd = LockedFD(self._file_path) try: - fp = open(self._file_path, "rb") - except IOError: + stream = lfd.open(write=False, stream=True) + except OSError: + lfd.rollback() # in new repositories, there may be no index, which means we are empty self.entries = dict() return # END exception handling - stream = fp try: - raise Exception() - stream = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ) + stream = mmap.mmap(stream.fileno(), 0, access=mmap.ACCESS_READ) except Exception: pass # END memory mapping @@ -108,12 +108,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): try: self._deserialize(stream) finally: - pass - # make sure we close the stream ( possibly an mmap ) - # and the file - #stream.close() - #if stream is not fp: - # fp.close() + lfd.rollback() + # The handles will be closed on desctruction # END read from default index on demand else: super(IndexFile, self)._set_cache_(attr) @@ -267,12 +263,12 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): Note Index writing based on the dulwich implementation """ - write_op = ConcurrentWriteOperation(file_path or self._file_path) - stream = write_op._begin_writing() + lfd = LockedFD(file_path or self._file_path) + stream = lfd.open(write=True, stream=True) self._serialize(stream, ignore_tree_extension_data) - write_op._end_writing() + lfd.commit() # make sure we represent what we have written if file_path is not None: |