Example #1
0
        private static string CreateInitCommit()
        {
            EnsureSystemFolderCreated();

            var tree     = new TreeNodeFolder("");
            var treeHash = SaveObjectToStorage(tree, TreesStorage);

            var hashes      = new Dictionary <string, string>();
            var hashAddress = SaveObjectToStorage(hashes, ModHashesStorage);

            var commitObject = new CommitModel()
            {
                Parents = null,
                Labels  = new Dictionary <string, string>()
                {
                    ["message"] = "init"
                },
                HashesAddress = hashAddress,
                TreeHash      = treeHash
            };

            return(SaveObjectToStorage(commitObject, CommitsStorage));
        }
Example #2
0
        private static async Task <IDictionary <string, string> > GetHashesForCommit(CommitModel commit)
        {
            var result = await ReadFromStorage <IDictionary <string, string> >(commit.HashesAddress, ModHashesStorage);

            var prevCommits = commit.Parents?.Select(h =>
                                                     ReadFromStorage <CommitModel>(h, CommitsStorage).GetAwaiter().GetResult()) ?? new List <CommitModel>();

            foreach (var prevCommit in prevCommits)
            {
                var prevState = await GetHashesForCommit(prevCommit);

                foreach (var prevRow in prevState)
                {
                    if (result.ContainsKey(prevRow.Key))
                    {
                        continue;
                    }

                    result.Add(prevRow);
                }
            }

            return(result);
        }
Example #3
0
        private static async Task <string> CreateCommit(string chash, Dictionary <string, string> labels)
        {
            var tree = await CreateTreeFiltered(Environment.CurrentDirectory);

            var treeHash = SaveObjectToStorage(tree, TreesStorage);

            var prevCommit = await ReadFromStorage <CommitModel>(chash, CommitsStorage);

            var hashes = await HashModifications(new[] { prevCommit.TreeHash, treeHash });

            var hashAddress = SaveObjectToStorage(hashes, ModHashesStorage);

            await SaveHashedBlobs(hashes);

            var commitObject = new CommitModel()
            {
                Parents       = new[] { chash },
                Labels        = labels,
                HashesAddress = hashAddress,
                TreeHash      = treeHash
            };

            return(SaveObjectToStorage(commitObject, CommitsStorage));
        }