private void clearReferences() { looseRefs.set(RefList.<LooseRef> emptyList()); packedRefs.set(NO_PACKED_REFS); }
/** * Remove an item at a specific index. * <p> * This list instance is not affected by the addition. Because this method * copies the entire list, it runs in O(N) time. * * @param idx * position to remove the item from. * @return copy of this list, after making removing the item at {@code idx}. */ public final RefList<T> remove(int idx) { if (cnt == 1) return emptyList(); Ref[] newList = new Ref[cnt - 1]; if (0 < idx) System.arraycopy(list, 0, newList, 0, idx); if (idx + 1 < cnt) System.arraycopy(list, idx + 1, newList, idx, cnt - (idx + 1)); return new RefList<>(newList, cnt - 1); }
/** {@inheritDoc} */ @Override public Map<String, Ref> getRefs(String prefix) throws IOException { if (!prefix.isEmpty() && prefix.charAt(prefix.length() - 1) != '/') { return new HashMap<>(0); } Ref src = bootstrap.exactRef(txnCommitted); Scanner.Result c = refs; if (c == null || !c.refTreeId.equals(idOf(src))) { c = Scanner.scanRefTree(repo, src, prefix, true); if (prefix.isEmpty()) { refs = c; } } return new RefMap(prefix, RefList.<Ref> emptyList(), c.all, c.sym); }
RefDirectory(FileRepository db) { final FS fs = db.getFS(); parent = db; gitDir = db.getDirectory(); refsDir = fs.resolve(gitDir, R_REFS); logsDir = fs.resolve(gitDir, LOGS); logsRefsDir = fs.resolve(gitDir, LOGS + '/' + R_REFS); packedRefsFile = fs.resolve(gitDir, PACKED_REFS); looseRefs.set(RefList.<LooseRef> emptyList()); packedRefs.set(NO_PACKED_REFS); }
/** {@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 Ref put(String keyName, Ref value) { String name = toRefName(keyName); if (!name.equals(value.getName())) throw new IllegalArgumentException(); if (!resolved.isEmpty()) { // Collapse the resolved list into the loose list so we // can discard it and stop joining the two together. for (Ref ref : resolved) loose = loose.put(ref); resolved = RefList.emptyList(); } int idx = loose.find(name); if (0 <= idx) { Ref prior = loose.get(name); loose = loose.set(idx, value); return prior; } else { Ref prior = get(keyName); loose = loose.add(idx, value); sizeIsValid = false; return prior; } }
private void clearReferences() { looseRefs.set(RefList.<LooseRef> emptyList()); packedRefs.set(PackedRefList.NO_PACKED_REFS); }
private void clearReferences() { looseRefs.set(RefList.<LooseRef> emptyList()); packedRefs.set(NO_PACKED_REFS); }
/** {@inheritDoc} */ @Override public Map<String, Ref> getRefs(String prefix) throws IOException { RefCache curr = read(); RefList<Ref> packed = RefList.emptyList(); RefList<Ref> loose = curr.ids; RefList.Builder<Ref> sym = new RefList.Builder<>(curr.sym.size()); for (int idx = 0; idx < curr.sym.size(); idx++) { Ref ref = curr.sym.get(idx); String name = ref.getName(); ref = resolve(ref, 0, loose); if (ref != null && ref.getObjectId() != null) { sym.add(ref); } else { // A broken symbolic reference, we have to drop it from the // collections the client is about to receive. Should be a // rare occurrence so pay a copy penalty. int toRemove = loose.find(name); if (0 <= toRemove) loose = loose.remove(toRemove); } } return new RefMap(prefix, packed, loose, sym.toRefList()); }
/** * Remove an item at a specific index. * <p> * This list instance is not affected by the addition. Because this method * copies the entire list, it runs in O(N) time. * * @param idx * position to remove the item from. * @return copy of this list, after making removing the item at {@code idx}. */ public final RefList<T> remove(int idx) { if (cnt == 1) return emptyList(); Ref[] newList = new Ref[cnt - 1]; if (0 < idx) System.arraycopy(list, 0, newList, 0, idx); if (idx + 1 < cnt) System.arraycopy(list, idx + 1, newList, idx, cnt - (idx + 1)); return new RefList<T>(newList, cnt - 1); }
/** {@inheritDoc} */ @Override public Map<String, Ref> getRefs(String prefix) throws IOException { if (!prefix.isEmpty() && prefix.charAt(prefix.length() - 1) != '/') { return new HashMap<>(0); } Ref src = bootstrap.exactRef(txnCommitted); Scanner.Result c = refs; if (c == null || !c.refTreeId.equals(idOf(src))) { c = Scanner.scanRefTree(repo, src, prefix, true); if (prefix.isEmpty()) { refs = c; } } return new RefMap(prefix, RefList.<Ref> emptyList(), c.all, c.sym); }
@Override public Map<String, Ref> getRefs(String prefix) throws IOException { if (!prefix.isEmpty() && prefix.charAt(prefix.length() - 1) != '/') { return new HashMap<>(0); } Ref src = bootstrap.exactRef(txnCommitted); Scanner.Result c = refs; if (c == null || !c.refTreeId.equals(idOf(src))) { c = Scanner.scanRefTree(repo, src, prefix, true); if (prefix.isEmpty()) { refs = c; } } return new RefMap(prefix, RefList.<Ref> emptyList(), c.all, c.sym); }
RefDirectory(final FileRepository db) { final FS fs = db.getFS(); parent = db; gitDir = db.getDirectory(); logWriter = new ReflogWriter(db); refsDir = fs.resolve(gitDir, R_REFS); packedRefsFile = fs.resolve(gitDir, PACKED_REFS); looseRefs.set(RefList.<LooseRef> emptyList()); packedRefs.set(PackedRefList.NO_PACKED_REFS); }
RefDirectory(FileRepository db) { final FS fs = db.getFS(); parent = db; gitDir = db.getDirectory(); refsDir = fs.resolve(gitDir, R_REFS); logsDir = fs.resolve(gitDir, LOGS); logsRefsDir = fs.resolve(gitDir, LOGS + '/' + R_REFS); packedRefsFile = fs.resolve(gitDir, PACKED_REFS); looseRefs.set(RefList.<LooseRef> emptyList()); packedRefs.set(NO_PACKED_REFS); }