/// <param name="refs"> /// the complete set of references. This should have been computed /// by applying updates to the advertised refs already discovered. /// </param> protected RefWriter(IDictionary <String, Ref> refs) { if (refs is RefMap) { this.refs = refs.Values; } else { this.refs = RefComparator.Sort(refs.Values); } }
/** * @param refs * the complete set of references. This should have been computed * by applying updates to the advertised refs already discovered. */ protected RefWriter(IEnumerable <Ref> refs) { this.refs = RefComparator.Sort(refs); }
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()); }
private void scanOne(string name) { LooseRef cur; if (curIdx < curLoose.size()) { do { cur = curLoose.get(curIdx); int cmp = RefComparator.compareTo(cur, name); if (cmp < 0) { // Reference is not loose anymore, its been deleted. // Skip the name in the new result list. if (newLoose == null) { newLoose = curLoose.copy(curIdx); } curIdx++; cur = null; continue; } if (cmp > 0) // Newly discovered loose reference. { cur = null; } break; } while (curIdx < curLoose.size()); } else { cur = null; // Newly discovered loose reference. } LooseRef n; try { n = _refDirectory.scanRef(cur, name); } catch (IOException) { n = null; } if (n != null) { if (cur != n && newLoose == null) { newLoose = curLoose.copy(curIdx); } if (newLoose != null) { newLoose.add(n); } if (n.isSymbolic()) { symbolic.add(n); } } else if (cur != null) { // Tragically, this file is no longer a loose reference. // Kill our cached entry of it. if (newLoose == null) { newLoose = curLoose.copy(curIdx); } } if (cur != null) { curIdx++; } }