diff options
author | Kaushik Lingarkar <quic_kaushikl@quicinc.com> | 2023-02-27 15:17:55 -0800 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2023-03-30 22:32:50 +0200 |
commit | 4f7627be24cc9115323f6dba4663f376179c59e2 (patch) | |
tree | cea7b8c7e20516061e8cdd185115a15b28441d59 | |
parent | 4652dd956e7cc0933bb27efe42f075b94171c016 (diff) | |
download | jgit-4f7627be24cc9115323f6dba4663f376179c59e2.tar.gz jgit-4f7627be24cc9115323f6dba4663f376179c59e2.zip |
RefDirectory.pack: Only rely on packed refs from disk
Since packed-refs is read from disk anyway, don't rely on the
in-memory copy as that is racy and if outdated, could result in
commit of pack-refs throwing an exception. This change also avoids
a possible unnecessary double read of packed-refs from disk.
Change-Id: I684a64991f53f8bdad58bbd248aae6522d11267d
Signed-off-by: Kaushik Lingarkar <quic_kaushikl@quicinc.com>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java | 16 |
1 files changed, 8 insertions, 8 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 d381ddd414..32eb067d36 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 @@ -746,13 +746,13 @@ public class RefDirectory extends RefDatabase { try { LockFile lck = lockPackedRefsOrThrow(); try { - final PackedRefList packed = getPackedRefs(); - RefList<Ref> cur = readPackedRefs(); + PackedRefList oldPacked = refreshPackedRefs(); + RefList<Ref> newPacked = oldPacked; // Iterate over all refs to be packed boolean dirty = false; for (String refName : refs) { - Ref oldRef = readRef(refName, cur); + Ref oldRef = readRef(refName, newPacked); if (oldRef == null) { continue; // A non-existent ref is already correctly packed. } @@ -769,11 +769,11 @@ public class RefDirectory extends RefDatabase { } dirty = true; - int idx = cur.find(refName); + int idx = newPacked.find(refName); if (idx >= 0) { - cur = cur.set(idx, newRef); + newPacked = newPacked.set(idx, newRef); } else { - cur = cur.add(idx, newRef); + newPacked = newPacked.add(idx, newRef); } } if (!dirty) { @@ -782,7 +782,7 @@ public class RefDirectory extends RefDatabase { } // The new content for packed-refs is collected. Persist it. - commitPackedRefs(lck, cur, packed,false); + commitPackedRefs(lck, newPacked, oldPacked,false); // Now delete the loose refs which are now packed for (String refName : refs) { @@ -809,7 +809,7 @@ public class RefDirectory extends RefDatabase { if (currentLooseRef == null || currentLooseRef.isSymbolic()) { continue; } - Ref packedRef = cur.get(refName); + Ref packedRef = newPacked.get(refName); ObjectId clr_oid = currentLooseRef.getObjectId(); if (clr_oid != null && clr_oid.equals(packedRef.getObjectId())) { |