RefDirectory: Make pack() and commitPackRefs() void

There are no more callers (since Iae71cb3) of these methods that need
the returned value. These methods should not have been returning
anything in the first place as that can introduce bugs such as the
one described in Iae71cb3.

Change-Id: I1d083a91603da803a106cfb1506925a82c2ef809
Signed-off-by: Kaushik Lingarkar <quic_kaushikl@quicinc.com>
This commit is contained in:
Kaushik Lingarkar 2023-03-07 13:10:00 -08:00 committed by Matthias Sohn
parent 33c00f3347
commit 4652dd956e
1 changed files with 7 additions and 14 deletions

View File

@ -727,17 +727,17 @@ public void pack(List<String> refs) throws IOException {
pack(refs, Collections.emptyMap());
}
PackedRefList pack(Map<String, LockFile> heldLocks) throws IOException {
return pack(heldLocks.keySet(), heldLocks);
void pack(Map<String, LockFile> heldLocks) throws IOException {
pack(heldLocks.keySet(), heldLocks);
}
private PackedRefList pack(Collection<String> refs,
private void pack(Collection<String> refs,
Map<String, LockFile> heldLocks) throws IOException {
for (LockFile ol : heldLocks.values()) {
ol.requireLock();
}
if (refs.isEmpty()) {
return null;
return;
}
FS fs = parent.getFS();
@ -778,12 +778,11 @@ private PackedRefList pack(Collection<String> refs,
}
if (!dirty) {
// All requested refs were already packed accurately
return packed;
return;
}
// The new content for packed-refs is collected. Persist it.
PackedRefList result = commitPackedRefs(lck, cur, packed,
false);
commitPackedRefs(lck, cur, packed,false);
// Now delete the loose refs which are now packed
for (String refName : refs) {
@ -834,7 +833,6 @@ private PackedRefList pack(Collection<String> refs,
}
// Don't fire refsChanged. The refs have not change, only their
// storage.
return result;
} finally {
lck.unlock();
}
@ -1061,12 +1059,9 @@ private static String copy(String src, int off, int end) {
return new StringBuilder(end - off).append(src, off, end).toString();
}
PackedRefList commitPackedRefs(final LockFile lck, final RefList<Ref> refs,
void commitPackedRefs(final LockFile lck, final RefList<Ref> refs,
final PackedRefList oldPackedList, boolean changed)
throws IOException {
// Can't just return packedRefs.get() from this method; it might have been
// updated again after writePackedRefs() returns.
AtomicReference<PackedRefList> result = new AtomicReference<>();
new RefWriter(refs) {
@Override
protected void writeFile(String name, byte[] content)
@ -1112,10 +1107,8 @@ protected void writeFile(String name, byte[] content)
if (changed) {
modCnt.incrementAndGet();
}
result.set(newPackedList);
}
}.writePackedRefs();
return result.get();
}
private Ref readRef(String name, RefList<Ref> packed) throws IOException {