@Override public Ref getRef(String needle) throws IOException { RefCache curr = readRefs(); for (String prefix : SEARCH_PATH) { DhtRef ref = curr.ids.get(prefix + needle); if (ref != null) { ref = resolve(ref, 0, curr.ids); return ref; } } return null; }
private DhtRef getOneRef(String refName) throws IOException { RefCache curr = readRefs(); DhtRef ref = curr.ids.get(refName); if (ref != null) return resolve(ref, 0, curr.ids); return ref; }
private DhtRef getOneRef(String refName) throws IOException { RefCache curr = readRefs(); DhtRef ref = curr.ids.get(refName); if (ref != null) return resolve(ref, 0, curr.ids); return ref; }
@Override public Ref getRef(String needle) throws IOException { RefCache curr = readRefs(); for (String prefix : SEARCH_PATH) { DhtRef ref = curr.ids.get(prefix + needle); if (ref != null) { ref = resolve(ref, 0, curr.ids); return ref; } } return null; }
@Override public boolean isNameConflicting(String refName) throws IOException { RefList<DhtRef> all = readRefs().ids; // Cannot be nested within an existing reference. int lastSlash = refName.lastIndexOf('/'); while (0 < lastSlash) { String needle = refName.substring(0, lastSlash); if (all.contains(needle)) return true; lastSlash = refName.lastIndexOf('/', lastSlash - 1); } // Cannot be the container of an existing reference. String prefix = refName + '/'; int idx = -(all.find(prefix) + 1); if (idx < all.size() && all.get(idx).getName().startsWith(prefix)) return true; return false; }
@Override public boolean isNameConflicting(String refName) throws IOException { RefList<DhtRef> all = readRefs().ids; // Cannot be nested within an existing reference. int lastSlash = refName.lastIndexOf('/'); while (0 < lastSlash) { String needle = refName.substring(0, lastSlash); if (all.contains(needle)) return true; lastSlash = refName.lastIndexOf('/', lastSlash - 1); } // Cannot be the container of an existing reference. String prefix = refName + '/'; int idx = -(all.find(prefix) + 1); if (idx < all.size() && all.get(idx).getName().startsWith(prefix)) return true; return false; }
@Override public Ref peel(Ref ref) throws IOException { final Ref oldLeaf = ref.getLeaf(); if (oldLeaf.isPeeled() || oldLeaf.getObjectId() == null) return ref; DhtRef newLeaf = doPeel(oldLeaf); RefCache cur = readRefs(); int idx = cur.ids.find(oldLeaf.getName()); if (0 <= idx && cur.ids.get(idx) == oldLeaf) { RefList<DhtRef> newList = cur.ids.set(idx, newLeaf); if (cache.compareAndSet(cur, new RefCache(newList, cur))) cachePeeledState(oldLeaf, newLeaf); } return recreate(ref, newLeaf); }
@Override public Ref peel(Ref ref) throws IOException { final Ref oldLeaf = ref.getLeaf(); if (oldLeaf.isPeeled() || oldLeaf.getObjectId() == null) return ref; DhtRef newLeaf = doPeel(oldLeaf); RefCache cur = readRefs(); int idx = cur.ids.find(oldLeaf.getName()); if (0 <= idx && cur.ids.get(idx) == oldLeaf) { RefList<DhtRef> newList = cur.ids.set(idx, newLeaf); if (cache.compareAndSet(cur, new RefCache(newList, cur))) cachePeeledState(oldLeaf, newLeaf); } return recreate(ref, newLeaf); }
@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 = 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()); }