internal DeltaBaseCache GetDeltaBaseCache() { if (baseCache == null) { baseCache = new DeltaBaseCache(); } return baseCache; }
internal DeltaBaseCache GetDeltaBaseCache() { if (baseCache == null) { baseCache = new DeltaBaseCache(); } return(baseCache); }
/// <summary>Close the resources utilized by this repository</summary> public virtual void Close() { DeltaBaseCache.Purge(this); WindowCache.Purge(this); lock (this) { loadedIdx = null; reverseIdx = null; } }
/// <summary>Modify the configuration of the window cache.</summary> /// <remarks> /// Modify the configuration of the window cache. /// <p> /// The new configuration is applied immediately. If the new limits are /// smaller than what what is currently cached, older entries will be purged /// as soon as possible to allow the cache to meet the new limit. /// </remarks> /// <param name="cfg">the new window cache configuration.</param> /// <exception cref="System.ArgumentException"> /// the cache configuration contains one or more invalid /// settings, usually too low of a limit. /// </exception> public static void Reconfigure(WindowCacheConfig cfg) { NGit.Storage.File.WindowCache nc = new NGit.Storage.File.WindowCache(cfg); NGit.Storage.File.WindowCache oc = cache; if (oc != null) { oc.RemoveAll(); } cache = nc; streamFileThreshold = cfg.GetStreamFileThreshold(); DeltaBaseCache.Reconfigure(cfg); }
/// <summary>Release the current window cursor.</summary> /// <remarks>Release the current window cursor.</remarks> public override void Release() { window = null; baseCache = null; try { InflaterCache.Release(inf); } finally { inf = null; } }
/// <summary>Release the current window cursor.</summary> /// <remarks>Release the current window cursor.</remarks> public override void Release() { window = null; baseCache = null; try { InflaterCache.Release(inf); } finally { inf = null; } }
/// <exception cref="System.IO.IOException"></exception> internal virtual ObjectLoader Load(WindowCursor curs, long pos) { try { byte[] ib = curs.tempId; PackFile.Delta delta = null; byte[] data = null; int type = Constants.OBJ_BAD; bool cached = false; for (; ;) { ReadFully(pos, ib, 0, 20, curs); int c = ib[0] & unchecked ((int)(0xff)); int typeCode = (c >> 4) & 7; long sz = c & 15; int shift = 4; int p = 1; while ((c & unchecked ((int)(0x80))) != 0) { c = ib[p++] & unchecked ((int)(0xff)); sz += (c & unchecked ((int)(0x7f))) << shift; shift += 7; } switch (typeCode) { case Constants.OBJ_COMMIT: case Constants.OBJ_TREE: case Constants.OBJ_BLOB: case Constants.OBJ_TAG: { if (sz < curs.GetStreamFileThreshold()) { data = Decompress(pos + p, (int)sz, curs); } if (delta != null) { type = typeCode; goto SEARCH_break; } if (data != null) { return(new ObjectLoader.SmallObject(typeCode, data)); } else { return(new LargePackedWholeObject(typeCode, sz, pos, p, this, curs.db)); } goto case Constants.OBJ_OFS_DELTA; } case Constants.OBJ_OFS_DELTA: { c = ib[p++] & unchecked ((int)(0xff)); long @base = c & 127; while ((c & 128) != 0) { @base += 1; c = ib[p++] & unchecked ((int)(0xff)); @base <<= 7; @base += (c & 127); } @base = pos - @base; delta = new PackFile.Delta(delta, pos, (int)sz, p, @base); if (sz != delta.deltaSize) { goto SEARCH_break; } DeltaBaseCache.Entry e = DeltaBaseCache.Get(this, @base); if (e != null) { type = e.type; data = e.data; cached = true; goto SEARCH_break; } pos = @base; goto SEARCH_continue; } case Constants.OBJ_REF_DELTA: { ReadFully(pos + p, ib, 0, 20, curs); long @base = FindDeltaBase(ObjectId.FromRaw(ib)); delta = new PackFile.Delta(delta, pos, (int)sz, p + 20, @base); if (sz != delta.deltaSize) { goto SEARCH_break; } DeltaBaseCache.Entry e = DeltaBaseCache.Get(this, @base); if (e != null) { type = e.type; data = e.data; cached = true; goto SEARCH_break; } pos = @base; goto SEARCH_continue; } default: { throw new IOException(MessageFormat.Format(JGitText.Get().unknownObjectType, typeCode )); } } SEARCH_continue :; } SEARCH_break :; // At this point there is at least one delta to apply to data. // (Whole objects with no deltas to apply return early above.) if (data == null) { return(delta.Large(this, curs)); } do { // Cache only the base immediately before desired object. if (cached) { cached = false; } else { if (delta.next == null) { DeltaBaseCache.Store(this, delta.basePos, data, type); } } pos = delta.deltaPos; byte[] cmds = Decompress(pos + delta.hdrLen, delta.deltaSize, curs); if (cmds == null) { data = null; // Discard base in case of OutOfMemoryError return(delta.Large(this, curs)); } long sz = BinaryDelta.GetResultSize(cmds); if (int.MaxValue <= sz) { return(delta.Large(this, curs)); } byte[] result; try { result = new byte[(int)sz]; } catch (OutOfMemoryException) { data = null; // Discard base in case of OutOfMemoryError return(delta.Large(this, curs)); } BinaryDelta.Apply(data, cmds, result); data = result; delta = delta.next; }while (delta != null); return(new ObjectLoader.SmallObject(type, data)); } catch (SharpZipBaseException dfe) { CorruptObjectException coe = new CorruptObjectException(MessageFormat.Format(JGitText .Get().objectAtHasBadZlibStream, pos, GetPackFile())); Sharpen.Extensions.InitCause(coe, dfe); throw coe; } }
private static void ClearEntry(DeltaBaseCache.Slot e) { openByteCount -= e.sz; e.provider = null; e.data = DEAD; e.sz = 0; }
private static void Unlink(DeltaBaseCache.Slot e) { DeltaBaseCache.Slot prev = e.lruPrev; DeltaBaseCache.Slot next = e.lruNext; if (prev != null) { prev.lruNext = next; } if (next != null) { next.lruPrev = prev; } }
private static void MoveToHead(DeltaBaseCache.Slot e) { Unlink(e); e.lruPrev = null; e.lruNext = lruHead; if (lruHead != null) { lruHead.lruPrev = e; } else { lruTail = e; } lruHead = e; }