/// <summary>
        /// Create reverse index from straight/forward pack index, by indexing all
        /// its entries.
        /// </summary>
        /// <remarks>
        /// Create reverse index from straight/forward pack index, by indexing all
        /// its entries.
        /// </remarks>
        /// <param name="packIndex">forward index - entries to (reverse) index.</param>
        public PackReverseIndex(PackIndex packIndex)
        {
            index = packIndex;
            long cnt = index.GetObjectCount();
            long n64 = index.GetOffset64Count();
            long n32 = cnt - n64;

            if (n32 > int.MaxValue || n64 > int.MaxValue || cnt > unchecked ((long)(0xffffffffL
                                                                                    )))
            {
                throw new ArgumentException(JGitText.Get().hugeIndexesAreNotSupportedByJgitYet);
            }
            offsets32 = new int[(int)n32];
            offsets64 = new long[(int)n64];
            nth32     = new int[offsets32.Length];
            nth64     = new int[offsets64.Length];
            int i32 = 0;
            int i64 = 0;

            foreach (PackIndex.MutableEntry me in index)
            {
                long o = me.GetOffset();
                if (o < int.MaxValue)
                {
                    offsets32[i32++] = (int)o;
                }
                else
                {
                    offsets64[i64++] = o;
                }
            }
            Arrays.Sort(offsets32);
            Arrays.Sort(offsets64);
            int nth = 0;

            foreach (PackIndex.MutableEntry me_1 in index)
            {
                long o = me_1.GetOffset();
                if (o < int.MaxValue)
                {
                    nth32[System.Array.BinarySearch(offsets32, (int)o)] = nth++;
                }
                else
                {
                    nth64[System.Array.BinarySearch(offsets64, o)] = nth++;
                }
            }
        }
Esempio n. 2
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));
            }
        }