private void UnregisterRepository(RepositoryCache.Key location) { Reference <Repository> oldRef = Sharpen.Collections.Remove(cacheMap, location); Repository oldDb = oldRef != null?oldRef.Get() : null; if (oldDb != null) { oldDb.Close(); } }
private void RegisterRepository(RepositoryCache.Key location, Repository db) { db.IncrementOpen(); SoftReference <Repository> newRef = new SoftReference <Repository>(db); Reference <Repository> oldRef = cacheMap.Put(location, newRef); Repository oldDb = oldRef != null?oldRef.Get() : null; if (oldDb != null) { oldDb.Close(); } }
/// <exception cref="System.IO.IOException"></exception> private Repository OpenRepository(RepositoryCache.Key location, bool mustExist) { Reference <Repository> @ref = cacheMap.Get(location); Repository db = @ref != null? @ref.Get() : null; if (db == null) { lock (LockFor(location)) { @ref = cacheMap.Get(location); db = @ref != null? @ref.Get() : null; if (db == null) { db = location.Open(mustExist); @ref = new SoftReference <Repository>(db); cacheMap.Put(location, @ref); } } } db.IncrementOpen(); return(db); }
/// <summary>Open an existing repository, reusing a cached instance if possible.</summary> /// <remarks> /// Open an existing repository, reusing a cached instance if possible. /// <p> /// When done with the repository, the caller must call /// <see cref="Repository.Close()">Repository.Close()</see> /// to decrement the repository's usage counter. /// </remarks> /// <param name="location"> /// where the local repository is. Typically a /// <see cref="FileKey">FileKey</see> /// . /// </param> /// <returns>the repository instance requested; caller must close when done.</returns> /// <exception cref="System.IO.IOException"> /// the repository could not be read (likely its core.version /// property is not supported). /// </exception> /// <exception cref="NGit.Errors.RepositoryNotFoundException">there is no repository at the given location. /// </exception> public static Repository Open(RepositoryCache.Key location) { return(Open(location, true)); }
private RepositoryCache.Lock LockFor(RepositoryCache.Key location) { return(openLocks[((int)(((uint)location.GetHashCode()) >> 1)) % openLocks.Length]); }
/// <summary>Open a repository, reusing a cached instance if possible.</summary> /// <remarks> /// Open a repository, reusing a cached instance if possible. /// <p> /// When done with the repository, the caller must call /// <see cref="Repository.Close()">Repository.Close()</see> /// to decrement the repository's usage counter. /// </remarks> /// <param name="location"> /// where the local repository is. Typically a /// <see cref="FileKey">FileKey</see> /// . /// </param> /// <param name="mustExist"> /// If true, and the repository is not found, throws /// <code>RepositoryNotFoundException</code> /// . If false, a repository instance /// is created and registered anyway. /// </param> /// <returns>the repository instance requested; caller must close when done.</returns> /// <exception cref="System.IO.IOException"> /// the repository could not be read (likely its core.version /// property is not supported). /// </exception> /// <exception cref="NGit.Errors.RepositoryNotFoundException"> /// There is no repository at the given location, only thrown if /// <code>mustExist</code> /// is true. /// </exception> public static Repository Open(RepositoryCache.Key location, bool mustExist) { return(cache.OpenRepository(location, mustExist)); }