/// <summary> * The constructor from object identifier /// </summary> /// <param name="base">the base configuration file </param> /// <param name="r">the repository</param> /// <param name="objectid">the object identifier</param> /// <exception cref="IOException"> /// the blob cannot be read from the repository. </exception> /// <exception cref="ConfigInvalidException"> /// the blob is not a valid configuration format. /// </exception> public BlobBasedConfig(Config @base, Repository r, ObjectId objectid) : base(@base) { ObjectLoader loader = r.OpenBlob(objectid); if (loader == null) { throw new IOException("Blob not found: " + objectid); } fromText(RawParseUtils.decode(loader.Bytes)); }
private void EnsureLoaded() { if (IsLoaded) { return; } ObjectLoader or = _db.OpenTree(Id); if (or == null) { throw new MissingObjectException(Id, ObjectType.Tree); } ReadTree(or.Bytes); }
/// <summary> * The constructor from object identifier /// </summary> /// <param name="base">the base configuration file </param> /// <param name="repo">the repository</param> /// <param name="objectid">the object identifier</param> /// <exception cref="IOException"> /// the blob cannot be read from the repository. </exception> /// <exception cref="ConfigInvalidException"> /// the blob is not a valid configuration format. /// </exception> public BlobBasedConfig(Config @base, Repository repo, ObjectId objectid) : base(@base) { if (repo == null) { throw new System.ArgumentNullException("repo"); } ObjectLoader loader = repo.OpenBlob(objectid); if (loader == null) { throw new IOException("Blob not found: " + objectid); } fromText(RawParseUtils.decode(loader.Bytes)); }
/// <summary> /// Access a Commit by SHA'1 id. /// </summary> /// <param name="id"></param> /// <returns>Commit or null</returns> public Commit MapCommit(ObjectId id) { ObjectLoader or = OpenObject(id); if (or == null) { return(null); } byte[] raw = or.Bytes; if (Constants.OBJ_COMMIT == or.Type) { return(new Commit(this, id, raw)); } throw new IncorrectObjectTypeException(id, ObjectType.Commit); }
private void WriteWholeObjectDeflate(ObjectToPack otp) { ObjectLoader loader = _db.OpenObject(_windowCursor, otp); byte[] data = loader.CachedBytes; WriteObjectHeader(otp.Type, data.Length); _deflater.Reset(); _deflater.SetInput(data, 0, data.Length); _deflater.Finish(); do { int n = _deflater.Deflate(_buf, 0, _buf.Length); if (n > 0) { _pos.Write(_buf, 0, n); } } while (!_deflater.IsFinished); }
/// <summary> /// Access a Tag by SHA'1 id /// </summary> /// <param name="refName"></param> /// <param name="id"></param> /// <returns>Commit or null</returns> public Tag MapTag(string refName, ObjectId id) { ObjectLoader or = OpenObject(id); if (or == null) { return(null); } byte[] raw = or.Bytes; if (ObjectType.Tag == (ObjectType)or.Type) { return(new Tag(this, id, refName, raw)); } return(new Tag(this, id, refName, null)); }
private ObjectLoader OpenObjectImpl2(WindowCursor curs, string objectName, AnyObjectId objectId) { ObjectLoader ldr = openObject2(curs, objectName, objectId); if (ldr != null) { return(ldr); } foreach (ObjectDatabase alt in getAlternates()) { ldr = alt.OpenObjectImpl2(curs, objectName, objectId); if (ldr != null) { return(ldr); } } return(null); }
/// <summary> /// Access a Tree by SHA'1 id. /// </summary> /// <param name="id"></param> /// <returns>Tree or null</returns> public Tree MapTree(ObjectId id) { ObjectLoader or = OpenObject(id); if (or == null) { return(null); } byte[] raw = or.Bytes; switch (((ObjectType)or.Type)) { case ObjectType.Tree: return(new Tree(this, id, raw)); case ObjectType.Commit: return(MapTree(ObjectId.FromString(raw, 5))); } throw new IncorrectObjectTypeException(id, ObjectType.Tree); }
/// <summary> /// Open an object from this database. /// <para /> /// Alternates (if present) are searched automatically. /// </summary> /// <param name="curs"> /// Temporary working space associated with the calling thread. /// </param> /// <param name="objectId">Identity of the object to open.</param> /// <returns> /// A <see cref="ObjectLoader"/> for accessing the data of the named /// object, or null if the object does not exist. /// </returns> public ObjectLoader openObject(WindowCursor curs, AnyObjectId objectId) { if (objectId == null) { return(null); } ObjectLoader ldr = OpenObjectImpl1(curs, objectId); if (ldr != null) { return(ldr); } ldr = OpenObjectImpl2(curs, objectId.Name, objectId); if (ldr != null) { return(ldr); } return(null); }
/// <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) { 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)); }
/// <summary> /// Check out content of the specified index entry /// </summary> /// <param name="workDir">workdir</param> /// <param name="e">index entry</param> /// <exception cref="IOException"></exception> public void checkoutEntry(FileSystemInfo workDir, Entry e) { ObjectLoader ol = Repository.OpenBlob(e.ObjectId); byte[] bytes = ol.Bytes; var file = new FileInfo(Path.Combine(workDir.DirectoryName(), e.Name)); if (file.Exists) { file.Delete(); } file.Directory.Mkdirs(); using (var fs = new FileStream(file.FullName, System.IO.FileMode.CreateNew)) { var ms = new MemoryStream(bytes); ms.WriteTo(fs); } if (ConfigFilemode(Repository) && FileHasExecute()) { if (FileMode.ExecutableFile.Equals(e.Mode)) { if (!FileCanExecute(file)) { FileSetExecute(file, true); } } else if (FileCanExecute(file)) { FileSetExecute(file, false); } } e.Mtime = file.lastModified() * 1000000L; e.Ctime = e.Mtime; }