Esempio n. 1
0
		public virtual void TestEmpty()
		{
			LeafBucket b = new LeafBucket(0);
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0x00))), null));
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0x01))), null));
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0xfe))), null));
		}
Esempio n. 2
0
		public virtual void TestParseFive()
		{
			LeafBucket b = new LeafBucket(0);
			b.ParseOneEntry(Id(unchecked((int)(0x11))), Id(unchecked((int)(0x81))));
			b.ParseOneEntry(Id(unchecked((int)(0x22))), Id(unchecked((int)(0x82))));
			b.ParseOneEntry(Id(unchecked((int)(0x33))), Id(unchecked((int)(0x83))));
			b.ParseOneEntry(Id(unchecked((int)(0x44))), Id(unchecked((int)(0x84))));
			b.ParseOneEntry(Id(unchecked((int)(0x55))), Id(unchecked((int)(0x85))));
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0x01))), null));
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x81))), b.GetNote(Id(unchecked(
				(int)(0x11))), null).GetData());
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x82))), b.GetNote(Id(unchecked(
				(int)(0x22))), null).GetData());
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x83))), b.GetNote(Id(unchecked(
				(int)(0x33))), null).GetData());
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x84))), b.GetNote(Id(unchecked(
				(int)(0x44))), null).GetData());
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x85))), b.GetNote(Id(unchecked(
				(int)(0x55))), null).GetData());
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0x66))), null));
		}
Esempio n. 3
0
		/// <exception cref="System.IO.IOException"></exception>
		private ObjectId Write(NonNoteEntry list)
		{
			LeafBucket b = new LeafBucket(0);
			b.nonNotes = list;
			return b.WriteTree(inserter);
		}
Esempio n. 4
0
		private static Note Get(LeafBucket b, int i)
		{
			return i < b.Size() ? b.Get(i) : null;
		}
Esempio n. 5
0
		private static LeafBucket NotNullOrEmpty(LeafBucket b)
		{
			return b != null ? b : EMPTY_LEAF;
		}
Esempio n. 6
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private InMemoryNoteBucket MergeLeafBucket(int treeDepth, LeafBucket bb, LeafBucket
			 ob, LeafBucket tb)
		{
			bb = NotNullOrEmpty(bb);
			ob = NotNullOrEmpty(ob);
			tb = NotNullOrEmpty(tb);
			InMemoryNoteBucket result = new LeafBucket(treeDepth * 2);
			int bi = 0;
			int oi = 0;
			int ti = 0;
			while (bi < bb.Size() || oi < ob.Size() || ti < tb.Size())
			{
				Note b = Get(bb, bi);
				Note o = Get(ob, oi);
				Note t = Get(tb, ti);
				Note min = Min(b, o, t);
				b = SameNoteOrNull(min, b);
				o = SameNoteOrNull(min, o);
				t = SameNoteOrNull(min, t);
				if (SameContent(o, t))
				{
					result = AddIfNotNull(result, o);
				}
				else
				{
					if (SameContent(b, o))
					{
						result = AddIfNotNull(result, t);
					}
					else
					{
						if (SameContent(b, t))
						{
							result = AddIfNotNull(result, o);
						}
						else
						{
							result = AddIfNotNull(result, noteMerger.Merge(b, o, t, reader, inserter));
						}
					}
				}
				if (b != null)
				{
					bi++;
				}
				if (o != null)
				{
					oi++;
				}
				if (t != null)
				{
					ti++;
				}
			}
			return result;
		}
Esempio n. 7
0
		private LeafBucket ParseLeafTree()
		{
			LeafBucket leaf = new LeafBucket(prefix.Length);
			MutableObjectId idBuf = new MutableObjectId();
			for (; !Eof; Next(1))
			{
				if (ParseObjectId(idBuf))
				{
					leaf.ParseOneEntry(idBuf, EntryObjectId);
				}
				else
				{
					StoreNonNote();
				}
			}
			return leaf;
		}
Esempio n. 8
0
		/// <summary>Attach (or remove) a note on an object.</summary>
		/// <remarks>
		/// Attach (or remove) a note on an object.
		/// If no note exists, a new note is stored. If a note already exists for the
		/// given object, it is replaced (or removed).
		/// This method only updates the map in memory.
		/// If the caller wants to attach a UTF-8 encoded string message to an
		/// object,
		/// <see cref="Set(NGit.AnyObjectId, string, NGit.ObjectInserter)">Set(NGit.AnyObjectId, string, NGit.ObjectInserter)
		/// 	</see>
		/// is a convenient
		/// way to encode and update a note in one step.
		/// </remarks>
		/// <param name="noteOn">
		/// the object to attach the note to. This same ObjectId can later
		/// be used as an argument to
		/// <see cref="Get(NGit.AnyObjectId)">Get(NGit.AnyObjectId)</see>
		/// or
		/// <see cref="GetCachedBytes(NGit.AnyObjectId, int)">GetCachedBytes(NGit.AnyObjectId, int)
		/// 	</see>
		/// to read back the
		/// <code>noteData</code>
		/// .
		/// </param>
		/// <param name="noteData">
		/// data to associate with the note. This must be the ObjectId of
		/// a blob that already exists in the repository. If null the note
		/// will be deleted, if present.
		/// </param>
		/// <exception cref="System.IO.IOException">a portion of the note space is not accessible.
		/// 	</exception>
		public virtual void Set(AnyObjectId noteOn, ObjectId noteData)
		{
			InMemoryNoteBucket newRoot = root.Set(noteOn, noteData, reader);
			if (newRoot == null)
			{
				newRoot = new LeafBucket(0);
				newRoot.nonNotes = root.nonNotes;
			}
			root = newRoot;
		}
Esempio n. 9
0
		public virtual void TestSetFive_InOrder()
		{
			LeafBucket b = new LeafBucket(0);
			NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked((int)(0x11))), Id(unchecked(
				(int)(0x81))), null));
			NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked((int)(0x22))), Id(unchecked(
				(int)(0x82))), null));
			NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked((int)(0x33))), Id(unchecked(
				(int)(0x83))), null));
			NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked((int)(0x44))), Id(unchecked(
				(int)(0x84))), null));
			NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked((int)(0x55))), Id(unchecked(
				(int)(0x85))), null));
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0x01))), null));
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x81))), b.GetNote(Id(unchecked(
				(int)(0x11))), null).GetData());
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x82))), b.GetNote(Id(unchecked(
				(int)(0x22))), null).GetData());
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x83))), b.GetNote(Id(unchecked(
				(int)(0x33))), null).GetData());
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x84))), b.GetNote(Id(unchecked(
				(int)(0x44))), null).GetData());
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x85))), b.GetNote(Id(unchecked(
				(int)(0x55))), null).GetData());
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0x66))), null));
		}
Esempio n. 10
0
		public virtual void TestRemoveMakesEmpty()
		{
			LeafBucket b = new LeafBucket(0);
			NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked((int)(0x11))), Id(unchecked(
				(int)(0x81))), null));
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x81))), b.GetNote(Id(unchecked(
				(int)(0x11))), null).GetData());
			NUnit.Framework.Assert.IsNull(b.Set(Id(unchecked((int)(0x11))), null, null));
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0x11))), null));
		}
Esempio n. 11
0
		public virtual void TestRemoveMissingNote()
		{
			LeafBucket b = new LeafBucket(0);
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0x11))), null));
			NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked((int)(0x11))), null, null));
			NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked((int)(0x11))), null));
		}
Esempio n. 12
0
		public virtual void TestSet_Replace()
		{
			LeafBucket b = new LeafBucket(0);
			NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked((int)(0x11))), Id(unchecked(
				(int)(0x81))), null));
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x81))), b.GetNote(Id(unchecked(
				(int)(0x11))), null).GetData());
			NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked((int)(0x11))), Id(unchecked(
				(int)(0x01))), null));
			NUnit.Framework.Assert.AreEqual(Id(unchecked((int)(0x01))), b.GetNote(Id(unchecked(
				(int)(0x11))), null).GetData());
		}