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 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 static Dictionary<string, Ref> ReadAdvertisedImpl(TextReader br) { var avail = new Dictionary<string, Ref>(); while (true) { string line = br.ReadLine(); if (line == null) break; int tab = line.IndexOf('\t'); if (tab < 0) { throw InvalidAdvertisement(line); } string name = line.Substring(tab + 1); ObjectId id = ObjectId.FromString(line.Slice(0, tab)); if (name.EndsWith("^{}")) { name = name.Slice(0, name.Length - 3); Ref prior = avail[name]; if (prior == null) { throw OutOfOrderAdvertisement(name); } if (prior.PeeledObjectId != null) { throw DuplicateAdvertisement(name + "^{}"); } avail.Add(name, new PeeledTag(Storage.Network, name, prior.ObjectId, id)); } else { Ref prior = null; if (avail.ContainsKey(name)) { prior = avail[name]; avail[name] = new PeeledNonTag(Storage.Network, name, id); } else { avail.Add(name, new PeeledNonTag(Storage.Network, name, id)); } if (prior != null) { throw DuplicateAdvertisement(name); } } } return avail; }