Ejemplo n.º 1
0
        /// <exception cref="System.IO.IOException"></exception>
        private FileObjectDatabase.AlternateHandle OpenAlternate(FilePath objdir)
        {
            FilePath parent = objdir.GetParentFile();

            if (RepositoryCache.FileKey.IsGitRepository(parent, fs))
            {
                RepositoryCache.FileKey key = RepositoryCache.FileKey.Exact(parent, fs);
                FileRepository          db  = (FileRepository)RepositoryCache.Open(key);
                return(new FileObjectDatabase.AlternateRepository(db));
            }
            NGit.Storage.File.ObjectDirectory db_1 = new NGit.Storage.File.ObjectDirectory(config
                                                                                           , objdir, null, fs);
            return(new FileObjectDatabase.AlternateHandle(db_1));
        }
Ejemplo n.º 2
0
        /// <exception cref="NGit.Errors.RepositoryNotFoundException"></exception>
        /// <exception cref="NGit.Transport.Resolver.ServiceNotEnabledException"></exception>
        public override Repository Open(C req, string name)
        {
            if (IsUnreasonableName(name))
            {
                throw new RepositoryNotFoundException(name);
            }
            Repository db = exports.Get(NameWithDotGit(name));

            if (db != null)
            {
                db.IncrementOpen();
                return(db);
            }
            foreach (FilePath @base in exportBase)
            {
                FilePath dir = RepositoryCache.FileKey.Resolve(new FilePath(@base, name), FS.DETECTED
                                                               );
                if (dir == null)
                {
                    continue;
                }
                try
                {
                    RepositoryCache.FileKey key = RepositoryCache.FileKey.Exact(dir, FS.DETECTED);
                    db = RepositoryCache.Open(key, true);
                }
                catch (IOException e)
                {
                    throw new RepositoryNotFoundException(name, e);
                }
                try
                {
                    if (IsExportOk(req, name, db))
                    {
                        // We have to leak the open count to the caller, they
                        // are responsible for closing the repository if we
                        // complete successfully.
                        return(db);
                    }
                    else
                    {
                        throw new ServiceNotEnabledException();
                    }
                }
                catch (RuntimeException e)
                {
                    db.Close();
                    throw new RepositoryNotFoundException(name, e);
                }
                catch (IOException e)
                {
                    db.Close();
                    throw new RepositoryNotFoundException(name, e);
                }
                catch (ServiceNotEnabledException e)
                {
                    db.Close();
                    throw;
                }
            }
            if (exportBase.Count == 1)
            {
                FilePath dir = new FilePath(exportBase.Iterator().Next(), name);
                throw new RepositoryNotFoundException(name, new RepositoryNotFoundException(dir));
            }
            throw new RepositoryNotFoundException(name);
        }