当前位置: 首页>>代码示例>>C#>>正文


C# Repository.GetRevisions方法代码示例

本文整理汇总了C#中LibGit2Sharp.Repository.GetRevisions方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.GetRevisions方法的具体用法?C# Repository.GetRevisions怎么用?C# Repository.GetRevisions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LibGit2Sharp.Repository的用法示例。


在下文中一共展示了Repository.GetRevisions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Get

        public async Task<object> Get(string id)
        {
            using (var ctx = new ReviewContext())
            {
                var review = await ctx.Reviews.FindAsync(id);
                if (review == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }

                List<Revision> revisions;
                var commits = new HashSet<Commit>();
                using (var repo = new Repository(GitReviewApplication.RepositoryPath))
                {
                    revisions = repo.GetRevisions(review.RefPrefix).ToList();
                    var mergeBases = new Dictionary<Revision, HashSet<Commit>>(revisions.Count);
                    var ignored = new Dictionary<Revision, HashSet<Commit>>(revisions.Count);

                    foreach (var rev in revisions)
                    {
                        var revReachable = new HashSet<Commit>();
                        var revMergeBases = new HashSet<Commit>();
                        var revIgnored = new HashSet<Commit>();

                        var sourceCommit = (Commit)rev.Source.Target;
                        var destinationCommit = (Commit)rev.Destination.Target;
                        GetMergeDetails(repo, sourceCommit, destinationCommit, out revReachable, out revMergeBases, out revIgnored);

                        ignored[rev] = revIgnored;
                        mergeBases[rev] = revMergeBases;
                        commits.UnionWith(revReachable);
                    }

                    return new
                    {
                        Review = new
                        {
                            Id = review.Id,
                            Revisions = revisions.Select(r => review.Id + ":" + r.Id)
                        },
                        Revisions = revisions.Select(r => new
                        {
                            Id = review.Id + ":" + r.Id,
                            Source = r.Source.TargetIdentifier,
                            Destination = r.Destination.TargetIdentifier,
                            MergeBases = mergeBases[r].Select(b => b.Sha).ToList(),
                            Ignored = ignored[r].Select(i => i.Sha).ToList(),
                        }).ToList(),
                        Commits = commits.Select(c => new
                        {
                            Id = c.Sha,
                            Author = c.Author.Email,
                            AuthoredAt = c.Author.When,
                            Committer = c.Committer.Email,
                            CommittedAt = c.Committer.When,
                            Message = c.Message,
                            Parents = c.Parents.Select(p => p.Sha).ToList(),
                        }).ToList(),
                    };
                }
            }
        }
开发者ID:otac0n,项目名称:GitReview,代码行数:62,代码来源:ReviewController.cs


注:本文中的LibGit2Sharp.Repository.GetRevisions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。