RefDirectory.delete: Prevent failures when packed-refs is outdated
The in-memory copy of packed refs might be outdated by the time the packed-refs lock is acquired, so ensure the one read from disk is used after acquiring the lock to prevent commit packed-refs from throwing an exception. As a side-effect, since this updates the in-memory copy of packed-refs when it is re-read from disk, it can prevent other callers needing to re-read if it had changed. Change-Id: I724c866b330b397e955b5eb04b259eedd9911e93 Signed-off-by: Kaushik Lingarkar <quic_kaushikl@quicinc.com>
This commit is contained in:
parent
4f7627be24
commit
5ae8d28faa
|
@ -673,16 +673,16 @@ void delete(RefDirectoryUpdate update) throws IOException {
|
||||||
// Write the packed-refs file using an atomic update. We might
|
// Write the packed-refs file using an atomic update. We might
|
||||||
// wind up reading it twice, before and after the lock, to ensure
|
// wind up reading it twice, before and after the lock, to ensure
|
||||||
// we don't miss an edit made externally.
|
// we don't miss an edit made externally.
|
||||||
final PackedRefList packed = getPackedRefs();
|
PackedRefList packed = getPackedRefs();
|
||||||
if (packed.contains(name)) {
|
if (packed.contains(name)) {
|
||||||
inProcessPackedRefsLock.lock();
|
inProcessPackedRefsLock.lock();
|
||||||
try {
|
try {
|
||||||
LockFile lck = lockPackedRefsOrThrow();
|
LockFile lck = lockPackedRefsOrThrow();
|
||||||
try {
|
try {
|
||||||
PackedRefList cur = readPackedRefs();
|
packed = refreshPackedRefs();
|
||||||
int idx = cur.find(name);
|
int idx = packed.find(name);
|
||||||
if (0 <= idx) {
|
if (0 <= idx) {
|
||||||
commitPackedRefs(lck, cur.remove(idx), packed, true);
|
commitPackedRefs(lck, packed.remove(idx), packed, true);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lck.unlock();
|
lck.unlock();
|
||||||
|
|
Loading…
Reference in New Issue