/// <summary> /// This method should be called after all the contents of tree is added ie. /// after every Blob was added via AddBlobToTreeHierarchy method call. /// </summary> /// <returns></returns> public HashKey GetChecksum() { if (_treeBuilderFileContent == null) { _treeBuilderFileContent = CreateTreeBuilderFileContent(); } return(ContentHasher.HashContent(_treeBuilderFileContent)); }
/// <param name="parentKey"> null if this is the initial commit </param> /// <param name="treeKey"></param> /// <param name="message"></param> public Commit(HashKey parentKey, HashKey treeKey, string message) { ParentKey = parentKey; TreeKey = treeKey; Message = message; _commitFileContent = CreateCommitFileContent(); _checksum = ContentHasher.HashContent(_commitFileContent); }
public Blob(RelativePath filePath) { FilePath = filePath.GetRelativeToGitRoot(); FileName = filePath.GetFileName(); using (StreamReader reader = new StreamReader(filePath.GetAbsolutePath())) { FileContent = reader.ReadToEnd(); } _blobContent = CreateBlobFileContent(); _checksum = ContentHasher.HashContent(_blobContent); }
/// <summary> /// This method is used for retrieving a blob object from <see cref="ObjectDatabase"/>. /// </summary> /// <param name="content"></param> /// <returns></returns> public static Blob ParseFromString(string content) { StringReader reader = new StringReader(content); string filePath = ParseFirstLine(reader.ReadLine()); if (filePath == null) { return(null); } Blob blob = new Blob(); blob.FilePath = filePath; blob.FileName = GetFileNameFromFilePath(filePath); blob.FileContent = reader.ReadToEnd(); blob._blobContent = blob.CreateBlobFileContent(); blob._checksum = ContentHasher.HashContent(blob._blobContent); return(blob); }
/// <summary> /// Parses tree from given string. Suppose that string represents content /// of a file. /// </summary> /// <param name="content"></param> /// <returns> null if parsing fails </returns> public static Tree ParseFromString(string content) { StringReader reader = new StringReader(content); string dirName = ParseFirstLine(reader.ReadLine()); if (dirName == null) { return(null); } Dictionary <string, HashKey> blobs = new Dictionary <string, HashKey>(); Dictionary <string, HashKey> subTrees = new Dictionary <string, HashKey>(); string line = reader.ReadLine(); while (line != null) { string[] lineItems = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (IsTreeEntry(lineItems)) { string subTreeDirName = lineItems[2]; HashKey subTreeKey = HashKey.ParseFromString(lineItems[1]); subTrees.Add(subTreeDirName, subTreeKey); } else if (IsBlobEntry(lineItems)) { string blobFileName = lineItems[2]; HashKey blobKey = HashKey.ParseFromString(lineItems[1]); blobs.Add(blobFileName, blobKey); } else { return(null); } line = reader.ReadLine(); } return(new Tree(ContentHasher.HashContent(content), dirName, blobs, subTrees)); }