Skip to content

Commit 63104d6

Browse files
committed
Avoid taking a lock for reading (#1338)
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 63104d6

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

Diff for: git/index/base.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,18 @@ def _set_cache_(self, attr: str) -> None:
129129
if attr == "entries":
130130
# read the current index
131131
# try memory map for speed
132-
lfd = LockedFD(self._file_path)
133132
ok = False
134133
try:
135-
fd = lfd.open(write=False, stream=False)
136-
ok = True
134+
fd = os.open(self._file_path, os.O_RDONLY)
137135
except OSError:
138136
# in new repositories, there may be no index, which means we are empty
139137
self.entries: Dict[Tuple[PathLike, StageType], IndexEntry] = {}
140138
return None
141-
finally:
142-
if not ok:
143-
lfd.rollback()
144139
# END exception handling
145140

146141
stream = file_contents_ro(fd, stream=True, allow_mmap=True)
147142

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
143+
self._deserialize(stream)
154144
else:
155145
super(IndexFile, self)._set_cache_(attr)
156146

0 commit comments

Comments
 (0)