diff options
author | Kaushik Lingarkar <quic_kaushikl@quicinc.com> | 2023-03-01 16:42:53 -0800 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2023-03-30 22:32:50 +0200 |
commit | 5ae8d28faaf6168921f673c89a4e6d601ffad78d (patch) | |
tree | 6dbd3a668a6c507d211fca85822bb8f9b631f27a /org.eclipse.jgit | |
parent | 4f7627be24cc9115323f6dba4663f376179c59e2 (diff) | |
download | jgit-5ae8d28faaf6168921f673c89a4e6d601ffad78d.tar.gz jgit-5ae8d28faaf6168921f673c89a4e6d601ffad78d.zip |
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>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 32eb067d36..aa3989e481 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -673,16 +673,16 @@ public class RefDirectory extends RefDatabase { // Write the packed-refs file using an atomic update. We might // wind up reading it twice, before and after the lock, to ensure // we don't miss an edit made externally. - final PackedRefList packed = getPackedRefs(); + PackedRefList packed = getPackedRefs(); if (packed.contains(name)) { inProcessPackedRefsLock.lock(); try { LockFile lck = lockPackedRefsOrThrow(); try { - PackedRefList cur = readPackedRefs(); - int idx = cur.find(name); + packed = refreshPackedRefs(); + int idx = packed.find(name); if (0 <= idx) { - commitPackedRefs(lck, cur.remove(idx), packed, true); + commitPackedRefs(lck, packed.remove(idx), packed, true); } } finally { lck.unlock(); |