public static GitObjectBase ReadGitObject(string repositoryPath, ObjectHash hash) { var gitObject = PackReader.GetObject(hash); if (gitObject != null) { return(gitObject); } var fileContent = HashContent.FromFile(repositoryPath, hash.ToString()); var contentIndex = fileContent.AsSpan(7).IndexOf <byte>(0) + 8; if (IsCommit(fileContent)) { return(new Commit(hash, fileContent.AsSpan(contentIndex).ToArray())); } if (IsTree(fileContent)) { return(new Tree(hash, fileContent.AsMemory(contentIndex))); } if (IsTag(fileContent)) { return(new Tag(hash, fileContent.AsMemory(contentIndex))); } // TODO blobs probably not working atm if (IsBlob(fileContent)) { return(new Blob(hash, fileContent.AsMemory(contentIndex))); } return(null); }
public static Tree ReadTree(string repositoryPath, ObjectHash hash) { var tree = PackReader.GetTree(hash); if (tree != null) { return(tree); } var fileContent = HashContent.FromFile(repositoryPath, hash.ToString()); if (IsTree(fileContent)) { return(new Tree(hash, fileContent.AsMemory(fileContent.AsSpan(5).IndexOf <byte>(0) + 6))); } return(null); }
public static Commit ReadCommit(string repositoryPath, ObjectHash hash) { var commit = PackReader.GetCommit(repositoryPath, hash); if (commit != null) { return(commit); } var fileContent = HashContent.FromFile(repositoryPath, hash.ToString()); if (IsCommit(fileContent)) { return(new Commit(hash, fileContent.AsMemory(fileContent.AsSpan(7).IndexOf <byte>(0) + 8).ToArray())); } throw new ArgumentException("Not a commit: " + hash); }