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 testConstructor_Peeled() { ObjectIdRef r; r = new Unpeeled(Storage.Loose, name, ID_A); Assert.AreSame(Storage.Loose, r.getStorage()); Assert.AreSame(name, r.getName()); Assert.AreSame(ID_A, r.getObjectId()); Assert.IsFalse(r.isPeeled(), "not peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); Assert.AreSame(r, r.getLeaf(), "leaf is this"); Assert.AreSame(r, r.getTarget(), "target is this"); Assert.IsFalse(r.isSymbolic(), "not symbolic"); r = new PeeledNonTag(Storage.Loose, name, ID_A); Assert.IsTrue(r.isPeeled(), "is peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); r = new PeeledTag(Storage.Loose, name, ID_A, ID_B); Assert.IsTrue(r.isPeeled(), "is peeled"); Assert.AreSame(ID_B, r.getPeeledObjectId()); }
public void testLeaf() { global::GitSharp.Core.Ref a; SymbolicRef b, c, d; a = new PeeledTag(Storage.Packed, targetName, ID_A, ID_B); b = new SymbolicRef("B", a); c = new SymbolicRef("C", b); d = new SymbolicRef("D", c); Assert.AreSame(c, d.getTarget()); Assert.AreSame(b, c.getTarget()); Assert.AreSame(a, b.getTarget()); Assert.AreSame(a, d.getLeaf()); Assert.AreSame(a, c.getLeaf()); Assert.AreSame(a, b.getLeaf()); Assert.AreSame(a, a.getLeaf()); Assert.AreSame(ID_A, d.getObjectId()); Assert.AreSame(ID_A, c.getObjectId()); Assert.AreSame(ID_A, b.getObjectId()); Assert.IsTrue(d.isPeeled()); Assert.IsTrue(c.isPeeled()); Assert.IsTrue(b.isPeeled()); Assert.AreSame(ID_B, d.getPeeledObjectId()); Assert.AreSame(ID_B, c.getPeeledObjectId()); Assert.AreSame(ID_B, b.getPeeledObjectId()); }
public void testToString() { global::GitSharp.Core.Ref a; SymbolicRef b, c, d; a = new PeeledTag(Storage.Packed, targetName, ID_A, ID_B); b = new SymbolicRef("B", a); c = new SymbolicRef("C", b); d = new SymbolicRef("D", c); Assert.AreEqual("SymbolicRef[D -> C -> B -> " + targetName + "=" + ID_A.Name + "]", d.ToString()); }
private static RefList <Ref> parsePackedRefs(TextReader br) { var all = new RefList <Ref> .Builder <Ref>(); Ref last = null; bool peeled = false; bool needSort = false; string p; while ((p = br.ReadLine()) != null) { if (p[0] == '#') { if (p.StartsWith(PACKED_REFS_HEADER)) { p = p.Substring(PACKED_REFS_HEADER.Length); peeled = p.Contains(PACKED_REFS_PEELED); } continue; } if (p[0] == '^') { if (last == null) { throw new IOException("Peeled line before ref."); } ObjectId id = ObjectId.FromString(p.Substring(1)); last = new PeeledTag(Storage.Packed, last.getName(), last .getObjectId(), id); all.set(all.size() - 1, last); continue; } int sp = p.IndexOf(' '); ObjectId id2 = ObjectId.FromString(p.Slice(0, sp)); string name = copy(p, sp + 1, p.Length); ObjectIdRef cur; if (peeled) { cur = new PeeledNonTag(Storage.Packed, name, id2); } else { cur = new Unpeeled(Storage.Packed, name, id2); } if (last != null && RefComparator.compareTo(last, cur) > 0) { needSort = true; } all.add(cur); last = cur; } if (needSort) { all.sort(); } return(all.toRefList()); }