Esempio n. 1
0
        protected void FireLineAnalyzedEvent(DiffLineNum diffline)
        {
            var handler = OnLineNumAnalyzed;

            if (handler != null)
            {
                handler(diffline);
            }
        }
Esempio n. 2
0
        public void Start(string diffContent)
        {
            var isCombinedDiff      = PatchProcessor.IsCombinedDiff(diffContent);
            var lineNumInDiff       = 0;
            var leftLineNum         = DiffLineNum.NotApplicableLineNum;
            var rightLineNum        = DiffLineNum.NotApplicableLineNum;
            var isHeaderLineLocated = false;

            foreach (var line in diffContent.Split('\n'))
            {
                if (_bgWorker.CancellationPending)
                {
                    return;
                }
                lineNumInDiff++;
                if (line.StartsWith("@"))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = DiffLineNum.NotApplicableLineNum,
                        RightLineNum  = DiffLineNum.NotApplicableLineNum,
                        Style         = DiffLineNum.DiffLineStyle.Header
                    };
                    var regex =
                        new Regex(
                            @"\-(?<leftStart>\d{1,})\,{0,}(?<leftCount>\d{0,})\s\+(?<rightStart>\d{1,})\,{0,}(?<rightCount>\d{0,})",
                            RegexOptions.Compiled | RegexOptions.IgnoreCase);

                    var lineNumbers = regex.Match(line);
                    leftLineNum  = int.Parse(lineNumbers.Groups["leftStart"].Value);
                    rightLineNum = int.Parse(lineNumbers.Groups["rightStart"].Value);

                    FireLineAnalyzedEvent(meta);
                    isHeaderLineLocated = true;
                }
                else if (isHeaderLineLocated && isCombinedDiff)
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = DiffLineNum.NotApplicableLineNum,
                        RightLineNum  = DiffLineNum.NotApplicableLineNum,
                    };

                    if (IsMinusLineInCombinedDiff(line))
                    {
                        meta.Style = DiffLineNum.DiffLineStyle.Minus;
                    }
                    else if (IsPlusLineInCombinedDiff(line))
                    {
                        meta.Style        = DiffLineNum.DiffLineStyle.Plus;
                        meta.RightLineNum = rightLineNum;
                        rightLineNum++;
                    }
                    else
                    {
                        meta.Style        = DiffLineNum.DiffLineStyle.Context;
                        meta.RightLineNum = rightLineNum;
                        rightLineNum++;
                    }

                    FireLineAnalyzedEvent(meta);
                }

                else if (isHeaderLineLocated && IsMinusLine(line))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = leftLineNum,
                        RightLineNum  = DiffLineNum.NotApplicableLineNum,
                        Style         = DiffLineNum.DiffLineStyle.Minus
                    };
                    FireLineAnalyzedEvent(meta);

                    leftLineNum++;
                }
                else if (isHeaderLineLocated && IsPlusLine(line))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = DiffLineNum.NotApplicableLineNum,
                        RightLineNum  = rightLineNum,
                        Style         = DiffLineNum.DiffLineStyle.Plus,
                    };
                    FireLineAnalyzedEvent(meta);
                    rightLineNum++;
                }
                else if (isHeaderLineLocated)
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = leftLineNum,
                        RightLineNum  = rightLineNum,
                        Style         = DiffLineNum.DiffLineStyle.Context,
                    };
                    FireLineAnalyzedEvent(meta);

                    leftLineNum++;
                    rightLineNum++;
                }
            }
        }
Esempio n. 3
0
 private void AddToResult(Result result, DiffLineNum diffLine)
 {
     result.LineNumbers.Add(diffLine.LineNumInDiff, diffLine);
     result.MaxLineNumber = Math.Max(result.MaxLineNumber,
                                     Math.Max(diffLine.LeftLineNum, diffLine.RightLineNum));
 }
Esempio n. 4
0
        public Result Analyze(string diffContent)
        {
            var ret                 = new Result();
            var isCombinedDiff      = PatchProcessor.IsCombinedDiff(diffContent);
            var lineNumInDiff       = 0;
            var leftLineNum         = DiffLineNum.NotApplicableLineNum;
            var rightLineNum        = DiffLineNum.NotApplicableLineNum;
            var isHeaderLineLocated = false;

            foreach (var line in diffContent.Split('\n'))
            {
                lineNumInDiff++;
                if (line.StartsWith("@"))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = DiffLineNum.NotApplicableLineNum,
                        RightLineNum  = DiffLineNum.NotApplicableLineNum,
                        Style         = DiffLineNum.DiffLineStyle.Header
                    };

                    var lineNumbers = regex.Match(line);
                    leftLineNum  = int.Parse(lineNumbers.Groups["leftStart"].Value);
                    rightLineNum = int.Parse(lineNumbers.Groups["rightStart"].Value);

                    AddToResult(ret, meta);
                    isHeaderLineLocated = true;
                }
                else if (isHeaderLineLocated && isCombinedDiff)
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = DiffLineNum.NotApplicableLineNum,
                        RightLineNum  = DiffLineNum.NotApplicableLineNum,
                    };

                    if (IsMinusLineInCombinedDiff(line))
                    {
                        meta.Style = DiffLineNum.DiffLineStyle.Minus;
                    }
                    else if (IsPlusLineInCombinedDiff(line))
                    {
                        meta.Style        = DiffLineNum.DiffLineStyle.Plus;
                        meta.RightLineNum = rightLineNum;
                        rightLineNum++;
                    }
                    else
                    {
                        meta.Style        = DiffLineNum.DiffLineStyle.Context;
                        meta.RightLineNum = rightLineNum;
                        rightLineNum++;
                    }

                    AddToResult(ret, meta);
                }

                else if (isHeaderLineLocated && IsMinusLine(line))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = leftLineNum,
                        RightLineNum  = DiffLineNum.NotApplicableLineNum,
                        Style         = DiffLineNum.DiffLineStyle.Minus
                    };
                    AddToResult(ret, meta);

                    leftLineNum++;
                }
                else if (isHeaderLineLocated && IsPlusLine(line))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = DiffLineNum.NotApplicableLineNum,
                        RightLineNum  = rightLineNum,
                        Style         = DiffLineNum.DiffLineStyle.Plus,
                    };
                    AddToResult(ret, meta);
                    rightLineNum++;
                }
                else if (line.StartsWith(GitModule.NoNewLineAtTheEnd))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = DiffLineNum.NotApplicableLineNum,
                        RightLineNum  = DiffLineNum.NotApplicableLineNum,
                        Style         = DiffLineNum.DiffLineStyle.Header
                    };
                    AddToResult(ret, meta);
                }
                else if (isHeaderLineLocated)
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum   = leftLineNum,
                        RightLineNum  = rightLineNum,
                        Style         = DiffLineNum.DiffLineStyle.Context,
                    };
                    AddToResult(ret, meta);

                    leftLineNum++;
                    rightLineNum++;
                }
            }
            return(ret);
        }
        public void Start(string diffContent)
        {
            var isCombinedDiff = PatchProcessor.IsCombinedDiff(diffContent);
            var lineNumInDiff = 0;
            var leftLineNum = DiffLineNum.NotApplicableLineNum;
            var rightLineNum = DiffLineNum.NotApplicableLineNum;
            var isHeaderLineLocated = false;
            foreach (var line in diffContent.Split('\n'))
            {
                if (_bgWorker.CancellationPending)
                {
                    return;
                }
                lineNumInDiff++;
                if (line.StartsWith("@"))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = DiffLineNum.NotApplicableLineNum,
                        RightLineNum = DiffLineNum.NotApplicableLineNum,
                        Style = DiffLineNum.DiffLineStyle.Header
                    };
                    var regex =
                        new Regex(
                            @"\-(?<leftStart>\d{1,})\,{0,}(?<leftCount>\d{0,})\s\+(?<rightStart>\d{1,})\,{0,}(?<rightCount>\d{0,})",
                            RegexOptions.Compiled | RegexOptions.IgnoreCase);

                    var lineNumbers = regex.Match(line);
                    leftLineNum = int.Parse(lineNumbers.Groups["leftStart"].Value);
                    rightLineNum = int.Parse(lineNumbers.Groups["rightStart"].Value);

                    FireLineAnalyzedEvent(meta);
                    isHeaderLineLocated = true;
                }
                else if (isHeaderLineLocated && isCombinedDiff)
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = DiffLineNum.NotApplicableLineNum,
                        RightLineNum = DiffLineNum.NotApplicableLineNum,
                    };

                    if (IsMinusLineInCombinedDiff(line))
                    {
                        meta.Style = DiffLineNum.DiffLineStyle.Minus;
                    }
                    else if (IsPlusLineInCombinedDiff(line))
                    {
                        meta.Style = DiffLineNum.DiffLineStyle.Plus;
                        meta.RightLineNum = rightLineNum;
                        rightLineNum++;
                    }
                    else
                    {
                        meta.Style = DiffLineNum.DiffLineStyle.Context;
                        meta.RightLineNum = rightLineNum;
                        rightLineNum++;
                    }

                    FireLineAnalyzedEvent(meta);
                }

                else if (isHeaderLineLocated && IsMinusLine(line))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = leftLineNum,
                        RightLineNum = DiffLineNum.NotApplicableLineNum,
                        Style = DiffLineNum.DiffLineStyle.Minus
                    };
                    FireLineAnalyzedEvent(meta);

                    leftLineNum++;
                }
                else if (isHeaderLineLocated && IsPlusLine(line))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = DiffLineNum.NotApplicableLineNum,
                        RightLineNum = rightLineNum,
                        Style = DiffLineNum.DiffLineStyle.Plus,
                    };
                    FireLineAnalyzedEvent(meta);
                    rightLineNum++;
                }
                else if (isHeaderLineLocated)
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = leftLineNum,
                        RightLineNum = rightLineNum,
                        Style = DiffLineNum.DiffLineStyle.Context,
                    };
                    FireLineAnalyzedEvent(meta);

                    leftLineNum++;
                    rightLineNum++;
                }
            }
        }
 protected void FireLineAnalyzedEvent(DiffLineNum diffline)
 {
     var handler = OnLineNumAnalyzed;
     if (handler != null) handler(diffline);
 }
Esempio n. 7
0
        public Result Analyze(string diffContent)
        {
            var ret = new Result();
            var isCombinedDiff = PatchProcessor.IsCombinedDiff(diffContent);
            var lineNumInDiff = 0;
            var leftLineNum = DiffLineNum.NotApplicableLineNum;
            var rightLineNum = DiffLineNum.NotApplicableLineNum;
            var isHeaderLineLocated = false;
            foreach (var line in diffContent.Split('\n'))
            {
                lineNumInDiff++;
                if (line.StartsWith("@"))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = DiffLineNum.NotApplicableLineNum,
                        RightLineNum = DiffLineNum.NotApplicableLineNum,
                        Style = DiffLineNum.DiffLineStyle.Header
                    };

                    var lineNumbers = regex.Match(line);
                    leftLineNum = int.Parse(lineNumbers.Groups["leftStart"].Value);
                    rightLineNum = int.Parse(lineNumbers.Groups["rightStart"].Value);

                    AddToResult(ret, meta);
                    isHeaderLineLocated = true;
                }
                else if (isHeaderLineLocated && isCombinedDiff)
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = DiffLineNum.NotApplicableLineNum,
                        RightLineNum = DiffLineNum.NotApplicableLineNum,
                    };

                    if (IsMinusLineInCombinedDiff(line))
                    {
                        meta.Style = DiffLineNum.DiffLineStyle.Minus;
                    }
                    else if (IsPlusLineInCombinedDiff(line))
                    {
                        meta.Style = DiffLineNum.DiffLineStyle.Plus;
                        meta.RightLineNum = rightLineNum;
                        rightLineNum++;
                    }
                    else
                    {
                        meta.Style = DiffLineNum.DiffLineStyle.Context;
                        meta.RightLineNum = rightLineNum;
                        rightLineNum++;
                    }

                    AddToResult(ret, meta);
                }

                else if (isHeaderLineLocated && IsMinusLine(line))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = leftLineNum,
                        RightLineNum = DiffLineNum.NotApplicableLineNum,
                        Style = DiffLineNum.DiffLineStyle.Minus
                    };
                    AddToResult(ret, meta);

                    leftLineNum++;
                }
                else if (isHeaderLineLocated && IsPlusLine(line))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = DiffLineNum.NotApplicableLineNum,
                        RightLineNum = rightLineNum,
                        Style = DiffLineNum.DiffLineStyle.Plus,
                    };
                    AddToResult(ret, meta);
                    rightLineNum++;
                }
                else if (line.StartsWith(GitModule.NoNewLineAtTheEnd))
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = DiffLineNum.NotApplicableLineNum,
                        RightLineNum = DiffLineNum.NotApplicableLineNum,
                        Style = DiffLineNum.DiffLineStyle.Header
                    };
                    AddToResult(ret, meta);
                }
                else if (isHeaderLineLocated)
                {
                    var meta = new DiffLineNum
                    {
                        LineNumInDiff = lineNumInDiff,
                        LeftLineNum = leftLineNum,
                        RightLineNum = rightLineNum,
                        Style = DiffLineNum.DiffLineStyle.Context,
                    };
                    AddToResult(ret, meta);

                    leftLineNum++;
                    rightLineNum++;
                }
            }
            return ret;
        }
Esempio n. 8
0
 private void AddToResult(Result result, DiffLineNum diffLine)
 {
     result.LineNumbers.Add(diffLine.LineNumInDiff, diffLine);
     result.MaxLineNumber = Math.Max(result.MaxLineNumber,
         Math.Max(diffLine.LeftLineNum, diffLine.RightLineNum));
 }
 public void AddDiffLineNum(DiffLineNum diffLineNum)
 {
     DiffLines[diffLineNum.LineNumInDiff] = diffLineNum;
     _maxValueOfLineNum = Math.Max(diffLineNum.LeftLineNum, diffLineNum.RightLineNum);
 }