示例#1
0
        public void Subtract(DiffStats stats)
        {
            Verify.Argument.IsNotNull(stats, nameof(stats));

            _addedLinesCount   -= stats._addedLinesCount;
            _removedLinesCount -= stats._removedLinesCount;
            _contextLinesCount -= stats._contextLinesCount;
            _headerLinesCount  -= stats._headerLinesCount;
        }
示例#2
0
        public void Add(DiffStats stats)
        {
            Verify.Argument.IsNotNull(stats, "stats");

            _addedLinesCount   += stats._addedLinesCount;
            _removedLinesCount += stats._removedLinesCount;
            _contextLinesCount += stats._contextLinesCount;
            _headerLinesCount  += stats._headerLinesCount;
        }
示例#3
0
文件: DiffHunk.cs 项目: kiple/gitter
        /// <summary>Create <see cref="DiffHunk"/>.</summary>
        /// <param name="headers">Column headers.</param>
        /// <param name="lines">List of diff lines.</param>
        /// <param name="stats"><see cref="DiffStats"/>.</param>
        public DiffHunk(DiffColumnHeader[] headers, IList <DiffLine> lines, DiffStats stats, bool isBinary)
        {
            Verify.Argument.IsNotNull(headers, nameof(headers));
            Verify.Argument.IsNotNull(lines, nameof(lines));
            Verify.Argument.IsNotNull(stats, nameof(stats));

            _headers = headers;
            _lines   = lines;
            Stats    = stats;
            IsBinary = isBinary;
        }
示例#4
0
文件: DiffHunk.cs 项目: oqewok/gitter
        /// <summary>Create <see cref="DiffHunk"/>.</summary>
        /// <param name="lines">List of diff lines.</param>
        /// <param name="colCount">Column headers.</param>
        /// <param name="stats"><see cref="DiffStats"/>.</param>
        public DiffHunk(DiffColumnHeader[] headers, IList <DiffLine> lines, DiffStats stats, bool isBinary)
        {
            Verify.Argument.IsNotNull(headers, "headers");
            Verify.Argument.IsNotNull(lines, "lines");
            Verify.Argument.IsNotNull(stats, "stats");

            _headers  = headers;
            _lines    = lines;
            _stats    = stats;
            _isBinary = isBinary;
        }
示例#5
0
        public DiffFile Cut(int from, int count)
        {
            var h = new List <DiffHunk>();
            var s = new DiffStats();

            int sl  = 0;
            int hid = 0;

            while (sl + _hunks[hid].LineCount <= from)
            {
                sl += _hunks[hid].LineCount;
                ++hid;
            }

            int start = from - sl;

            while (count > 0)
            {
                var hunk = _hunks[hid];
                var c    = count;
                if (c + start > hunk.LineCount)
                {
                    c = hunk.LineCount - start;
                }
                var newHunk = hunk.Cut(start, c);
                h.Add(newHunk);
                s.Add(newHunk.Stats);
                count -= c;
                start  = 0;
                ++hid;
            }

            return(new DiffFile(
                       OldIndex,
                       NewIndex,
                       OldMode,
                       NewMode,
                       SourceFile,
                       TargetFile,
                       Status,
                       h,
                       IsBinary,
                       s));
        }
示例#6
0
        /// <summary>Create <see cref="DiffFile"/>.</summary>
        /// <param name="oldIndex">Old index value.</param>
        /// <param name="newIndex">New index value.</param>
        /// <param name="oldMode">Old mode value.</param>
        /// <param name="newMode">New mode value.</param>
        /// <param name="sourceFile">Source file name.</param>
        /// <param name="targetFile">Target file name.</param>
        /// <param name="status">File status.</param>
        /// <param name="hunks">List of <see cref="DiffHunk"/>.</param>
        /// <param name="isBinary">File is binary.</param>
        /// <param name="stats"><see cref="DiffStats"/>.</param>
        public DiffFile(
            string oldIndex, string newIndex, int oldMode, int newMode,
            string sourceFile, string targetFile,
            FileStatus status, IList <DiffHunk> hunks, bool isBinary, DiffStats stats)
        {
            Verify.Argument.IsNotNull(hunks, nameof(hunks));
            Verify.Argument.IsNotNull(stats, nameof(stats));

            OldIndex   = oldIndex;
            NewIndex   = newIndex;
            OldMode    = oldMode;
            NewMode    = newMode;
            SourceFile = sourceFile;
            TargetFile = targetFile;
            Status     = status;
            _hunks     = hunks;
            IsBinary   = isBinary;
            Stats      = stats;
        }
示例#7
0
文件: DiffFile.cs 项目: oqewok/gitter
        /// <summary>Create <see cref="DiffFile"/>.</summary>
        /// <param name="oldIndex">Old index value.</param>
        /// <param name="newIndex">New index value.</param>
        /// <param name="oldMode">Old mode value.</param>
        /// <param name="newMode">New mode value.</param>
        /// <param name="sourceFile">Source file name.</param>
        /// <param name="targetFile">Target file name.</param>
        /// <param name="status">File status.</param>
        /// <param name="hunks">List of <see cref="DiffHunk"/>.</param>
        /// <param name="isBinary">File is binary.</param>
        /// <param name="stats"><see cref="DiffStats"/>.</param>
        public DiffFile(
            string oldIndex, string newIndex, int oldMode, int newMode,
            string sourceFile, string targetFile,
            FileStatus status, IList <DiffHunk> hunks, bool isBinary, DiffStats stats)
        {
            Verify.Argument.IsNotNull(hunks, "hunks");
            Verify.Argument.IsNotNull(stats, "stats");

            _oldIndex   = oldIndex;
            _newIndex   = newIndex;
            _oldMode    = oldMode;
            _newMode    = newMode;
            _sourceFile = sourceFile;
            _targetFile = targetFile;
            _status     = status;
            _hunks      = hunks;
            _isBinary   = isBinary;
            _stats      = stats;
        }
示例#8
0
文件: DiffStats.cs 项目: Kuzq/gitter
        public void Subtract(DiffStats stats)
        {
            Verify.Argument.IsNotNull(stats, "stats");

            _addedLinesCount -= stats._addedLinesCount;
            _removedLinesCount -= stats._removedLinesCount;
            _contextLinesCount -= stats._contextLinesCount;
            _headerLinesCount -= stats._headerLinesCount;
        }
示例#9
0
文件: DiffHunk.cs 项目: kiple/gitter
        public DiffHunk Cut(int from, int count)
        {
            if ((from < 0) || (from == _lines.Count))
            {
                throw new ArgumentOutOfRangeException(nameof(from));
            }
            if ((count <= 0) || (from + count > _lines.Count))
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            int to = from + count - 1;

            // exclude header
            if (from == 0)
            {
                ++from;
            }
            // expand with context
            while (from > 1 && _lines[from - 1].State == DiffLineState.Context)
            {
                --from;
            }
            while (to < _lines.Count - 1 && _lines[to + 1].State == DiffLineState.Context)
            {
                ++to;
            }
            if (from == 1 && to == _lines.Count - 1)
            {
                // copy whole hunk
                var lines = new List <DiffLine>(_lines.Count);
                lines.AddRange(_lines);
                return(new DiffHunk(_headers, lines, Stats.Clone(), IsBinary));
            }
            else
            {
                var lines = new List <DiffLine>(to - from + 2);
                // prepare new header
                int rf = _lines[from].Nums[0];
                int af = _lines[from].Nums[1];
                int rc = 0;
                int ac = 0;
                for (int i = from; i <= to; ++i)
                {
                    switch (_lines[i].State)
                    {
                    case DiffLineState.Removed:
                        ++rc;
                        break;

                    case DiffLineState.Added:
                        ++ac;
                        break;

                    case DiffLineState.Context:
                        ++rc;
                        ++ac;
                        break;
                    }
                }
                var culture = System.Globalization.CultureInfo.InvariantCulture;
                var header  = new DiffLine(
                    DiffLineState.Header,
                    new [] { DiffLineState.Header, DiffLineState.Header },
                    new [] { 0, 0 },
                    string.Format(culture, "@@ -{0},{1} +{2},{3} @@", rf, rc, af, ac),
                    LineEnding.Lf);
                lines.Add(header);
                var stats = new DiffStats();
                stats.Increment(header.State);
                // copy lines
                for (int i = from; i <= to; ++i)
                {
                    var line = _lines[i];
                    lines.Add(line);
                    stats.Increment(line.State);
                }
                return(new DiffHunk(new[]
                {
                    new DiffColumnHeader(DiffColumnAction.Remove, rf, rc),
                    new DiffColumnHeader(DiffColumnAction.Add, af, ac)
                }, lines, stats, IsBinary));
            }
        }