Ejemplo n.º 1
0
        public virtual void TestCacheOpen()
        {
            RepositoryCache.FileKey loc = RepositoryCache.FileKey.Exact(db.Directory, db.FileSystem
                                                                        );
            Repository d2 = RepositoryCache.Open(loc);

            NUnit.Framework.Assert.AreNotSame(db, d2);
            NUnit.Framework.Assert.AreSame(d2, RepositoryCache.Open(RepositoryCache.FileKey.Exact
                                                                        (loc.GetFile(), db.FileSystem)));
            d2.Close();
            d2.Close();
        }
Ejemplo n.º 2
0
        public virtual void TestCacheRegisterOpen()
        {
            FilePath dir = db.Directory;

            RepositoryCache.Register(db);
            NUnit.Framework.Assert.AreSame(db, RepositoryCache.Open(RepositoryCache.FileKey.Exact
                                                                        (dir, db.FileSystem)));
            NUnit.Framework.Assert.AreEqual(".git", dir.GetName());
            FilePath parent = dir.GetParentFile();

            NUnit.Framework.Assert.AreSame(db, RepositoryCache.Open(RepositoryCache.FileKey.Lenient
                                                                        (parent, db.FileSystem)));
        }
Ejemplo n.º 3
0
		/// <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);
		}
Ejemplo n.º 4
0
		private RepositoryCache.Lock LockFor(RepositoryCache.Key location)
		{
			return openLocks[((int)(((uint)location.GetHashCode()) >> 1)) % openLocks.Length];
		}
Ejemplo n.º 5
0
		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();
			}
		}
Ejemplo n.º 6
0
		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();
			}
		}
Ejemplo n.º 7
0
		/// <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;
		}
Ejemplo n.º 8
0
		/// <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);
		}