protected void FireLineAnalyzedEvent(DiffLineNum diffline) { var handler = OnLineNumAnalyzed; if (handler != null) { handler(diffline); } }
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++; } } }
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 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); }
protected void FireLineAnalyzedEvent(DiffLineNum diffline) { var handler = OnLineNumAnalyzed; if (handler != null) handler(diffline); }
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 AddDiffLineNum(DiffLineNum diffLineNum) { DiffLines[diffLineNum.LineNumInDiff] = diffLineNum; _maxValueOfLineNum = Math.Max(diffLineNum.LeftLineNum, diffLineNum.RightLineNum); }