From 4652dd956e7cc0933bb27efe42f075b94171c016 Mon Sep 17 00:00:00 2001 From: Kaushik Lingarkar Date: Tue, 7 Mar 2023 13:10:00 -0800 Subject: [PATCH] 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 --- .../internal/storage/file/RefDirectory.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 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 cc9db5f77..d381ddd41 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 void pack(List refs) throws IOException { 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 @@ private PackedRefList pack(Collection 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 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 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 @@ protected void writeFile(String name, byte[] content) if (changed) { modCnt.incrementAndGet(); } - result.set(newPackedList); } }.writePackedRefs(); - return result.get(); } private Ref readRef(String name, RefList packed) throws IOException {