private ObjectLoader OpenObjectImpl1(WindowCursor curs, AnyObjectId objectId) { ObjectLoader ldr = openObject1(curs, objectId); if (ldr != null) { return(ldr); } foreach (ObjectDatabase alt in getAlternates()) { ldr = alt.OpenObjectImpl1(curs, objectId); if (ldr != null) { return(ldr); } } if (tryAgain1()) { ldr = openObject1(curs, objectId); if (ldr != null) { return(ldr); } } return(null); }
public override void Materialize(WindowCursor curs) { if (CachedBytes != null) { return; } if (Type != ObjCommit) { UnpackedObjectCache.Entry cache = PackFile.readCache(DataOffset); if (cache != null) { curs.Release(); CachedBytes = cache.data; return; } } try { CachedBytes = PackFile.decompress(DataOffset, Size, curs); curs.Release(); if (Type != ObjCommit) { PackFile.saveCache(DataOffset, CachedBytes, Type); } } catch (IOException dfe) { throw new CorruptObjectException("object at " + DataOffset + " in " + PackFile.File.FullName + " has bad zlib stream", dfe); } }
private void ReadFully(long position, byte[] dstbuf, int dstoff, int cnt, WindowCursor curs) { if (curs.Copy(this, position, dstbuf, dstoff, cnt) != cnt) { throw new EndOfStreamException(); } }
/// <summary> /// Open the object from all packs containing it. /// <para /> /// If any alternates are present, their packs are also considered. /// </summary> /// <param name="out"> /// Result collection of loaders for this object, filled with /// loaders from all packs containing specified object /// </param> /// <param name="windowCursor"> /// Temporary working space associated with the calling thread. /// </param> /// <param name="objectId"><see cref="ObjectId"/> of object to search for.</param> public void OpenObjectInAllPacks(ICollection <PackedObjectLoader> @out, WindowCursor windowCursor, AnyObjectId objectId) { OpenObjectInAllPacksImplementation(@out, windowCursor, objectId); foreach (ObjectDatabase alt in getAlternates()) { alt.OpenObjectInAllPacksImplementation(@out, windowCursor, objectId); } }
/// <summary> /// Release the window cursor. /// </summary> /// <param name="cursor">cursor to Release; may be null. /// </param> /// <returns>always null</returns> public static WindowCursor Release(WindowCursor cursor) { if (cursor != null) { cursor.Release(); } return(null); }
public override ObjectLoader openObject2(WindowCursor curs, String objectName, AnyObjectId objectId) { if (_unpackedObjects.Get(objectId) == null) { return(null); } return(base.openObject2(curs, objectName, objectId)); }
public override PackedObjectLoader GetBaseLoader(WindowCursor curs) { PackedObjectLoader or = PackFile.Get(curs, _deltaBase); if (or == null) { throw new MissingObjectException(_deltaBase, "delta base"); } return or; }
public override PackedObjectLoader GetBaseLoader(WindowCursor curs) { PackedObjectLoader or = PackFile.Get(curs, _deltaBase); if (or == null) { throw new MissingObjectException(_deltaBase, "delta base"); } return(or); }
public byte[] decompress(long position, long totalSize, WindowCursor curs) { var dstbuf = new byte[totalSize]; if (curs.Inflate(this, position, dstbuf, 0) != totalSize) { throw new EndOfStreamException("Short compressed stream at " + position); } return(dstbuf); }
private PackedObjectLoader Reader(WindowCursor curs, long objOffset) { long pos = objOffset; int p = 0; byte[] ib = curs.TempId; // Reader.ReadBytes(ObjectId.ObjectIdLength); ReadFully(pos, ib, 0, 20, curs); int c = ib[p++] & 0xff; int typeCode = (c >> 4) & 7; long dataSize = c & 15; int shift = 4; while ((c & 0x80) != 0) { c = ib[p++] & 0xff; dataSize += (c & 0x7f) << shift; shift += 7; } pos += p; switch (typeCode) { case Constants.OBJ_COMMIT: case Constants.OBJ_TREE: case Constants.OBJ_BLOB: case Constants.OBJ_TAG: return(new WholePackedObjectLoader(this, pos, objOffset, typeCode, (int)dataSize)); case Constants.OBJ_OFS_DELTA: ReadFully(pos, ib, 0, 20, curs); p = 0; c = ib[p++] & 0xff; long ofs = c & 127; while ((c & 128) != 0) { ofs += 1; c = ib[p++] & 0xff; ofs <<= 7; ofs += (c & 127); } return(new DeltaOfsPackedObjectLoader(this, pos + p, objOffset, (int)dataSize, objOffset - ofs)); case Constants.OBJ_REF_DELTA: ReadFully(pos, ib, 0, 20, curs); return(new DeltaRefPackedObjectLoader(this, pos + ib.Length, objOffset, (int)dataSize, ObjectId.FromRaw(ib))); default: throw new IOException("Unknown object type " + typeCode + "."); } }
/// <summary> /// /// </summary> /// <param name="id">SHA-1 of an object.</param> /// <returns> /// A <see cref="ObjectLoader"/> for accessing the data of the named /// object, or null if the object does not exist. /// </returns> public ObjectLoader OpenObject(AnyObjectId id) { var wc = new WindowCursor(); try { return(OpenObject(wc, id)); } finally { wc.Release(); } }
public override ObjectLoader openObject2(WindowCursor curs, string objectName, AnyObjectId objectId) { try { return(new UnpackedObjectLoader(fileFor(objectName), objectId)); } catch (FileNotFoundException) { return(null); } catch (DirectoryNotFoundException) { return(null); } }
public override void Materialize(WindowCursor curs) { if (curs == null) { throw new System.ArgumentNullException("curs"); } if (CachedBytes != null) { return; } if (Type != ObjCommit) { UnpackedObjectCache.Entry cache = PackFile.readCache(DataOffset); if (cache != null) { curs.Release(); Type = cache.type; Size = cache.data.Length; CachedBytes = cache.data; return; } } try { PackedObjectLoader baseLoader = GetBaseLoader(curs); baseLoader.Materialize(curs); CachedBytes = BinaryDelta.Apply(baseLoader.CachedBytes, PackFile.decompress(DataOffset, _deltaSize, curs)); curs.Release(); Type = baseLoader.Type; Size = CachedBytes.Length; if (Type != ObjCommit) { PackFile.saveCache(DataOffset, CachedBytes, Type); } } catch (IOException dfe) { throw new CorruptObjectException("object at " + DataOffset + " in " + PackFile.File.FullName + " has bad zlib stream", dfe); } }
public override void Materialize(WindowCursor curs) { if ( curs == null) { throw new System.ArgumentNullException("curs"); } if (CachedBytes != null) { return; } if (Type != ObjCommit) { UnpackedObjectCache.Entry cache = PackFile.readCache(DataOffset); if (cache != null) { curs.Release(); Type = cache.type; Size = cache.data.Length; CachedBytes = cache.data; return; } } try { PackedObjectLoader baseLoader = GetBaseLoader(curs); baseLoader.Materialize(curs); CachedBytes = BinaryDelta.Apply(baseLoader.CachedBytes, PackFile.decompress(DataOffset, _deltaSize, curs)); curs.Release(); Type = baseLoader.Type; Size = CachedBytes.Length; if (Type != ObjCommit) { PackFile.saveCache(DataOffset, CachedBytes, Type); } } catch (IOException dfe) { throw new CorruptObjectException("object at " + DataOffset + " in " + PackFile.File.FullName + " has bad zlib stream", dfe); } }
public PackWriter(Repository repo, ProgressMonitor imonitor, ProgressMonitor wmonitor) { _objectsLists = CreateObjectsLists(); _objectsMap = new ObjectIdSubclassMap <ObjectToPack>(); _edgeObjects = new ObjectIdSubclassMap <ObjectId>(); _buf = new byte[16384]; // 16 KB _windowCursor = new WindowCursor(); IgnoreMissingUninteresting = true; MaxDeltaDepth = DEFAULT_MAX_DELTA_DEPTH; DeltaBaseAsOffset = DEFAULT_DELTA_BASE_AS_OFFSET; ReuseObjects = DEFAULT_REUSE_OBJECTS; ReuseDeltas = DEFAULT_REUSE_DELTAS; _db = repo; _initMonitor = imonitor; _writeMonitor = wmonitor; _deflater = new Deflater(_db.Config.getCore().getCompression()); _outputVersion = repo.Config.getCore().getPackIndexVersion(); }
internal void CopyRawData <T>(PackedObjectLoader loader, T @out, byte[] buf, WindowCursor cursor) where T : Stream { long objectOffset = loader.ObjectOffset; long dataOffset = loader.DataOffset; var cnt = (int)(FindEndOffset(objectOffset) - dataOffset); if (LoadPackIndex().HasCRC32Support) { var crc = new Crc32(); var headerCnt = (int)(dataOffset - objectOffset); while (headerCnt > 0) { int toRead = Math.Min(headerCnt, buf.Length); ReadFully(objectOffset, buf, 0, toRead, cursor); crc.Update(buf, 0, toRead); headerCnt -= toRead; } var crcOut = new CheckedOutputStream(@out, crc); CopyToStream(dataOffset, buf, cnt, crcOut, cursor); long computed = crc.Value; ObjectId id = FindObjectForOffset(objectOffset); long expected = LoadPackIndex().FindCRC32(id); if (computed != expected) { throw new CorruptObjectException("object at " + dataOffset + " in " + File.FullName + " has bad zlib stream"); } } else { try { cursor.InflateVerify(this, dataOffset); } catch (Exception fe) // [henon] was DataFormatException { throw new CorruptObjectException("object at " + dataOffset + " in " + File.FullName + " has bad zlib stream", fe); } CopyToStream(dataOffset, buf, cnt, @out, cursor); } }
private ObjectLoader OpenObjectImpl2(WindowCursor curs, string objectName, AnyObjectId objectId) { ObjectLoader ldr = openObject2(curs, objectName, objectId); if (ldr != null) { return(ldr); } foreach (ObjectDatabase alt in getAlternates()) { ldr = alt.OpenObjectImpl2(curs, objectName, objectId); if (ldr != null) { return(ldr); } } return(null); }
/// <summary> /// Open an object from this database. /// <para /> /// Alternates (if present) are searched automatically. /// </summary> /// <param name="curs"> /// Temporary working space associated with the calling thread. /// </param> /// <param name="objectId">Identity of the object to open.</param> /// <returns> /// A <see cref="ObjectLoader"/> for accessing the data of the named /// object, or null if the object does not exist. /// </returns> public ObjectLoader openObject(WindowCursor curs, AnyObjectId objectId) { if (objectId == null) { return(null); } ObjectLoader ldr = OpenObjectImpl1(curs, objectId); if (ldr != null) { return(ldr); } ldr = OpenObjectImpl2(curs, objectId.Name, objectId); if (ldr != null) { return(ldr); } return(null); }
public override ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId) { PackList pList = _packList.get(); while (true) { SEARCH: foreach (PackFile p in pList.packs) { try { PackedObjectLoader ldr = p.Get(curs, objectId); if (ldr != null) { ldr.Materialize(curs); return(ldr); } } catch (PackMismatchException) { // Pack was modified; refresh the entire pack list. // pList = ScanPacks(pList); goto SEARCH; } catch (IOException) { // Assume the pack is corrupted. // RemovePack(p); } } return(null); } }
/// <summary> /// Slow half of <see cref="openObject(WindowCursor, AnyObjectId)"/>. /// </summary> /// <param name="curs"> /// temporary working space associated with the calling thread. /// </param> /// <param name="objectName">Name of the object to open.</param> /// <param name="objectId">identity of the object to open.</param> /// <returns> /// A <see cref="ObjectLoader"/> for accessing the data of the named /// object, or null if the object does not exist. /// </returns> public virtual ObjectLoader openObject2(WindowCursor curs, string objectName, AnyObjectId objectId) { // Assume the search took place during openObject1. return null; }
/// <summary> /// /// </summary> /// <param name="windowCursor"></param> /// <param name="offset"></param> /// <returns> /// The file object which locates this pack on disk. /// </returns> internal PackedObjectLoader ResolveBase(WindowCursor windowCursor, long offset) { return(Reader(windowCursor, offset)); }
/// <summary> /// Fast half of <see cref="openObject(WindowCursor, AnyObjectId)"/>. /// </summary> /// <param name="curs"> /// temporary working space associated with the calling thread. /// </param> /// <param name="objectId">identity of the object to open.</param> /// <returns> /// A <see cref="ObjectLoader"/> for accessing the data of the named /// object, or null if the object does not exist. /// </returns> public abstract ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId);
public override ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId) { PackList pList = _packList.get(); while (true) { SEARCH: foreach (PackFile p in pList.packs) { try { PackedObjectLoader ldr = p.Get(curs, objectId); if (ldr != null) { ldr.Materialize(curs); return ldr; } } catch (PackMismatchException) { // Pack was modified; refresh the entire pack list. // pList = ScanPacks(pList); goto SEARCH; } catch (IOException) { // Assume the pack is corrupted. // RemovePack(p); } } return null; } }
public override void OpenObjectInAllPacksImplementation(ICollection<PackedObjectLoader> @out, WindowCursor windowCursor, AnyObjectId objectId) { if (@out == null) throw new ArgumentNullException ("out"); PackList pList = _packList.get(); while (true) { SEARCH: foreach (PackFile p in pList.packs) { try { PackedObjectLoader ldr = p.Get(windowCursor, objectId); if (ldr != null) { @out.Add(ldr); } } catch (PackMismatchException) { // Pack was modified; refresh the entire pack list. // pList = ScanPacks(pList); goto SEARCH; } catch (IOException) { // Assume the pack is corrupted. // RemovePack(p); } } break; } }
public override void OpenObjectInAllPacksImplementation(ICollection <PackedObjectLoader> @out, WindowCursor windowCursor, AnyObjectId objectId) { _objectDatabase.OpenObjectInAllPacksImplementation(@out, windowCursor, objectId); }
/// <summary> /// /// </summary> /// <param name="windowCursor"> /// Temporary thread storage during data access. /// </param> /// <returns> /// The object loader for the base object /// </returns> public abstract PackedObjectLoader GetBaseLoader(WindowCursor windowCursor);
private ObjectLoader OpenObjectImpl1(WindowCursor curs, AnyObjectId objectId) { ObjectLoader ldr = openObject1(curs, objectId); if (ldr != null) { return ldr; } foreach (ObjectDatabase alt in getAlternates()) { ldr = alt.OpenObjectImpl1(curs, objectId); if (ldr != null) { return ldr; } } if (tryAgain1()) { ldr = openObject1(curs, objectId); if (ldr != null) { return ldr; } } return null; }
public override PackedObjectLoader GetBaseLoader(WindowCursor windowCursor) { return(PackFile.ResolveBase(windowCursor, _deltaBase)); }
/// <summary> /// Get an object from this pack. /// </summary> /// <param name="curs">temporary working space associated with the calling thread.</param> /// <param name="id">the object to obtain from the pack. Must not be null.</param> /// <returns> /// The object loader for the requested object if it is contained in /// this pack; null if the object was not found. /// </returns> public PackedObjectLoader Get(WindowCursor curs, AnyObjectId id) { long offset = LoadPackIndex().FindOffset(id); return(0 < offset?Reader(curs, offset) : null); }
/// <summary> /// Open the object from all packs containing it. /// <para /> /// If any alternates are present, their packs are also considered. /// </summary> /// <param name="out"> /// Result collection of loaders for this object, filled with /// loaders from all packs containing specified object /// </param> /// <param name="windowCursor"> /// Temporary working space associated with the calling thread. /// </param> /// <param name="objectId"><see cref="ObjectId"/> of object to search for.</param> public void OpenObjectInAllPacks(ICollection<PackedObjectLoader> @out, WindowCursor windowCursor, AnyObjectId objectId) { OpenObjectInAllPacksImplementation(@out, windowCursor, objectId); foreach (ObjectDatabase alt in getAlternates()) { alt.OpenObjectInAllPacksImplementation(@out, windowCursor, objectId); } }
/// <summary> /// Open object in all packs containing specified object. /// </summary> /// <param name="objectId"><see cref="ObjectId"/> of object to search for</param> /// <param name="resultLoaders"> /// Result collection of loaders for this object, filled with /// loaders from all packs containing specified object /// </param> /// <param name="windowCursor"> /// Temporary working space associated with the calling thread. /// </param> public void OpenObjectInAllPacks(AnyObjectId objectId, ICollection <PackedObjectLoader> resultLoaders, WindowCursor windowCursor) { _objectDatabase.OpenObjectInAllPacks(resultLoaders, windowCursor, objectId); }
public override void MaterializeNoStore(WindowCursor curs) { //Do nothing }
private void CopyToStream(long position, byte[] buffer, long count, Stream stream, WindowCursor windowCursor) { while (count > 0) { var toRead = (int)Math.Min(count, buffer.Length); ReadFully(position, buffer, 0, toRead, windowCursor); position += toRead; count -= toRead; stream.Write(buffer, 0, toRead); } }
public override ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId) { return _objectDatabase.openObject1(curs, objectId); }
/// <summary> /// Open the object from all packs containing it. /// <para /> /// If any alternates are present, their packs are also considered. /// </summary> /// <param name="out"> /// Result collection of loaders for this object, filled with /// loaders from all packs containing specified object. /// </param> /// <param name="windowCursor"> /// Temporary working space associated with the calling thread. /// </param> /// <param name="objectId"><see cref="ObjectId"/> of object to search for.</param> public virtual void OpenObjectInAllPacksImplementation(ICollection<PackedObjectLoader> @out, WindowCursor windowCursor, AnyObjectId objectId) { // Assume no pack support }
public override void OpenObjectInAllPacksImplementation(ICollection <PackedObjectLoader> @out, WindowCursor windowCursor, AnyObjectId objectId) { PackList pList = _packList.get(); while (true) { SEARCH: foreach (PackFile p in pList.packs) { try { PackedObjectLoader ldr = p.Get(windowCursor, objectId); if (ldr != null) { @out.Add(ldr); } } catch (PackMismatchException) { // Pack was modified; refresh the entire pack list. // pList = ScanPacks(pList); goto SEARCH; } catch (IOException) { // Assume the pack is corrupted. // RemovePack(p); } } break; } }
private ObjectLoader OpenObjectImpl2(WindowCursor curs, string objectName, AnyObjectId objectId) { ObjectLoader ldr = openObject2(curs, objectName, objectId); if (ldr != null) { return ldr; } foreach (ObjectDatabase alt in getAlternates()) { ldr = alt.OpenObjectImpl2(curs, objectName, objectId); if (ldr != null) { return ldr; } } return null; }
/// <summary> /// /// </summary> /// <param name="id">SHA-1 of an object.</param> /// <returns> /// A <see cref="ObjectLoader"/> for accessing the data of the named /// object, or null if the object does not exist. /// </returns> public ObjectLoader OpenObject(AnyObjectId id) { var wc = new WindowCursor(); try { return OpenObject(wc, id); } finally { wc.Release(); } }
public override ObjectLoader openObject2(WindowCursor curs, string objectName, AnyObjectId objectId) { return(_objectDatabase.openObject2(curs, objectName, objectId)); }
/// <summary> /// Open object in all packs containing specified object. /// </summary> /// <param name="objectId"><see cref="ObjectId"/> of object to search for</param> /// <param name="resultLoaders"> /// Result collection of loaders for this object, filled with /// loaders from all packs containing specified object /// </param> /// <param name="windowCursor"> /// Temporary working space associated with the calling thread. /// </param> public void OpenObjectInAllPacks(AnyObjectId objectId, ICollection<PackedObjectLoader> resultLoaders, WindowCursor windowCursor) { _objectDatabase.OpenObjectInAllPacks(resultLoaders, windowCursor, objectId); }
public override ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId) { return(_objectDatabase.openObject1(curs, objectId)); }
public abstract void MaterializeNoStore(WindowCursor curs);
public override void OpenObjectInAllPacksImplementation(ICollection<PackedObjectLoader> @out, WindowCursor windowCursor, AnyObjectId objectId) { _objectDatabase.OpenObjectInAllPacksImplementation(@out, windowCursor, objectId); }
public override void OpenObjectInAllPacks(ICollection<PackedObjectLoader> @out, WindowCursor curs, AnyObjectId objectId) { wrapped.OpenObjectInAllPacks(@out, curs, objectId); }
public override ObjectLoader openObject2(WindowCursor curs, string objectName, AnyObjectId objectId) { try { return new UnpackedObjectLoader(fileFor(objectName), objectId); } catch (FileNotFoundException) { return null; } catch (DirectoryNotFoundException) { return null; } }
/// <summary> /// Open an object from this database. /// <para /> /// Alternates (if present) are searched automatically. /// </summary> /// <param name="curs"> /// Temporary working space associated with the calling thread. /// </param> /// <param name="objectId">Identity of the object to open.</param> /// <returns> /// A <see cref="ObjectLoader"/> for accessing the data of the named /// object, or null if the object does not exist. /// </returns> public ObjectLoader openObject(WindowCursor curs, AnyObjectId objectId) { if (objectId == null) return null; ObjectLoader ldr = OpenObjectImpl1(curs, objectId); if (ldr != null) { return ldr; } ldr = OpenObjectImpl2(curs, objectId.Name, objectId); if (ldr != null) { return ldr; } return null; }
/// <summary> /// /// </summary> /// <param name="windowCursor"> /// Temporary working space associated with the calling thread. /// </param> /// <param name="id">SHA-1 of an object.</param> /// <returns> /// A <see cref="ObjectLoader"/> for accessing the data of the named /// object, or null if the object does not exist. /// </returns> public ObjectLoader OpenObject(WindowCursor windowCursor, AnyObjectId id) { return _objectDatabase.openObject(windowCursor, id); }
public override ObjectLoader openObject2(WindowCursor curs, string objectName, AnyObjectId objectId) { return _objectDatabase.openObject2(curs, objectName, objectId); }
/// <summary> /// Open object in all packs containing specified object. /// </summary> /// <param name="objectId">id of object to search for</param> /// <param name="windowCursor"> /// Temporary working space associated with the calling thread. /// </param> /// <returns> /// Collection of loaders for this object, from all packs containing /// this object /// </returns> public IEnumerable<PackedObjectLoader> OpenObjectInAllPacks(AnyObjectId objectId, WindowCursor windowCursor) { var result = new List<PackedObjectLoader>(); OpenObjectInAllPacks(objectId, result, windowCursor); return result; }
public override PackedObjectLoader GetBaseLoader(WindowCursor curs) { return PackFile.ResolveBase(curs, _deltaBase); }
/// <summary> /// Copy raw object representation from storage to provided output stream. /// <para /> /// Copied data doesn't include object header. User must provide temporary /// buffer used during copying by underlying I/O layer. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="out"> /// Output stream when data is copied. No buffering is guaranteed. /// </param> /// <param name="buf"> /// Temporary buffer used during copying. Recommended size is at /// least few kB. /// </param> /// <param name="curs">temporary thread storage during data access.</param> /// <exception cref="Exception"> /// When the object cannot be read. /// </exception> /// <seealso cref="beginCopyRawData"/> public void CopyRawData <T>(T @out, byte[] buf, WindowCursor curs) where T : Stream { _packFile.CopyRawData(this, @out, buf, curs); }
public override ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId) { return wrapped.openObject1(curs, objectId); }
public override ObjectLoader openObject2(WindowCursor curs, string objectName, AnyObjectId objectId) { return wrapped.openObject2(curs, objectName, objectId); }
public override ObjectLoader openObject2(WindowCursor curs, String objectName, AnyObjectId objectId) { if (_unpackedObjects.Get(objectId) == null) return null; return base.openObject2(curs, objectName, objectId); }
/// <summary> /// Release the window cursor. /// </summary> /// <param name="cursor">cursor to Release; may be null. /// </param> /// <returns>always null</returns> public static WindowCursor Release(WindowCursor cursor) { if (cursor != null) { cursor.Release(); } return null; }