示例#1
0
        public GitRevision(string hash, string description, GitDiff diff, Author author, DateTime committerDate, ICollection <string> parentHashes)
        {
            this.Hash          = hash;
            this.Description   = description;
            this.Diff          = diff;
            this.Author        = author;
            this.CommitterDate = committerDate;

            this.ParentHashes = new List <string>(parentHashes);
        }
示例#2
0
        public List <GitRevision> GetAllRevisions()
        {
            // --topo-order - Show no parents before all of its children are shown.  The graphing algorithm assumes this is true.
            // --reflog - Pretend as if all objects mentioned by reflogs are listed on the command line as <commit>.
            // --all - Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as <commit>.
            // %H - commit hash
            // %P - parent hash
            // %s - commit subject
            // %ci - committer date: 2018-04-23 11:48:59 -0700
            // %an - author name
            string output = this.RunGitCommand("rev-list --all --reflog --topo-order --pretty=\"format:%H|**|%P|**|%ci|**|%an|**|%s\"");

            string[] outputLines = output.Split('\n');

            List <GitRevision> commits = new List <GitRevision>();

            foreach (string outputLine in outputLines)
            {
                if (outputLine.Length == 0)
                {
                    continue;
                }

                string[] outputLineParts = outputLine.Split(new string[] { "|**|" }, StringSplitOptions.None);
                string   hash            = outputLineParts[0];
                // Each commit has a "header" line that looks like "commit 1234567890..." followed by the actual formatted line.
                if (hash.StartsWith("commit"))
                {
                    continue;
                }

                string[] parentHashes;
                if (outputLineParts[1].Length > 0)
                {
                    parentHashes = outputLineParts[1].Split(' ');
                }
                else
                {
                    parentHashes = new string[0];
                }

                // We can cache the diff -- we know if the commit hash hasn't changed, the diff couldn't have either.
                string diffStr;
                if (diffCache.HasCachedDiff(hash))
                {
                    diffStr = diffCache.GetCachedDiff(hash);
                }
                else
                {
                    diffStr = GetContextlessDiff(hash);
                    diffCache.Add(hash, diffStr);
                }
                GitDiff  diff          = new GitDiff(diffStr);
                Author   author        = new Author(outputLineParts[3]);
                DateTime committerDate = DateTime.Parse(outputLineParts[2]);
                string   description   = outputLineParts[4];

                commits.Add(new GitRevision(hash, description, diff, author, committerDate, parentHashes));
            }
            return(commits);
        }