Traditional file system based ObjectDatabase. This is the classical object database representation for a Git repository, where objects are stored loose by hashing them into directories by their ObjectId, or are stored in compressed containers known as PackFiles.
Inheritance: ObjectDatabase
Exemplo n.º 1
0
        /// <summary>
        /// The constructor
        /// </summary>
        /// <param name="wrapped">the wrapped database</param>
        public CachedObjectDirectory(ObjectDirectory wrapped) : base(wrapped)
        {
            DirectoryInfo objects = wrapped.getDirectory();

            string[] fanout = objects.GetDirectories().Select(x => x.FullName).ToArray();
            if (fanout == null)
            {
                fanout = new string[0];
            }
            foreach (string d in fanout)
            {
                if (d.Length != 2)
                {
                    continue;
                }
                string[] entries = PathUtil.CombineDirectoryPath(objects, d).GetFiles().Select(x => x.FullName).ToArray();
                if (entries == null)
                {
                    continue;
                }
                foreach (string e in entries)
                {
                    if (e.Length != Constants.OBJECT_ID_STRING_LENGTH - 2)
                    {
                        continue;
                    }
                    try {
                        _unpackedObjects.Add(ObjectId.FromString(d + e));
                    } catch (ArgumentException) {
                        // ignoring the file that does not represent loose object
                    }
                }
            }
        }
Exemplo n.º 2
0
        static private List <RepositoryListener> allListeners = new List <RepositoryListener>(); //TODO: make thread safe

        /**
         * Construct a representation of a Git repository.
         *
         * @param d
         *            GIT_DIR (the location of the repository metadata).
         * @throws IOException
         *             the repository appears to already exist but cannot be
         *             accessed.
         */
        public Repository(DirectoryInfo gitDirectory)
        {
            Directory       = gitDirectory;
            _refDb          = new RefDatabase(this);
            _objectDatabase = new ObjectDirectory(new DirectoryInfo(FS.resolve(gitDirectory, "objects").FullName));

            var userConfig = SystemReader.getInstance().openUserConfig();

            try
            {
                userConfig.load();
            }
            catch (ConfigInvalidException e1)
            {
                Dispose();

                throw new IOException("User config file "
                                      + userConfig.getFile().FullName + " invalid: "
                                      + e1, e1);
            }

            Config = new RepositoryConfig(userConfig, (FileInfo)FS.resolve(gitDirectory, "config"));

            WorkingDirectory = gitDirectory.Parent;

            if (_objectDatabase.exists())
            {
                try
                {
                    Config.load();
                }
                catch (ConfigInvalidException e1)
                {
                    Dispose();
                    throw new IOException("Unknown repository format", e1);
                }

                string repositoryFormatVersion = Config.getString("core", null, "repositoryFormatVersion");

                if (!"0".Equals(repositoryFormatVersion))
                {
                    Dispose();
                    throw new IOException("Unknown repository format \""
                                          + repositoryFormatVersion + "\"; expected \"0\".");
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// The constructor
 /// </summary>
 /// <param name="wrapped">the wrapped database</param>
 public CachedObjectDirectory(ObjectDirectory wrapped) : base(wrapped) {
     DirectoryInfo objects = wrapped.getDirectory();
     string[] fanout = objects.GetDirectories().Select(x => x.FullName).ToArray();
     if (fanout == null)
         fanout = new string[0];
     foreach (string d in fanout) {
         if (d.Length != 2)
             continue;
         string[] entries = PathUtil.CombineDirectoryPath(objects, d).GetFiles().Select(x => x.FullName).ToArray();
         if (entries == null)
             continue;
         foreach (string e in entries) {
             if (e.Length != Constants.OBJECT_ID_STRING_LENGTH - 2)
                 continue;
             try {
                 _unpackedObjects.Add(ObjectId.FromString(d + e));
             } catch (ArgumentException) {
                 // ignoring the file that does not represent loose object
             }
         }
     }
 }
Exemplo n.º 4
0
        /**
         * Construct a representation of a Git repository.
         *
         * @param d
         *            GIT_DIR (the location of the repository metadata).
         * @throws IOException
         *             the repository appears to already exist but cannot be
         *             accessed.
         */
        public Repository(DirectoryInfo gitDirectory)
        {
            Directory = gitDirectory;
            _refDb = new RefDatabase(this);
            _objectDatabase = new ObjectDirectory(new DirectoryInfo(FS.resolve(gitDirectory, "objects").FullName));

            var userConfig = SystemReader.getInstance().openUserConfig();

            try
            {
                userConfig.load();
            }
            catch (ConfigInvalidException e1)
            {
                throw new IOException("User config file "
                    + userConfig.getFile().FullName + " invalid: "
                    + e1, e1);
            }

            Config = new RepositoryConfig(userConfig, (FileInfo)FS.resolve(gitDirectory, "config"));

            WorkingDirectory = gitDirectory.Parent;

            if (_objectDatabase.exists())
            {
                try
                {
                    Config.load();
                }
                catch (ConfigInvalidException e1)
                {
                    throw new IOException("Unknown repository format", e1);
                }

                string repositoryFormatVersion = Config.getString("core", null, "repositoryFormatVersion");

                if (!"0".Equals(repositoryFormatVersion))
                {
                    throw new IOException("Unknown repository format \""
                                          + repositoryFormatVersion + "\"; expected \"0\".");
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Construct a representation of a Git repository using the given parameters possibly overriding default conventions..
        /// </summary>
        /// <param name="d">GIT_DIR (the location of the repository metadata). May be null for default value in which case it depends on GIT_WORK_TREE.</param>
        /// <param name="workTree">GIT_WORK_TREE (the root of the checkout). May be null for default value if GIT_DIR is</param>
        /// <param name="objectDir">GIT_OBJECT_DIRECTORY (where objects and are stored). May be null for default value. Relative names ares resolved against GIT_WORK_TREE</param>
        /// <param name="alternateObjectDir">GIT_ALTERNATE_OBJECT_DIRECTORIES (where more objects are read from). May be null for default value. Relative names ares resolved against GIT_WORK_TREE</param>
        /// <param name="indexFile">GIT_INDEX_FILE (the location of the index file). May be null for default value. Relative names ares resolved against GIT_WORK_TREE.</param>
        public Repository(DirectoryInfo d, DirectoryInfo workTree, DirectoryInfo objectDir,
                DirectoryInfo[] alternateObjectDir, FileInfo indexFile)
        {
            if (workTree != null)
            {
                workDir = workTree;
                if (d == null)
                    Directory = PathUtil.CombineDirectoryPath(workTree, Constants.DOT_GIT);
                else
                    Directory = d;
            }
            else
            {
                if (d != null)
                    Directory = d;
                else
                {
                    Dispose();
                    throw new ArgumentException("Either GIT_DIR or GIT_WORK_TREE must be passed to Repository constructor");
                }
            }

            var userConfig = SystemReader.getInstance().openUserConfig();

            try
            {
                userConfig.load();
            }
            catch (ConfigInvalidException e1)
            {
                Dispose();

                throw new IOException("User config file "
                    + userConfig.getFile().FullName + " invalid: "
                    + e1, e1);
            }

            Config = new RepositoryConfig(userConfig, (FileInfo)FS.resolve(Directory, "config"));

            try
            {
                Config.load();
            }
            catch (ConfigInvalidException e1)
            {
                Dispose();
                throw new IOException("Unknown repository format", e1);
            }

            if (workDir == null)
            {
                String workTreeConfig = Config.getString("core", null, "worktree");
                if (workTreeConfig != null)
                {
                    workDir = (DirectoryInfo)FS.resolve(d, workTreeConfig);
                }
                else
                {
                    workDir = Directory.Parent;
                }
            }

            _refDb = new RefDirectory(this);
            if (objectDir != null)
                _objectDatabase = new ObjectDirectory(PathUtil.CombineDirectoryPath(objectDir, ""),
                        alternateObjectDir);
            else
                _objectDatabase = new ObjectDirectory(PathUtil.CombineDirectoryPath(Directory, "objects"),
                        alternateObjectDir);

            if (indexFile != null)
                this.indexFile = indexFile;
            else
                this.indexFile = PathUtil.CombineFilePath(Directory, "index");

            if (_objectDatabase.exists())
            {
                string repositoryFormatVersion = Config.getString("core", null, "repositoryFormatVersion");

                if (!"0".Equals(repositoryFormatVersion))
                {
                    Dispose();
                    throw new IOException("Unknown repository format \""
                                          + repositoryFormatVersion + "\"; expected \"0\".");
                }
            }
        }