From d2bab654700cff1ea0427156aef1b18a6d3bd9ac Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Wed, 26 Dec 2018 20:33:55 -0800 Subject: [PATCH] RefDirectory: Look up several exact refs in one shot Override exactRef(String...) and firstExactRef(String...) with implementations specific to FileRepository. The specialized implementations are similar to the generic ones from RefDatabase, but because these use readRef directly instead of exactRef, they only need to call fireRefsChanged once. This will allow replacing RefDirectory#getRef with a generic implementation that uses firstExactRef without hurting performance. Change-Id: I1be1948bd6121c1a1e8152e201aab97e7fb308bb Signed-off-by: Jonathan Nieder --- .../internal/storage/file/RefDirectory.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) 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 dcf30c713..83127eb54 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 @@ -74,6 +74,7 @@ import java.text.MessageFormat; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -350,6 +351,43 @@ public class RefDirectory extends RefDatabase { } } + /** {@inheritDoc} */ + @Override + @NonNull + public Map exactRef(String... refs) throws IOException { + try { + RefList packed = getPackedRefs(); + Map result = new HashMap<>(refs.length); + for (String name : refs) { + Ref ref = readAndResolve(name, packed); + if (ref != null) { + result.put(name, ref); + } + } + return result; + } finally { + fireRefsChanged(); + } + } + + /** {@inheritDoc} */ + @Override + @Nullable + public Ref firstExactRef(String... refs) throws IOException { + try { + RefList packed = getPackedRefs(); + for (String name : refs) { + Ref ref = readAndResolve(name, packed); + if (ref != null) { + return ref; + } + } + return null; + } finally { + fireRefsChanged(); + } + } + /** {@inheritDoc} */ @Override public Ref getRef(String needle) throws IOException {