From: Kaushik Lingarkar Date: Tue, 7 Mar 2023 21:10:00 +0000 (-0800) Subject: RefDirectory: Make pack() and commitPackRefs() void X-Git-Tag: v6.6.0.202305031100-m2~42 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F02%2F200402%2F4;p=jgit.git 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 --- 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 cc9db5f77d..d381ddd414 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 @@ -727,17 +727,17 @@ public class RefDirectory extends RefDatabase { pack(refs, Collections.emptyMap()); } - PackedRefList pack(Map heldLocks) throws IOException { - return pack(heldLocks.keySet(), heldLocks); + void pack(Map heldLocks) throws IOException { + pack(heldLocks.keySet(), heldLocks); } - private PackedRefList pack(Collection refs, + private void pack(Collection refs, Map heldLocks) throws IOException { for (LockFile ol : heldLocks.values()) { ol.requireLock(); } if (refs.isEmpty()) { - return null; + return; } FS fs = parent.getFS(); @@ -778,12 +778,11 @@ public class RefDirectory extends RefDatabase { } 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 @@ public class RefDirectory extends RefDatabase { } // Don't fire refsChanged. The refs have not change, only their // storage. - return result; } finally { lck.unlock(); } @@ -1061,12 +1059,9 @@ public class RefDirectory extends RefDatabase { return new StringBuilder(end - off).append(src, off, end).toString(); } - PackedRefList commitPackedRefs(final LockFile lck, final RefList refs, + void commitPackedRefs(final LockFile lck, final RefList 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 result = new AtomicReference<>(); new RefWriter(refs) { @Override protected void writeFile(String name, byte[] content) @@ -1112,10 +1107,8 @@ public class RefDirectory extends RefDatabase { if (changed) { modCnt.incrementAndGet(); } - result.set(newPackedList); } }.writePackedRefs(); - return result.get(); } private Ref readRef(String name, RefList packed) throws IOException {