Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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());
            }
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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}");
                }
            }
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }