/// <summary> /// Create reverse index from straight/forward pack index, by indexing all /// its entries. /// </summary> /// <param name="packIndex"> /// Forward index - entries to (reverse) index. /// </param> public PackReverseIndex(PackIndex packIndex) { _index = packIndex; long cnt = _index.ObjectCount; long n64 = _index.Offset64Count; long n32 = cnt - n64; if (n32 > int.MaxValue || n64 > int.MaxValue || cnt > 0xffffffffL) { throw new ArgumentException("Huge indexes are not supported, yet"); } _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.Offset; if (o < int.MaxValue) { _offsets32[i32++] = (int)o; } else { _offsets64[i64++] = o; } } Array.Sort(_offsets32); Array.Sort(_offsets64); int nth = 0; foreach (PackIndex.MutableEntry me in _index) { long o = me.Offset; if (o < int.MaxValue) { _nth32[Array.BinarySearch(_offsets32, (int)o)] = nth++; } else { _nth64[Array.BinarySearch(_offsets64, o)] = nth++; } } }
/// <summary> /// Close the resources utilized by this repository. /// </summary> public void Close() { UnpackedObjectCache.purge(this); WindowCache.Purge(this); lock (locker) { _loadedIdx = null; _reverseIdx = null; } #if DEBUG GC.SuppressFinalize(this); // Disarm lock-release checker #endif }
private void OnOpenPack() { PackIndex idx = LoadPackIndex(); var buf = new byte[20]; IO.ReadFully(_fd, 0, buf, 0, 12); if (RawParseUtils.match(buf, 0, Constants.PACK_SIGNATURE) != 4) { throw new IOException("Not a PACK file."); } long vers = NB.decodeUInt32(buf, 4); long packCnt = NB.decodeUInt32(buf, 8); if (vers != 2 && vers != 3) { throw new IOException("Unsupported pack version " + vers + "."); } if (packCnt != idx.ObjectCount) { throw new PackMismatchException("Pack object count mismatch:" + " pack " + packCnt + " index " + idx.ObjectCount + ": " + File.FullName); } IO.ReadFully(_fd, Length - 20, buf, 0, 20); if (!buf.SequenceEqual(_packChecksum)) { throw new PackMismatchException("Pack checksum mismatch:" + " pack " + ObjectId.FromRaw(buf) + " index " + ObjectId.FromRaw(idx.PackChecksum) + ": " + File.FullName); } }
private PackIndex LoadPackIndex() { lock (locker) { if (_loadedIdx == null) { if (_invalid) { throw new PackInvalidException(_packFile.FullName); } try { PackIndex idx = PackIndex.Open(_idxFile); if (_packChecksum == null) { _packChecksum = idx.PackChecksum; } else if (_packChecksum.SequenceEqual(idx.PackChecksum)) { throw new PackMismatchException("Pack checksum mismatch"); } _loadedIdx = idx; } catch (IOException) { _invalid = true; throw; } } } return(_loadedIdx); }
protected EntriesIterator(PackIndex packIndex) { _packIndex = packIndex; }