/** * 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(); } }
/** * Test if any reference starts with {@code prefix} as a prefix. * * @param prefix * prefix to find. * @return {@code true} if at least one reference exists with prefix. * @throws java.io.IOException * if references cannot be read. */ public boolean hasRefsWithPrefix(String prefix) throws IOException { try (RefCursor rc = seekRefsWithPrefix(prefix)) { return rc.next(); } }
/** * Test if any reference directly refers to the object. * * @param id * ObjectId to find. * @return {@code true} if any reference exists directly referencing * {@code id}, or a annotated tag that peels to {@code id}. * @throws java.io.IOException * if references cannot be read. */ public boolean hasId(AnyObjectId id) throws IOException { try (RefCursor rc = byObjectId(id)) { return rc.next(); } }
void add(RefQueueEntry t) throws IOException { // Common case is many iterations over the same RefQueueEntry // for the bottom of the stack (scanning all refs). Its almost // always less than the top of the queue. Avoid the queue's // O(log N) insertion and removal costs for this common case. if (!t.rc.next()) { t.rc.close(); } else if (head == null) { RefQueueEntry p = queue.peek(); if (p == null || RefQueueEntry.compare(t, p) < 0) { head = t; } else { head = queue.poll(); queue.add(t); } } else if (RefQueueEntry.compare(t, head) > 0) { queue.add(t); } else { queue.add(head); head = t; } }
/** {@inheritDoc} */ @Override public List<Ref> getRefsByPrefix(String prefix) throws IOException { List<Ref> all = new ArrayList<>(); lock.lock(); try { Reftable table = reader(); try (RefCursor rc = ALL.equals(prefix) ? table.allRefs() : table.seekRefsWithPrefix(prefix)) { while (rc.next()) { Ref ref = table.resolve(rc.getRef()); if (ref != null && ref.getObjectId() != null) { all.add(ref); } } } } finally { lock.unlock(); } return Collections.unmodifiableList(all); }
/** * 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; } }
private void mergeRefs(MergedReftable mr) throws IOException { try (RefCursor rc = mr.allRefs()) { while (rc.next()) { writer.writeRef(rc.getRef(), rc.getUpdateIndex()); } } }
/** {@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); }
/** * 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(); } }
/** * Test if any reference starts with {@code prefix} as a prefix. * * @param prefix * prefix to find. * @return {@code true} if at least one reference exists with prefix. * @throws java.io.IOException * if references cannot be read. */ public boolean hasRefsWithPrefix(String prefix) throws IOException { try (RefCursor rc = seekRefsWithPrefix(prefix)) { return rc.next(); } }
/** * Test if any reference directly refers to the object. * * @param id * ObjectId to find. * @return {@code true} if any reference exists directly referencing * {@code id}, or a annotated tag that peels to {@code id}. * @throws java.io.IOException * if references cannot be read. */ public boolean hasId(AnyObjectId id) throws IOException { try (RefCursor rc = byObjectId(id)) { return rc.next(); } }
void add(RefQueueEntry t) throws IOException { // Common case is many iterations over the same RefQueueEntry // for the bottom of the stack (scanning all refs). Its almost // always less than the top of the queue. Avoid the queue's // O(log N) insertion and removal costs for this common case. if (!t.rc.next()) { t.rc.close(); } else if (head == null) { RefQueueEntry p = queue.peek(); if (p == null || RefQueueEntry.compare(t, p) < 0) { head = t; } else { head = queue.poll(); queue.add(t); } } else if (RefQueueEntry.compare(t, head) > 0) { queue.add(t); } else { queue.add(head); head = t; } }
/** {@inheritDoc} */ @Override public List<Ref> getRefsByPrefix(String prefix) throws IOException { List<Ref> all = new ArrayList<>(); lock.lock(); try { Reftable table = reader(); try (RefCursor rc = ALL.equals(prefix) ? table.allRefs() : table.seekRefsWithPrefix(prefix)) { while (rc.next()) { Ref ref = table.resolve(rc.getRef()); if (ref != null && ref.getObjectId() != null) { all.add(ref); } } } } finally { lock.unlock(); } return Collections.unmodifiableList(all); }
/** * 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; } }
private void mergeRefs(MergedReftable mr) throws IOException { try (RefCursor rc = mr.allRefs()) { while (rc.next()) { writer.writeRef(rc.getRef(), rc.getUpdateIndex()); } } }
/** {@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); }