]> source.dussan.org Git - jgit.git/commitdiff
RefDirectory: Make pack() and commitPackRefs() void 02/200402/4
authorKaushik Lingarkar <quic_kaushikl@quicinc.com>
Tue, 7 Mar 2023 21:10:00 +0000 (13:10 -0800)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 30 Mar 2023 20:32:50 +0000 (22:32 +0200)
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>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

index cc9db5f77d2503ea4f7dc1a588c5177213794f1f..d381ddd41462eff20577c2d70531a6c81e2b7d7f 100644 (file)
@@ -727,17 +727,17 @@ public class RefDirectory extends RefDatabase {
                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 @@ 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<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 @@ public class RefDirectory extends RefDatabase {
                                if (changed) {
                                        modCnt.incrementAndGet();
                                }
-                               result.set(newPackedList);
                        }
                }.writePackedRefs();
-               return result.get();
        }
 
        private Ref readRef(String name, RefList<Ref> packed) throws IOException {