/** {@inheritDoc} */ @Override public LogCursor allLogs() throws IOException { MergedLogCursor m = new MergedLogCursor(); for (int i = 0; i < tables.length; i++) { m.add(new LogQueueEntry(tables[i].allLogs(), i)); } return m; }
/** {@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 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(); } }
/** {@inheritDoc} */ @Override public boolean isNameConflicting(String refName) throws IOException { lock.lock(); try { Reftable table = reader(); // Cannot be nested within an existing reference. int lastSlash = refName.lastIndexOf('/'); while (0 < lastSlash) { if (table.hasRef(refName.substring(0, lastSlash))) { return true; } lastSlash = refName.lastIndexOf('/', lastSlash - 1); } // Cannot be the container of an existing reference. return table.hasRefsWithPrefix(refName + '/'); } 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); }
/** * 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(); } }
/** * Read a single reference's log. * * @param refName * exact name of the reference whose log to read. * @return cursor to iterate; empty cursor if no logs match. * @throws java.io.IOException * if logs cannot be read. */ public LogCursor seekLog(String refName) throws IOException { return seekLog(refName, Long.MAX_VALUE); }
/** {@inheritDoc} */ @Override public void close() { for (Reftable t : tables) { try { t.close(); } catch (IOException e) { // Ignore close failures. } } } }
/** {@inheritDoc} */ @Override public RefCursor allRefs() throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].allRefs(), i)); } return m; }
/** * 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); }
private boolean checkExpected(Reftable table, List<ReceiveCommand> pending) throws IOException { for (ReceiveCommand cmd : pending) { if (!matchOld(cmd, table.exactRef(cmd.getRefName()))) { cmd.setResult(LOCK_FAILURE); if (isAtomic()) { ReceiveCommand.abort(pending); return false; } } } return true; }
/** {@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); }
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); }
/** {@inheritDoc} */ @Override public boolean isNameConflicting(String refName) throws IOException { lock.lock(); try { Reftable table = reader(); // Cannot be nested within an existing reference. int lastSlash = refName.lastIndexOf('/'); while (0 < lastSlash) { if (table.hasRef(refName.substring(0, lastSlash))) { return true; } lastSlash = refName.lastIndexOf('/', lastSlash - 1); } // Cannot be the container of an existing reference. return table.hasRefsWithPrefix(refName + '/'); } finally { lock.unlock(); } }
/** {@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; }
/** {@inheritDoc} */ @Override public LogCursor seekLog(String refName, long updateIdx) throws IOException { MergedLogCursor m = new MergedLogCursor(); for (int i = 0; i < tables.length; i++) { m.add(new LogQueueEntry(tables[i].seekLog(refName, updateIdx), i)); } return m; }
/** {@inheritDoc} */ @Override public void close() throws IOException { for (Reftable t : tables) { t.close(); } }
/** {@inheritDoc} */ @Override public RefCursor allRefs() throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].allRefs(), i)); } return m; }
/** * 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); }