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>
This commit is contained in:
parent
4652dd956e
commit
4f7627be24
|
@ -746,13 +746,13 @@ private void pack(Collection<String> refs,
|
|||
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 @@ private void pack(Collection<String> refs,
|
|||
}
|
||||
|
||||
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 @@ private void pack(Collection<String> refs,
|
|||
}
|
||||
|
||||
// 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 @@ private void pack(Collection<String> refs,
|
|||
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())) {
|
||||
|
|
Loading…
Reference in New Issue