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()); }
private static void readPackedRefsImpl(Dictionary <string, Ref> avail, StreamReader sr) { Ref last = null; bool peeled = false; for (; ;) { string line = sr.ReadLine(); if (line == null) { break; } if (line[0] == '#') { if (line.StartsWith(RefDirectory.PACKED_REFS_HEADER)) { line = line.Substring(RefDirectory.PACKED_REFS_HEADER.Length); peeled = line.Contains(RefDirectory.PACKED_REFS_PEELED); } continue; } if (line[0] == '^') { if (last == null) { throw new TransportException("Peeled line before ref"); } ObjectId pid = ObjectId.FromString(line.Substring(1)); last = new PeeledTag(Storage.Packed, last.Name, last.ObjectId, pid); avail.put(last.Name, last); continue; } int sp = line.IndexOf(' '); if (sp < 0) { throw new TransportException("Unrecognized ref: " + line); } ObjectId id = ObjectId.FromString(line.Slice(0, sp)); string name = line.Substring(sp + 1); if (peeled) { last = new PeeledNonTag(Storage.Packed, name, id); } else { last = new Unpeeled(Storage.Packed, name, id); } avail.put(last.Name, last); } }
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()); }
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()); }
private static void readPackedRefsImpl(Dictionary<string, Ref> avail, StreamReader sr) { Ref last = null; bool peeled = false; for (; ; ) { string line = sr.ReadLine(); if (line == null) break; if (line[0] == '#') { if (line.StartsWith(RefDirectory.PACKED_REFS_HEADER)) { line = line.Substring(RefDirectory.PACKED_REFS_HEADER.Length); peeled = line.Contains(RefDirectory.PACKED_REFS_PEELED); } continue; } if (line[0] == '^') { if (last == null) throw new TransportException("Peeled line before ref"); ObjectId pid = ObjectId.FromString(line.Substring(1)); last = new PeeledTag(Storage.Packed, last.Name, last.ObjectId, pid); avail.put(last.Name, last); continue; } int sp = line.IndexOf(' '); if (sp < 0) throw new TransportException("Unrecognized ref: " + line); ObjectId id = ObjectId.FromString(line.Slice(0, sp)); string name = line.Substring(sp + 1); if (peeled) last = new PeeledNonTag(Storage.Packed, name, id); else last = new Unpeeled(Storage.Packed, name, id); avail.put(last.Name, last); } }
private void readAdvertisedRefsImpl() { var avail = new Dictionary<string, Ref>(); while (true) { string line; try { line = pckIn.ReadString(); } catch (EndOfStreamException) { if (avail.Count == 0) { throw noRepository(); } throw; } if (avail.Count == 0) { int nul = line.IndexOf('\0'); if (nul >= 0) { foreach (string c in line.Substring(nul + 1).Split(' ')) remoteCapabilies.Add(c); line = line.Slice(0, nul); } } if (line.Length == 0) break; string name = line.Slice(41, line.Length); if (avail.Count == 0 && name.Equals("capabilities^{}")) { continue; } string idname = line.Slice(0, 40); ObjectId id = ObjectId.FromString(idname); if (name.Equals(".have")) additionalHaves.Add(id); else if (name.EndsWith("^{}")) { name = name.Slice(0, name.Length - 3); Ref prior = avail.ContainsKey(name) ? avail[name] : null; if (prior == null) throw new PackProtocolException(uri, "advertisement of " + name + "^{} came before " + name); if (prior.PeeledObjectId != null) throw duplicateAdvertisement(name + "^{}"); avail[name] = new PeeledTag(Storage.Network, name, prior.ObjectId, id); } else { Ref prior = avail.ContainsKey(name) ? avail[name] : null; if (prior != null) throw duplicateAdvertisement(name); avail.Add(name, new PeeledNonTag(Storage.Network, name, id)); } } available(avail); }