コード例 #1
0
        /// <summary>
        /// Converts this object to a Commit object
        /// </summary>
        /// <param name="directory">The directory dependency for proxies</param>
        /// <param name="loader">The loader object which specifies which objects to load</param>
        /// <returns></returns>
        public Commit GetCommit(DirectoryStructure directory, CommitDependencyLoader loader)
        {
            Commit[] parents = new Commit[Parents.Length];
            for (int i = 0; i < parents.Length; i++)
            {
                string p = Parents[i];
                if (loader.LoadParents && loader.ShouldLoadParent(p))
                {
                    parents[i] = directory.GetCommit(p, loader.GetParent(p));
                }
                else
                {
                    parents[i] = new CommitProxy(p, directory);
                }
            }

            Changelog changelog = loader.LoadChangelog ?
                                  directory.GetChangelog(Changelog) :
                                  new ChangelogProxy(Changelog, directory);

            Version version = loader.LoadVersion ?
                              directory.GetVersion(Hash, loader.LoadVersionData) :
                              new VersionProxy(Version, directory);

            CommitMetadata metadata = Metadata != null?Metadata.GetMetadata()
                                          : throw new FormatException("Commit must contain metadata");

            return(new Commit(parents, changelog, version, metadata, Hash));
        }
コード例 #2
0
        public bool Test_CommitMetadata_Equals(string first, string second)
        {
            var firstMeta  = new CommitMetadata(first);
            var secondMeta = new CommitMetadata(second);

            return(firstMeta.Equals(secondMeta));
        }
コード例 #3
0
        public bool Test_CommitMetadata_GetHashCode(string first, string second)
        {
            var firstMeta  = new CommitMetadata(first);
            var secondMeta = new CommitMetadata(second);

            return(firstMeta.GetHashCode() == secondMeta.GetHashCode());
        }
コード例 #4
0
ファイル: ReparentFilter.cs プロジェクト: Xcelled/firebolt
        public async Task <bool> FilterParents(CommitMetadata commit, ParentFilterContext context)
        {
            if (newParents.ContainsKey(commit.Original?.Sha))
            {
                commit.Parents = (await Task.WhenAll(newParents[commit.Original?.Sha].Select(context.Map))).Flatten().ToList();
                return(true);
            }

            return(false);
        }
コード例 #5
0
        /// <summary>
        /// Converts this object to a Commit object
        /// </summary>
        /// <param name="directory">The directory dependency for proxies</param>
        /// <returns></returns>
        public Commit GetCommit(DirectoryStructure directory)
        {
            Commit[]  parents   = Parents.Select(p => new CommitProxy(p, directory)).ToArray();
            Changelog changelog = new ChangelogProxy(Changelog, directory);
            Version   version   = new VersionProxy(Version, directory);

            CommitMetadata metadata = Metadata != null?Metadata.GetMetadata()
                                          : throw new FormatException("Commit must contain metadata");

            return(new Commit(parents, changelog, version, metadata, Hash));
        }
コード例 #6
0
        public bool FilterCommit(CommitMetadata commit, FilterContext context)
        {
            var newTree = new TreeMetadata();

            foreach (var rel in relocations)
            {
                if (rel.Key == null)
                {
                    // Move whole tree under a subdir
                    throw new NotImplementedException();
                }
                else
                {
                    var subtree = commit.Tree[rel.Key];

                    if (subtree != null)
                    {
                        if (rel.Key == null)
                        {
                            // Move tree under the root
                            throw new NotImplementedException();
                        }
                        else
                        {
                            newTree.Add(rel.Value, subtree);
                        }
                    }
                }
            }

            if (newTree.IsEmpty)
            {
                return(false);
            }

            commit.Tree = newTree;
            return(true);
        }
コード例 #7
0
ファイル: CommitCommand.cs プロジェクト: Jeffjewett27/EChest
        public void Create(string message)
        {
            //Loads the files in the working directory
            Version working = directory.GetWorkingVersion();
            //Aggregates the files from all commits up to HEAD
            Head   head         = directory.GetHead();
            Commit parentCommit = head.GetTarget();
            AggregatedChangelog parentAggregate = parentCommit.AggregateChangelog();
            Version             parent          = directory.AggregateVersion(parentAggregate);
            //Creates the data fields for commit
            Changelog      diffChangelog = parent.GetChangelog(working);
            Version        diffVersion   = working.GetChangelogVersion(diffChangelog);
            CommitMetadata metadata      = new CommitMetadata(message);
            //Creates the commit
            Commit newCommit = new Commit(parentCommit, diffChangelog, diffVersion, metadata);

            //Adds the data fields to the file directory
            directory.CreateVersion(diffVersion);
            directory.CreateChangelog(diffChangelog);
            directory.CreateCommit(newCommit);
            //Update the position of the HEAD
            directory.UpdateHead(head, newCommit);
        }
コード例 #8
0
ファイル: PruneEmptyFilter.cs プロジェクト: Xcelled/firebolt
        public async Task <bool> FilterParents(CommitMetadata commit, ParentFilterContext context)
        {
            // Re-process merges to eliminate branches that don't contribute anything to the tree
            if (commit.Parents.Count > 1 && pruneMergesAggressive)
            {
                var treeSameTo = commit.Parents.Where(p => commit.Tree.Equals(p.Tree)).FirstOrDefault();

                if (treeSameTo != null)
                {
                    // eliminate the parents that are not treesame as they contribute nothing
                    commit.Parents = commit.Parents.Where(p => p.Tree.Equals(treeSameTo.Tree)).Distinct().ToList();

                    // If it's demoted from a merge, it's a pointless commit now
                    // as it's treesame to its only parent. So dump out early and drop it
                    if (commit.Parents.Count == 1)
                    {
                        return(false);
                    }
                }
            }

            if (commit.Parents.Count == 2 && pruneMerges)
            {
                // Heuristic to quickly eliminate the common case of a triangle
                var p1 = commit.Parents[0];
                var p2 = commit.Parents[1];

                if (p2.Parents.Contains(p1))
                {
                    // p1 is redundant as it's reachable from p2
                    commit.Parents.Remove(p1);
                }
                else if (p1.Parents.Contains(p2))
                {
                    // p2 is redundant since reachable from p1
                    commit.Parents.Remove(p2);
                }
            }

            if (commit.Parents.Count > 1 && pruneMerges)
            {
                var procInfo = new ProcessStartInfo("git", "show-branch --independent " + string.Join(" ", commit.Parents.Select(x => x.Sha)))
                {
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    UseShellExecute        = false
                };

                using (var proc = await RunProcessAsync(procInfo).ConfigureAwait(false))
                {
                    var newParentShas = proc.StandardOutput.ReadToEnd().Split(' ', '\r', '\n').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).Distinct().ToSet();

                    if (proc.ExitCode != 0)
                    {
                        throw new Exception("git show-branch failed! " + proc.StandardError.ReadToEnd());
                    }

                    commit.Parents = commit.Parents.Where(p => newParentShas.Contains(p.Sha)).ToList();
                }
            }

            if (commit.Parents.Count == 0)
            {
                return(!commit.Tree.IsEmpty); // Don't include null trees if we're a root
            }

            if (commit.Parents.Count == 1 && commit.Tree.Equals(commit.Parents[0].Tree))
            {
                return(false); // Skip unchanged
            }

            return(true);
        }
コード例 #9
0
 public CommitMetadataJSON(CommitMetadata metadata) : base(metadata)
 {
 }