/** * Resolve a symbolic reference to populate its value. * * @param symref * reference to resolve. * @return resolved {@code symref}, or {@code null}. * @throws java.io.IOException * if references cannot be read. */ @Nullable public Ref resolve(Ref symref) throws IOException { return resolve(symref, 0); }
/** {@inheritDoc} */ @Override public Ref exactRef(String name) throws IOException { lock.lock(); try { Reftable table = reader(); Ref ref = table.exactRef(name); if (ref != null && ref.isSymbolic()) { return table.resolve(ref); } return ref; } finally { lock.unlock(); } }
/** {@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); }
/** {@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); }
private Ref resolve(Ref ref, int depth) throws IOException { if (!ref.isSymbolic()) { return ref; } Ref dst = ref.getTarget(); if (MAX_SYMBOLIC_REF_DEPTH <= depth) { return null; // claim it doesn't exist } dst = exactRef(dst.getName()); if (dst == null) { return ref; } dst = resolve(dst, depth + 1); if (dst == null) { return null; // claim it doesn't exist } return new SymbolicRef(ref.getName(), dst); }
/** * Resolve a symbolic reference to populate its value. * * @param symref * reference to resolve. * @return resolved {@code symref}, or {@code null}. * @throws java.io.IOException * if references cannot be read. */ @Nullable public Ref resolve(Ref symref) throws IOException { return resolve(symref, 0); }
/** {@inheritDoc} */ @Override public Ref exactRef(String name) throws IOException { lock.lock(); try { Reftable table = reader(); Ref ref = table.exactRef(name); if (ref != null && ref.isSymbolic()) { return table.resolve(ref); } return ref; } finally { lock.unlock(); } }
/** {@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); }
/** {@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); }
private Ref resolve(Ref ref, int depth) throws IOException { if (!ref.isSymbolic()) { return ref; } Ref dst = ref.getTarget(); if (MAX_SYMBOLIC_REF_DEPTH <= depth) { return null; // claim it doesn't exist } dst = exactRef(dst.getName()); if (dst == null) { return ref; } dst = resolve(dst, depth + 1); if (dst == null) { return null; // claim it doesn't exist } return new SymbolicRef(ref.getName(), dst); }