public void testEmptyBuilder() { RefList <global::GitSharp.Core.Ref> list = new RefList <global::GitSharp.Core.Ref> .Builder <global::GitSharp.Core.Ref>().toRefList(); Assert.AreEqual(0, list.size()); Assert.IsFalse(list.iterator().hasNext()); Assert.AreEqual(-1, list.find("a")); Assert.AreEqual(-1, list.find("z")); Assert.IsFalse(list.contains("a")); Assert.IsNull(list.get("a")); Assert.IsTrue(list.asList().Count == 0); Assert.AreEqual("[]", list.ToString()); // default array capacity should be 16, with no bounds checking. Assert.IsNull(list.get(16 - 1)); try { list.get(16); Assert.Fail("default RefList should have 16 element array"); } catch (IndexOutOfRangeException) { // expected } }
public void testFindContainsGet() { RefList <global::GitSharp.Core.Ref> list = toList(REF_A, REF_B, REF_c); Assert.AreEqual(0, list.find("A")); Assert.AreEqual(1, list.find("B")); Assert.AreEqual(2, list.find("c")); Assert.AreEqual(-1, list.find("0")); Assert.AreEqual(-2, list.find("AB")); Assert.AreEqual(-3, list.find("a")); Assert.AreEqual(-4, list.find("z")); Assert.AreSame(REF_A, list.get("A")); Assert.AreSame(REF_B, list.get("B")); Assert.AreSame(REF_c, list.get("c")); Assert.IsNull(list.get("AB")); Assert.IsNull(list.get("z")); Assert.IsTrue(list.contains("A")); Assert.IsTrue(list.contains("B")); Assert.IsTrue(list.contains("c")); Assert.IsFalse(list.contains("AB")); Assert.IsFalse(list.contains("z")); }
public void testAddToMiddleOfListByInsertionPosition() { RefList <global::GitSharp.Core.Ref> one = toList(REF_A, REF_c); Assert.AreEqual(-2, one.find(REF_B.Name)); RefList <global::GitSharp.Core.Ref> two = one.add(one.find(REF_B.Name), REF_B); Assert.AreNotSame(one, two); // one is not modified, but two is Assert.AreEqual(2, one.size()); Assert.AreSame(REF_A, one.get(0)); Assert.AreSame(REF_c, one.get(1)); Assert.AreEqual(3, two.size()); Assert.AreSame(REF_A, two.get(0)); Assert.AreSame(REF_B, two.get(1)); Assert.AreSame(REF_c, two.get(2)); }
public void testEmpty() { RefList <global::GitSharp.Core.Ref> list = RefList <global::GitSharp.Core.Ref> .emptyList(); Assert.AreEqual(0, list.size()); Assert.IsTrue(list.isEmpty()); Assert.IsFalse(list.iterator().hasNext()); Assert.AreEqual(-1, list.find("a")); Assert.AreEqual(-1, list.find("z")); Assert.IsFalse(list.contains("a")); Assert.IsNull(list.get("a")); try { list.get(0); Assert.Fail("RefList.emptyList should have 0 element array"); } catch (IndexOutOfRangeException) { // expected } }
public void testEmptyBuilder() { RefList<global::GitSharp.Core.Ref> list = new RefList<global::GitSharp.Core.Ref>.Builder<global::GitSharp.Core.Ref>().toRefList(); Assert.AreEqual(0, list.size()); Assert.IsFalse(list.iterator().hasNext()); Assert.AreEqual(-1, list.find("a")); Assert.AreEqual(-1, list.find("z")); Assert.IsFalse(list.contains("a")); Assert.IsNull(list.get("a")); Assert.IsTrue(list.asList().Count == 0); Assert.AreEqual("[]", list.ToString()); // default array capacity should be 16, with no bounds checking. Assert.IsNull(list.get(16 - 1)); try { list.get(16); Assert.Fail("default RefList should have 16 element array"); } catch (IndexOutOfRangeException) { // expected } }
private Ref resolve(Ref @ref, int depth, string prefix, RefList <LooseRef> loose, RefList <Ref> packed) { if (@ref.isSymbolic()) { Ref dst = @ref.getTarget(); if (MAX_SYMBOLIC_REF_DEPTH <= depth) { return(null); // claim it doesn't exist } // If the cached value can be assumed to be current due to a // recent scan of the loose directory, use it. if (loose != null && dst.getName().StartsWith(prefix)) { int idx; if (0 <= (idx = loose.find(dst.getName()))) { dst = loose.get(idx); } else if (0 <= (idx = packed.find(dst.getName()))) { dst = packed.get(idx); } else { return(@ref); } } else { dst = readRef(dst.getName(), packed); if (dst == null) { return(@ref); } } dst = resolve(dst, depth + 1, prefix, loose, packed); if (dst == null) { return(null); } return(new SymbolicRef(@ref.getName(), dst)); } return(@ref); }
public override Ref peel(Ref @ref) { Ref leaf = @ref.getLeaf(); if (leaf.isPeeled() || leaf.getObjectId() == null) { return(@ref); } RevWalk.RevWalk rw = new RevWalk.RevWalk(getRepository()); RevObject obj = rw.parseAny(leaf.getObjectId()); ObjectIdRef newLeaf; if (obj is RevTag) { do { obj = rw.parseAny(((RevTag)obj).getObject()); } while (obj is RevTag); newLeaf = new PeeledTag(leaf.getStorage(), leaf .getName(), leaf.getObjectId(), obj.Copy()); } else { newLeaf = new PeeledNonTag(leaf.getStorage(), leaf .getName(), leaf.getObjectId()); } // Try to remember this peeling in the cache, so we don't have to do // it again in the future, but only if the reference is unchanged. if (leaf.getStorage().IsLoose) { RefList <LooseRef> curList = looseRefs.get(); int idx = curList.find(leaf.getName()); if (0 <= idx && curList.get(idx) == leaf) { LooseRef asPeeled = ((LooseRef)leaf).peel(newLeaf); RefList <LooseRef> newList = curList.set(idx, asPeeled); looseRefs.compareAndSet(curList, newList); } } return(recreate(@ref, newLeaf)); }
public void scan(string prefix) { if (ALL.Equals(prefix)) { scanOne(Constants.HEAD); scanTree(Constants.R_REFS, _refDirectory.refsDir); // If any entries remain, they are deleted, drop them. if (newLoose == null && curIdx < curLoose.size()) { newLoose = curLoose.copy(curIdx); } } else if (prefix.StartsWith(Constants.R_REFS) && prefix.EndsWith("/")) { curIdx = -(curLoose.find(prefix) + 1); DirectoryInfo dir = PathUtil.CombineDirectoryPath(_refDirectory.refsDir, prefix.Substring(Constants.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++)); } } } }
private Ref readRef(string name, RefList <Ref> packed) { RefList <LooseRef> curList = looseRefs.get(); int idx = curList.find(name); if (0 <= idx) { LooseRef o = curList.get(idx); LooseRef n = scanRef(o, name); if (n == null) { if (looseRefs.compareAndSet(curList, curList.remove(idx))) { modCnt.incrementAndGet(); } return(packed.get(name)); } if (o == n) { return(n); } if (looseRefs.compareAndSet(curList, curList.set(idx, n))) { modCnt.incrementAndGet(); } return(n); } LooseRef n2 = scanRef(null, name); if (n2 == null) { return(packed.get(name)); } if (looseRefs.compareAndSet(curList, curList.add(idx, n2))) { modCnt.incrementAndGet(); } return(n2); }
public override bool isNameConflicting(string name) { RefList <Ref> packed = getPackedRefs(); RefList <LooseRef> loose = getLooseRefs(); // Cannot be nested within an existing reference. int lastSlash = name.LastIndexOf('/'); while (0 < lastSlash) { string needle = name.Slice(0, lastSlash); if (loose.contains(needle) || packed.contains(needle)) { return(true); } lastSlash = name.LastIndexOf('/', lastSlash - 1); } // Cannot be the container of an existing reference. string prefix = name + '/'; int idx; idx = -(packed.find(prefix) + 1); if (idx < packed.size() && packed.get(idx).getName().StartsWith(prefix)) { return(true); } idx = -(loose.find(prefix) + 1); if (idx < loose.size() && loose.get(idx).getName().StartsWith(prefix)) { return(true); } return(false); }