private static AnyObjectId Id(int first) { MutableObjectId id = new MutableObjectId(); id.SetByte(1, first); return(id); }
/// <exception cref="System.IO.IOException"></exception> internal override int EstimateSize(AnyObjectId noteOn, ObjectReader or) { // If most of this fan-out is full, estimate it should still be split. if (LeafBucket.MAX_SIZE * 3 / 4 <= cnt) { return(1 + LeafBucket.MAX_SIZE); } // Due to the uniform distribution of ObjectIds, having less nodes full // indicates a good chance the total number of children below here // is less than the MAX_SIZE split point. Get a more accurate count. MutableObjectId id = new MutableObjectId(); id.FromObjectId(noteOn); int sz = 0; for (int cell = 0; cell < 256; cell++) { NoteBucket b = table[cell]; if (b == null) { continue; } id.SetByte(prefixLen >> 1, cell); sz += b.EstimateSize(id, or); if (LeafBucket.MAX_SIZE < sz) { break; } } return(sz); }
public virtual void TestEditFlat() { RevBlob a = tr.Blob("a"); RevBlob b = tr.Blob("b"); RevBlob data1 = tr.Blob("data1"); RevBlob data2 = tr.Blob("data2"); RevCommit r = tr.Commit().Add(a.Name, data1).Add(b.Name, data2).Add(".gitignore", string.Empty).Add("zoo-animals.txt", b).Create(); // // // // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); map.Set(a, data2); map.Set(b, null); map.Set(data1, b); map.Set(data2, null); NUnit.Framework.Assert.AreEqual(data2, map.Get(a)); NUnit.Framework.Assert.AreEqual(b, map.Get(data1)); NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b"); NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2"); MutableObjectId id = new MutableObjectId(); for (int p = 42; p > 0; p--) { id.SetByte(1, p); map.Set(id, data1); } for (int p_1 = 42; p_1 > 0; p_1--) { id.SetByte(1, p_1); NUnit.Framework.Assert.IsTrue(map.Contains(id), "contains " + id); } RevCommit n = CommitNoteMap(map); map = NoteMap.Read(reader, n); NUnit.Framework.Assert.AreEqual(data2, map.Get(a)); NUnit.Framework.Assert.AreEqual(b, map.Get(data1)); NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b"); NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2"); NUnit.Framework.Assert.AreEqual(b, TreeWalk.ForPath(reader, "zoo-animals.txt", n. Tree).GetObjectId(0)); }
public virtual void TestLeafSplitsWhenFull() { RevBlob data1 = tr.Blob("data1"); MutableObjectId idBuf = new MutableObjectId(); RevCommit r = tr.Commit().Add(data1.Name, data1).Create(); // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); for (int i = 0; i < 254; i++) { idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i); map.Set(idBuf, data1); } RevCommit n = CommitNoteMap(map); TreeWalk tw = new TreeWalk(reader); tw.Reset(n.Tree); while (tw.Next()) { NUnit.Framework.Assert.IsFalse(tw.IsSubtree, "no fan-out subtree"); } for (int i_1 = 254; i_1 < 256; i_1++) { idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i_1); map.Set(idBuf, data1); } idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 2, 1); map.Set(idBuf, data1); n = CommitNoteMap(map); // The 00 bucket is fully split. string path = Fanout(38, idBuf.Name); tw = TreeWalk.ForPath(reader, path, n.Tree); NUnit.Framework.Assert.IsNotNull(tw, "has " + path); // The other bucket is not. path = Fanout(2, data1.Name); tw = TreeWalk.ForPath(reader, path, n.Tree); NUnit.Framework.Assert.IsNotNull(tw, "has " + path); }
/// <exception cref="System.IO.IOException"></exception> private InMemoryNoteBucket MergeFanoutBucket(int treeDepth, FanoutBucket @base, FanoutBucket ours, FanoutBucket theirs) { FanoutBucket result = new FanoutBucket(treeDepth * 2); // walking through entries of base, ours, theirs for (int i = 0; i < 256; i++) { NoteBucket b = @base.GetBucket(i); NoteBucket o = ours.GetBucket(i); NoteBucket t = theirs.GetBucket(i); if (Equals(o, t)) { AddIfNotNull(result, i, o); } else { if (Equals(b, o)) { AddIfNotNull(result, i, t); } else { if (Equals(b, t)) { AddIfNotNull(result, i, o); } else { objectIdPrefix.SetByte(treeDepth, i); InMemoryNoteBucket mergedBucket = Merge(treeDepth + 1, FanoutBucket.LoadIfLazy(b, objectIdPrefix, reader), FanoutBucket.LoadIfLazy(o, objectIdPrefix, reader), FanoutBucket .LoadIfLazy(t, objectIdPrefix, reader)); result.SetBucket(i, mergedBucket); } } } } return(result.ContractIfTooSmall(objectIdPrefix, reader)); }