new RefList.Builder<>(refs.size() - nDeletes + adds.size()); for (Ref ref : refs) { String name = ref.getName(); ReceiveCommand cmd = byName.remove(name); if (cmd == null) { b.add(ref); continue; ReceiveCommand currAdd = adds.get(addIdx); if (currAdd.getRefName().compareTo(name) < 0) { b.add(peeledRef(walk, currAdd)); byName.remove(currAdd.getRefName()); } else { b.add(peeledRef(walk, cmd)); ReceiveCommand cmd = adds.get(addIdx++); byName.remove(cmd.getRefName()); b.add(peeledRef(walk, cmd)); return b.toRefList();
private RefList<Ref> parsePackedRefs(BufferedReader br) throws IOException { RefList.Builder<Ref> all = new RefList.Builder<>(); Ref last = null; boolean peeled = false; last = new ObjectIdRef.PeeledTag(PACKED, last.getName(), last .getObjectId(), id); all.set(all.size() - 1, last); continue; if (last != null && RefComparator.compareTo(last, cur) > 0) needSort = true; all.add(cur); last = cur; all.sort(); return all.toRefList();
/** * Obtain a builder initialized with the first {@code n} elements. * <p> * Copies the first {@code n} elements from this list into a new builder, * which can be used by the caller to add additional elements. * * @param n * the number of elements to copy. * @return a new builder with the first {@code n} elements already added. */ public final Builder<T> copy(int n) { Builder<T> r = new Builder<>(Math.max(16, n)); r.addAll(list, 0, n); return r; }
new RefList.Builder<>(refs.size() - nDeletes + adds.size()); for (Ref ref : refs) { String name = ref.getName(); ReceiveCommand cmd = byName.remove(name); if (cmd == null) { b.add(ref); continue; ReceiveCommand currAdd = adds.get(addIdx); if (currAdd.getRefName().compareTo(name) < 0) { b.add(peeledRef(walk, currAdd)); byName.remove(currAdd.getRefName()); } else { b.add(peeledRef(walk, cmd)); ReceiveCommand cmd = adds.get(addIdx++); byName.remove(cmd.getRefName()); b.add(peeledRef(walk, cmd)); return b.toRefList();
RefList.Builder<Ref> all = new RefList.Builder<>(); RefList.Builder<Ref> sym = new RefList.Builder<>(); RefList<Ref> aList = all.toRefList(); for (int idx = 0; idx < sym.size();) { Ref s = sym.get(idx); Ref r = resolve(s, 0, aList); if (r != null) { sym.set(idx++, r); } else { sym.remove(idx); int rm = aList.find(s.getName()); if (0 <= rm) { return new Result(srcId, aList, sym.toRefList());
RefList.Builder<Ref> all = new RefList.Builder<>(); RefList.Builder<Ref> sym = new RefList.Builder<>(); RefList<Ref> aList = all.toRefList(); for (int idx = 0; idx < sym.size();) { Ref s = sym.get(idx); Ref r = resolve(s, 0, aList); if (r != null) { sym.set(idx++, r); } else { sym.remove(idx); int rm = aList.find(s.getName()); if (0 <= rm) { return new Result(srcId, aList, sym.toRefList());
private RefList<Ref> parsePackedRefs(final BufferedReader br) throws IOException { RefList.Builder<Ref> all = new RefList.Builder<Ref>(); Ref last = null; boolean peeled = false; last = new ObjectIdRef.PeeledTag(PACKED, last.getName(), last .getObjectId(), id); all.set(all.size() - 1, last); continue; if (last != null && RefComparator.compareTo(last, cur) > 0) needSort = true; all.add(cur); last = cur; all.sort(); return all.toRefList();
private RefList<Ref> parsePackedRefs(BufferedReader br) throws IOException { RefList.Builder<Ref> all = new RefList.Builder<>(); Ref last = null; boolean peeled = false; last = new ObjectIdRef.PeeledTag(PACKED, last.getName(), last .getObjectId(), id); all.set(all.size() - 1, last); continue; if (last != null && RefComparator.compareTo(last, cur) > 0) needSort = true; all.add(cur); last = cur; all.sort(); return all.toRefList();
scan.newLoose.sort(); loose = scan.newLoose.toRefList(); if (looseRefs.compareAndSet(oldLoose, loose)) modCnt.incrementAndGet(); for (int idx = 0; idx < symbolic.size();) { final Ref symbolicRef = symbolic.get(idx); final Ref resolvedRef = resolve(symbolicRef, 0, prefix, loose, packed); if (resolvedRef != null && resolvedRef.getObjectId() != null) { symbolic.set(idx, resolvedRef); idx++; } else { symbolic.remove(idx); final int toRemove = loose.find(symbolicRef.getName()); if (0 <= toRemove) symbolic.sort(); return new RefMap(prefix, packed, upcast(loose), symbolic.toRefList());
scan.newLoose.sort(); loose = scan.newLoose.toRefList(); if (looseRefs.compareAndSet(oldLoose, loose)) modCnt.incrementAndGet(); for (int idx = 0; idx < symbolic.size();) { final Ref symbolicRef = symbolic.get(idx); final Ref resolvedRef = resolve(symbolicRef, 0, prefix, loose, packed); if (resolvedRef != null && resolvedRef.getObjectId() != null) { symbolic.set(idx, resolvedRef); idx++; } else { symbolic.remove(idx); final int toRemove = loose.find(symbolicRef.getName()); if (0 <= toRemove) symbolic.sort(); return new RefMap(prefix, packed, upcast(loose), symbolic.toRefList());
void scan(String prefix) { if (ALL.equals(prefix)) { scanOne(HEAD); scanTree(R_REFS, refsDir); // If any entries remain, they are deleted, drop them. if (newLoose == null && curIdx < curLoose.size()) newLoose = curLoose.copy(curIdx); } else if (prefix.startsWith(R_REFS) && prefix.endsWith("/")) { //$NON-NLS-1$ curIdx = -(curLoose.find(prefix) + 1); File dir = new File(refsDir, prefix.substring(R_REFS.length())); scanTree(prefix, dir); // Skip over entries still within the prefix; these have // been removed from the directory. while (curIdx < curLoose.size()) { if (!curLoose.get(curIdx).getName().startsWith(prefix)) break; if (newLoose == null) newLoose = curLoose.copy(curIdx); curIdx++; } // Keep any entries outside of the prefix space, we // do not know anything about their status. if (newLoose != null) { while (curIdx < curLoose.size()) newLoose.add(curLoose.get(curIdx++)); } } }
/** {@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()); }
void scan(String prefix) { if (ALL.equals(prefix)) { scanOne(HEAD); scanTree(R_REFS, refsDir); // If any entries remain, they are deleted, drop them. if (newLoose == null && curIdx < curLoose.size()) newLoose = curLoose.copy(curIdx); } else if (prefix.startsWith(R_REFS) && prefix.endsWith("/")) { //$NON-NLS-1$ curIdx = -(curLoose.find(prefix) + 1); File dir = new File(refsDir, prefix.substring(R_REFS.length())); scanTree(prefix, dir); // Skip over entries still within the prefix; these have // been removed from the directory. while (curIdx < curLoose.size()) { if (!curLoose.get(curIdx).getName().startsWith(prefix)) break; if (newLoose == null) newLoose = curLoose.copy(curIdx); curIdx++; } // Keep any entries outside of the prefix space, we // do not know anything about their status. if (newLoose != null) { while (curIdx < curLoose.size()) newLoose.add(curLoose.get(curIdx++)); } } }
@Override public Map<String, Ref> getRefs(String prefix) throws IOException { RefCache curr = readRefs(); RefList<DhtRef> packed = RefList.emptyList(); RefList<DhtRef> loose = curr.ids; RefList.Builder<DhtRef> sym = new RefList.Builder<DhtRef>(curr.sym.size()); for (int idx = 0; idx < curr.sym.size(); idx++) { DhtRef 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()); }
@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<Ref>(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()); }
/** {@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); }