public void CreateTreeObject(CallDirectory callDirectory) { string content = String.Empty; foreach (Tree subtree in Subtrees) { //tree <hash> <folderName> subtree.CreateTreeObject(callDirectory); content += CreateTreeDataUnit(subtree); } foreach (Blob blob in Blobs) { //blob <hash> <fileName> content += CreateTreeDataUnit(blob); } Hash hash = new Hash(content); Hash = hash.GetContent(); Path objectPath = callDirectory.GetRepositoryFolder(); objectPath = objectPath.ConcatPath("objects"); objectPath = objectPath.ConcatPath(Hash); using (StreamWriter streamWriter = new StreamWriter(objectPath.ToString())) { streamWriter.Write(content); } }
private List <Path> ExtractFiles(Path path) { List <Path> filesPaths = new List <Path>(); string currentDirectory = path.ToString(); string[] files = Directory.GetFiles(currentDirectory); foreach (string filePath in files) { filesPaths.Add(new Path(filePath)); } string[] directories = Directory.GetDirectories(currentDirectory); Path repositoryPath = _callDirectory.GetRepositoryFolder(); foreach (string directory in directories) { if (directory == repositoryPath.ToString()) { continue; // skip .repo directory } Path subdirectory = new Path(directory); filesPaths.AddRange(ExtractFiles(subdirectory)); } return(filesPaths); }
public void CreateBlobObject(CallDirectory callDirectory) { string objectPath = callDirectory.GetRepositoryFolder().ToString() + $"\\objects\\{Hash}"; using (StreamWriter streamWriter = new StreamWriter(objectPath)) { StreamReader contentReader = File.OpenText(FilePath.ToString()); streamWriter.Write(contentReader.ReadToEnd()); } }
public Path GetShortPath(CallDirectory callDirectory) { Path unnecessaryPath = callDirectory.GetRepositoryFolder(); unnecessaryPath = unnecessaryPath.GetUpperDirectory(2); // pass .repo and initialized directory string shortPath = _path.Replace(unnecessaryPath.ToString() + "\\", ""); return(new Path(shortPath)); }
public void WriteToIndex(CallDirectory callDirectory) { string indexPath = callDirectory.GetRepositoryFolder().ToString() + "\\index"; using (StreamWriter streamWriter = new StreamWriter(indexPath)) { foreach (Blob tracked in Tracked) { streamWriter.WriteLine($"{tracked.Hash} {tracked.FilePath}"); } } }
public Hash CreateCommitObject(CallDirectory callDirectory) { string content = ParseContent(); Hash hash = new Hash(content); Path commitPath = callDirectory.GetRepositoryFolder().ConcatPath("commits"); commitPath = commitPath.ConcatPath(hash.GetContent()); using (StreamWriter streamWriter = new StreamWriter(commitPath.ToString())) { streamWriter.Write(content); } return(hash); }
private List <Blob> ReadIndex() { List <Blob> blobsInfo = new List <Blob>(); Path repositoryPath = _callDirectory.GetRepositoryFolder(); string indexPath = repositoryPath.ToString() + "\\index"; string[] lines = File.ReadAllLines(indexPath); foreach (string line in lines) { if (line == String.Empty) { break; } blobsInfo.Add(ParseBlobInfo(line)); } return(blobsInfo); }