Skip to content

Commit d79d20d

Browse files
committed
Avoid taking a lock for reading
This isn't needed as git will replace this file atomicially, hence we always see a fully written file when reading. Only when writing we need to obtain a lock.
1 parent 2141eae commit d79d20d

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

Diff for: git/index/base.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,17 @@ def __init__(self, repo: 'Repo', file_path: Union[PathLike, None] = None) -> Non
127127

128128
def _set_cache_(self, attr: str) -> None:
129129
if attr == "entries":
130-
# read the current index
131-
# try memory map for speed
132-
lfd = LockedFD(self._file_path)
133-
ok = False
134130
try:
135-
fd = lfd.open(write=False, stream=False)
136-
ok = True
131+
fd = os.open(self._file_path, os.O_RDONLY)
137132
except OSError:
138133
# in new repositories, there may be no index, which means we are empty
139134
self.entries: Dict[Tuple[PathLike, StageType], IndexEntry] = {}
140135
return None
141-
finally:
142-
if not ok:
143-
lfd.rollback()
144136
# END exception handling
145137

146138
stream = file_contents_ro(fd, stream=True, allow_mmap=True)
147139

148-
try:
149-
self._deserialize(stream)
150-
finally:
151-
lfd.rollback()
152-
# The handles will be closed on destruction
153-
# END read from default index on demand
140+
self._deserialize(stream)
154141
else:
155142
super(IndexFile, self)._set_cache_(attr)
156143

0 commit comments

Comments
 (0)