private RepositoryCommitModel ConvertToRepositoryCommitModel(Commit commit, bool withDiff = false)
 {
     var model = new RepositoryCommitModel
     {
         Author = commit.Author.Name,
         AuthorEmail = commit.Author.Email,
         Date = commit.Author.When.LocalDateTime,
         ID = commit.Sha,
         Message = commit.MessageShort,
         TreeID = commit.Tree.Sha,
         Parents = commit.Parents.Select(i => i.Sha).ToArray(),
     };
     if (withDiff)
     {
         TreeChanges changes = commit.Parents.Count() == 0
             ? _repository.Diff.Compare(null, commit.Tree)
             : _repository.Diff.Compare(commit.Parents.First().Tree, commit.Tree);
         model.Changes = changes.OrderBy(s => s.Path).Select(i => new RepositoryCommitChangeModel
         {
             //Name = i.Name,
             Path = i.Path.Replace('\\', '/'),
             Status = i.Status,
         });
     }
     return model;
 }
        private RepositoryCommitModel ToModel(Commit commit, bool withDiff = false)
        {
            var model = new RepositoryCommitModel
            {
                Author = commit.Author.Name,
                AuthorEmail = commit.Author.Email,
                Date = commit.Author.When.LocalDateTime,
                ID = commit.Sha,
                Message = commit.Message,
                TreeID = commit.Tree.Sha,
                Parents = commit.Parents.Select(i => i.Sha).ToArray(),
            };

            if (!withDiff)
            {
                return model;
            }

            TreeChanges changes = !commit.Parents.Any() ? _repository.Diff.Compare<TreeChanges>(null, commit.Tree) : _repository.Diff.Compare<TreeChanges>(commit.Parents.First().Tree, commit.Tree);
            Patch patches = !commit.Parents.Any() ? _repository.Diff.Compare<Patch>(null, commit.Tree) : _repository.Diff.Compare<Patch>(commit.Parents.First().Tree, commit.Tree);

            model.Changes = changes.OrderBy(s => s.Path).Select(i =>
            {
                var patch = patches[i.Path];
                return new RepositoryCommitChangeModel
                {
                    Path = i.Path.Replace('\\', '/'),
                    Status = i.Status,
                    LinesAdded = patch.LinesAdded,
                    LinesDeleted = patch.LinesDeleted,
                    Patch = patch.Patch,
                };
            });

            return model;
        }
        private RepositoryCommitModel ToModel(Commit commit, bool withDiff = false)
        {
            string tagsString = string.Empty;
            var tags = _repository.Tags.Where(o => o.Target.Sha == commit.Sha).Select(o => o.Name).ToList();

            var shortMessageDetails = RepositoryCommitModelHelpers.MakeCommitMessage(commit.Message, 50);

            IEnumerable<string> links = null;
            if (UserConfiguration.Current.HasLinks)
            {
                links = Regex.Matches(commit.Message, UserConfiguration.Current.LinksRegex).OfType<Match>().Select(m => m.Value);
            }
            

            var model = new RepositoryCommitModel
            {
                Author = commit.Author.Name,
                AuthorEmail = commit.Author.Email,
                AuthorAvatar = commit.Author.GetAvatar(),
                Date = commit.Author.When.LocalDateTime,
                ID = commit.Sha,
                Message = shortMessageDetails.ShortTitle,
                MessageShort = shortMessageDetails.ExtraTitle,
                TreeID = commit.Tree.Sha,
                Parents = commit.Parents.Select(i => i.Sha).ToArray(),
                Tags = tags,
                Notes = (from n in commit.Notes select new RepositoryCommitNoteModel(n.Message, n.Namespace)).ToList(),
                Links = links
            };

            if (!withDiff)
            {
                return model;
            }

            TreeChanges changes = !commit.Parents.Any() ? _repository.Diff.Compare<TreeChanges>(null, commit.Tree) : _repository.Diff.Compare<TreeChanges>(commit.Parents.First().Tree, commit.Tree);
            Patch patches = !commit.Parents.Any() ? _repository.Diff.Compare<Patch>(null, commit.Tree) : _repository.Diff.Compare<Patch>(commit.Parents.First().Tree, commit.Tree);

            model.Changes = changes.OrderBy(s => s.Path).Select(i =>
            {
                var patch = patches[i.Path];
                return new RepositoryCommitChangeModel
                {
                    ChangeId = i.Oid.Sha,
                    Path = i.Path.Replace('\\', '/'),
                    Status = i.Status,
                    LinesAdded = patch.LinesAdded,
                    LinesDeleted = patch.LinesDeleted,
                    Patch = patch.Patch,

                };
            });

            return model;
        }
        private RepositoryCommitModel ToModel(Commit commit, bool withDiff = false)
        {
            string tagsString = string.Empty;
            var tags = _repository.Tags.Where(o => o.Target.Sha == commit.Sha);

            if (tags != null && tags.Any())
                tagsString = tags.Select(o => o.Name).Aggregate((o, p) => o + " " + p);

            var shortMessageDetails = RepositoryCommitModelHelpers.MakeCommitMessage(commit.Message, 30);

            var model = new RepositoryCommitModel
            {
                Author = commit.Author.Name,
                AuthorEmail = commit.Author.Email,
                AuthorAvatar = commit.Author.GetAvatar(),
                Date = commit.Author.When.LocalDateTime,
                ID = commit.Sha,
                Message = shortMessageDetails.ShortTitle,
                MessageShort = shortMessageDetails.ExtraTitle,
                TreeID = commit.Tree.Sha,
                Parents = commit.Parents.Select(i => i.Sha).ToArray(),
                TagName = tagsString,
                Notes = (from n in commit.Notes select new RepositoryCommitNoteModel(n.Message, n.Namespace)).ToList(),
            };

            if (!withDiff)
            {
                return model;
            }

            TreeChanges changes = !commit.Parents.Any() ? _repository.Diff.Compare<TreeChanges>(null, commit.Tree) : _repository.Diff.Compare<TreeChanges>(commit.Parents.First().Tree, commit.Tree);
            Patch patches = !commit.Parents.Any() ? _repository.Diff.Compare<Patch>(null, commit.Tree) : _repository.Diff.Compare<Patch>(commit.Parents.First().Tree, commit.Tree);

            model.Changes = changes.OrderBy(s => s.Path).Select(i =>
            {
                var patch = patches[i.Path];
                return new RepositoryCommitChangeModel
                {
                    ChangeId = i.Oid.Sha,
                    Path = i.Path.Replace('\\', '/'),
                    Status = i.Status,
                    LinesAdded = patch.LinesAdded,
                    LinesDeleted = patch.LinesDeleted,
                    Patch = patch.Patch,

                };
            });

            return model;
        }