示例#1
0
 private void AssertContent(PackIndex pi, IList <ObjectId> expected)
 {
     NUnit.Framework.Assert.AreEqual(expected.Count, pi.GetObjectCount(), "Pack index has wrong size."
                                     );
     for (int i = 0; i < pi.GetObjectCount(); i++)
     {
         NUnit.Framework.Assert.IsTrue(expected.Contains(pi.GetObjectId(i)), "Pack index didn't contain the expected id "
                                       + pi.GetObjectId(i));
     }
 }
 /// <summary>
 /// Search for object id with the specified start offset in this pack
 /// (reverse) index.
 /// </summary>
 /// <remarks>
 /// Search for object id with the specified start offset in this pack
 /// (reverse) index.
 /// </remarks>
 /// <param name="offset">start offset of object to find.</param>
 /// <returns>object id for this offset, or null if no object was found.</returns>
 public virtual ObjectId FindObject(long offset)
 {
     if (offset <= int.MaxValue)
     {
         int i32 = System.Array.BinarySearch(offsets32, (int)offset);
         if (i32 < 0)
         {
             return(null);
         }
         return(index.GetObjectId(nth32[i32]));
     }
     else
     {
         int i64 = System.Array.BinarySearch(offsets64, offset);
         if (i64 < 0)
         {
             return(null);
         }
         return(index.GetObjectId(nth64[i64]));
     }
 }
示例#3
0
        public virtual void TestWriteIndex()
        {
            config.SetIndexVersion(2);
            WriteVerifyPack4(false);
            FilePath packFile  = pack.GetPackFile();
            string   name      = packFile.GetName();
            string   @base     = Sharpen.Runtime.Substring(name, 0, name.LastIndexOf('.'));
            FilePath indexFile = new FilePath(packFile.GetParentFile(), @base + ".idx");
            // Validate that IndexPack came up with the right CRC32 value.
            PackIndex idx1 = PackIndex.Open(indexFile);

            NUnit.Framework.Assert.IsTrue(idx1 is PackIndexV2);
            NUnit.Framework.Assert.AreEqual(unchecked ((long)(0x4743F1E4L)), idx1.FindCRC32(ObjectId
                                                                                            .FromString("82c6b885ff600be425b4ea96dee75dca255b69e7")));
            // Validate that an index written by PackWriter is the same.
            FilePath         idx2File = new FilePath(indexFile.GetAbsolutePath() + ".2");
            FileOutputStream @is      = new FileOutputStream(idx2File);

            try
            {
                writer.WriteIndex(@is);
            }
            finally
            {
                @is.Close();
            }
            PackIndex idx2 = PackIndex.Open(idx2File);

            NUnit.Framework.Assert.IsTrue(idx2 is PackIndexV2);
            NUnit.Framework.Assert.AreEqual(idx1.GetObjectCount(), idx2.GetObjectCount());
            NUnit.Framework.Assert.AreEqual(idx1.GetOffset64Count(), idx2.GetOffset64Count());
            for (int i = 0; i < idx1.GetObjectCount(); i++)
            {
                ObjectId id = idx1.GetObjectId(i);
                NUnit.Framework.Assert.AreEqual(id, idx2.GetObjectId(i));
                NUnit.Framework.Assert.AreEqual(idx1.FindOffset(id), idx2.FindOffset(id));
                NUnit.Framework.Assert.AreEqual(idx1.FindCRC32(id), idx2.FindCRC32(id));
            }
        }