Пример #1
0
        ///	<summary>
        /// The constructor from commit and path
        ///	</summary>
        ///	<param name="base">The base configuration file</param>
        ///	<param name="commit">The commit that contains the object</param>
        ///	<param name="path">The path within the tree of the commit</param>
        /// <exception cref="FileNotFoundException">
        /// the path does not exist in the commit's tree.
        /// </exception>
        /// <exception cref="IOException">
        /// the tree and/or blob cannot be accessed.
        /// </exception>
        /// <exception cref="ConfigInvalidException">
        /// the blob is not a valid configuration format.
        /// </exception>
        public BlobBasedConfig(Config @base, Commit commit, string path)
            : base(@base)
        {
            if (commit == null)
            {
                throw new System.ArgumentNullException("commit");
            }

            ObjectId   treeId = commit.TreeId;
            Repository r      = commit.Repository;

            TreeWalk.TreeWalk tree = TreeWalk.TreeWalk.ForPath(r, path, treeId);
            if (tree == null)
            {
                throw new FileNotFoundException("Entry not found by path: " + path);
            }
            ObjectId     blobId = tree.getObjectId(0);
            ObjectLoader loader = tree.Repository.OpenBlob(blobId);

            if (loader == null)
            {
                throw new IOException("Blob not found: " + blobId + " for path: " + path);
            }

            fromText(RawParseUtils.decode(loader.Bytes));
        }