コード例 #1
0
        /// <summary>
        /// Builds a compacted diff from this instance. Compacted diff has multiple subsequent untouched lines
        /// squashed into a single ellipsis line.
        /// </summary>
        /// <returns></returns>
        public UnifiedDiffViewModel GetCompactedDiff()
        {
            var model = new UnifiedDiffViewModel();
            // number of unchanged lines around the change that should be kept.
            const int unchangedWrappingLines = 3;
            var lastLineAdded = -1;
            var lines = new List<Line>();
            // number of lines left to append when the changed section is left.
            var postChangeWrapperLinesLeft = 0;
            for (int i = 0; i < Lines.Count; i++)
            {
                // change found
                var currentLine = Lines[i];
                if (currentLine.LineType != Diff.EditType.Unchanged)
                {
                    // previous line was unchanged - adding wrapper
                    if (i > 0 && Lines[i - 1].LineType == Diff.EditType.Unchanged)
                    {
                        // taking unchangedWrappingLines before first changed line
                        var firstWrappingLine = Math.Max(0, i - unchangedWrappingLines);
                        // making sure we don't grab a line we already added
                        firstWrappingLine = Math.Max(lastLineAdded + 1, firstWrappingLine);
                        for (int wrapperIndex = firstWrappingLine; wrapperIndex < i; wrapperIndex++)
                        {
                            lines.Add(Lines[wrapperIndex]);
                        }
                    }
                    lines.Add(currentLine);
                    lastLineAdded = i;
                    // how many unchanged lines we want to append after we append all changed lines.
                    postChangeWrapperLinesLeft = unchangedWrappingLines;
                }
                else
                {
                    if (postChangeWrapperLinesLeft > 0)
                    {
                        lines.Add(currentLine);
                        postChangeWrapperLinesLeft -= 1;
                        lastLineAdded = i;
                    }
                }
            }

            model.Lines.AddRange(lines);
            return model;
        }
コード例 #2
0
        public ChangeViewModel(RepositoryNavigationRequest request, Change change, Diff diff)
            : base(request)
        {
            Change = change;
            Treeish = change.ComparedCommit.Hash;
            Name = System.IO.Path.GetFileName(change.Path);
            Path = change.Path;
            Diff = new UnifiedDiffViewModel(diff);
            Summary = new SummaryViewModel();
            Summary.Inserts = Diff.Lines.Count(x =>
                x.LineType == GitSharp.Diff.EditType.Inserted ||
                (x.LineType == GitSharp.Diff.EditType.Replaced && x.LineB.HasValue) // new ones
            );

            Summary.Deletes = Diff.Lines.Count(x =>
                x.LineType == GitSharp.Diff.EditType.Deleted ||
                (x.LineType == GitSharp.Diff.EditType.Replaced && x.LineA.HasValue) // replaced with new one(s)
            );
        }
コード例 #3
0
 private UnifiedDiffViewModel(UnifiedDiffViewModel other)
     : this()
 {
     Lines.AddRange(other.Lines);
 }