/** * Test if a reference exists. * * @param refName * reference name or subtree to find. * @return {@code true} if the reference exists. * @throws java.io.IOException * if references cannot be read. */ public boolean hasRef(String refName) throws IOException { try (RefCursor rc = seekRef(refName)) { return rc.next(); } }
/** {@inheritDoc} */ @Override public Map<String, Ref> getRefs(String prefix) throws IOException { RefList.Builder<Ref> all = new RefList.Builder<>(); lock.lock(); try { Reftable table = reader(); try (RefCursor rc = ALL.equals(prefix) ? table.allRefs() : (prefix.endsWith("/") ? table.seekRefsWithPrefix(prefix) //$NON-NLS-1$ : table.seekRef(prefix))) { while (rc.next()) { Ref ref = table.resolve(rc.getRef()); if (ref != null && ref.getObjectId() != null) { all.add(ref); } } } } finally { lock.unlock(); } RefList<Ref> none = RefList.emptyList(); return new RefMap(prefix, all.toRefList(), none, none); }
/** {@inheritDoc} */ @Override public Map<String, Ref> getRefs(String prefix) throws IOException { RefList.Builder<Ref> all = new RefList.Builder<>(); lock.lock(); try { Reftable table = reader(); try (RefCursor rc = ALL.equals(prefix) ? table.allRefs() : (prefix.endsWith("/") ? table.seekRefsWithPrefix(prefix) //$NON-NLS-1$ : table.seekRef(prefix))) { while (rc.next()) { Ref ref = table.resolve(rc.getRef()); if (ref != null && ref.getObjectId() != null) { all.add(ref); } } } } finally { lock.unlock(); } RefList<Ref> none = RefList.emptyList(); return new RefMap(prefix, all.toRefList(), none, none); }
/** {@inheritDoc} */ @Override public RefCursor seekRef(String name) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].seekRef(name), i)); } return m; }
/** * Lookup a reference, or null if not found. * * @param refName * reference name to find. * @return the reference, or {@code null} if not found. * @throws java.io.IOException * if references cannot be read. */ @Nullable public Ref exactRef(String refName) throws IOException { try (RefCursor rc = seekRef(refName)) { return rc.next() ? rc.getRef() : null; } }
/** * Test if a reference exists. * * @param refName * reference name or subtree to find. * @return {@code true} if the reference exists. * @throws java.io.IOException * if references cannot be read. */ public boolean hasRef(String refName) throws IOException { try (RefCursor rc = seekRef(refName)) { return rc.next(); } }
/** {@inheritDoc} */ @Override public RefCursor seekRef(String name) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].seekRef(name), i)); } return m; }
/** * Lookup a reference, or null if not found. * * @param refName * reference name to find. * @return the reference, or {@code null} if not found. * @throws java.io.IOException * if references cannot be read. */ @Nullable public Ref exactRef(String refName) throws IOException { try (RefCursor rc = seekRef(refName)) { return rc.next() ? rc.getRef() : null; } }