private void BuildEditList() { _editList = DiffAlgorithm.GetAlgorithm(DiffAlgorithm.SupportedAlgorithm.HISTOGRAM).Diff( IgnoreWhitespace ? DiffViewer.Text.Comparator.WS_IGNORE_ALL : DiffViewer.Text.Comparator.DEFAULT, _leftText, _rightText ); }
public void DiffBisectTest_WithTimeout() { var a = "cat"; var b = "map"; var diffs = new List <Diff> { Diff.Delete("cat"), Diff.Insert("map") }; Assert.Equal(diffs, DiffAlgorithm.MyersDiffBisect(a, b, true, new CancellationToken(true))); }
/// <param name="local"></param> /// <param name="inCore"></param> protected internal ResolveMerger(Repository local, bool inCore) : base(local) { DiffAlgorithm.SupportedAlgorithm diffAlg = local.GetConfig().GetEnum(ConfigConstants .CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, DiffAlgorithm.SupportedAlgorithm .HISTOGRAM); mergeAlgorithm = new MergeAlgorithm(DiffAlgorithm.GetAlgorithm(diffAlg)); commitNames = new string[] { "BASE", "OURS", "THEIRS" }; this.inCore = inCore; if (inCore) { dircache = DirCache.NewInCore(); } }
private static void WriteUnifiedDiffBetweenJson(StringBuilder sb, JToken expectedJToken, JToken actualJToken) { NormalizeForTextDiffJson(expectedJToken); NormalizeForTextDiffJson(actualJToken); var expectedJson = JsonConvert.SerializeObject(expectedJToken, Formatting.Indented).Replace("\r\n", "\n"); var actualJson = JsonConvert.SerializeObject(actualJToken, Formatting.Indented).Replace("\r\n", "\n"); var expectedText = new RawText(Encoding.UTF8.GetBytes(expectedJson)); var actualText = new RawText(Encoding.UTF8.GetBytes(actualJson)); var diffAlgorithm = DiffAlgorithm.GetAlgorithm(DiffAlgorithm.SupportedAlgorithm.HISTOGRAM); var differences = diffAlgorithm.Diff(RawTextComparator.WS_IGNORE_ALL, expectedText, actualText); if (differences.Count == 0) { return; } var expectedLines = expectedJson.Split('\n'); var actualLines = actualJson.Split('\n'); var a = 0; var b = 0; var i = 0; var difference = differences[i]; while (a < expectedLines.Length && b < actualLines.Length) { if (difference != null && a >= difference.GetBeginA()) { while (a < difference.GetEndA()) { sb.AppendLine("-" + expectedLines[a]); a++; } while (b < difference.GetEndB()) { sb.AppendLine("+" + actualLines[b]); b++; } i++; difference = i < differences.Count ? differences[i] : null; } else { sb.AppendLine(" " + actualLines[b]); b++; a++; } } }
public static void PopulateDiffs(IList <Diff> diffs, Substring left, Substring right, bool boundRuntime) { int n = left.Length; int m = right.Length; int max = CeilNPlusMOverTwo(n, m); if (boundRuntime && ((long)n) * ((long)m) > TooLong) { max = (int)Math.Pow(max, PowLimit - 1.0); } DiffAlgorithm algorithm = new DiffAlgorithm(diffs, left.Range.StartIndex, right.Range.StartIndex, max); algorithm.ComputeLCS(left, right); algorithm.FlushDiffs(left.Range.EndIndex, right.Range.EndIndex); }
public void DiffBisectTest_NoTimeout() { // Normal. var a = "cat"; var b = "map"; // Since the resulting diff hasn't been normalized, it would be ok if // the insertion and deletion pairs are swapped. // If the order changes, tweak this test as required. var diffs = new List <Diff> { Diff.Delete("c"), Diff.Insert("m"), Diff.Equal("a"), Diff.Delete("t"), Diff.Insert("p") }; Assert.Equal(diffs, DiffAlgorithm.MyersDiffBisect(a, b, false, new CancellationToken())); }
/// <summary>Creates a new MergeAlgorithm</summary> /// <param name="diff">the diff algorithm used by this merge</param> public MergeAlgorithm(DiffAlgorithm diff) { this.diffAlg = diff; }
private static CallSpecAndTarget[] GetCallsExpectedButNoReceived(IEnumerable <CallSpecAndTarget> expectedCalls, IEnumerable <ICall> receivedCalls) { return(DiffAlgorithm.DifferenceBetween(expectedCalls, receivedCalls, (call, spec) => Matches(spec, call))); }
private static ICall[] GetCallsReceivedButNotExpected(IEnumerable <CallSpecAndTarget> expectedCalls, IEnumerable <ICall> receivedCalls) { return(DiffAlgorithm.DifferenceBetween(receivedCalls, expectedCalls, Matches)); }
/// <summary>Difference algorithm to use when comparing revisions.</summary> /// <remarks>Difference algorithm to use when comparing revisions.</remarks> /// <param name="algorithm"></param> /// <returns> /// /// <code>this</code> /// </returns> public virtual NGit.Blame.BlameGenerator SetDiffAlgorithm(DiffAlgorithm algorithm ) { diffAlgorithm = algorithm; return(this); }
public void Dispose() { DiffAlgorithm?.Dispose(); Highlighter?.Dispose(); }
public static void PopulateDiffs(IList<Diff> diffs, Substring left, Substring right, bool boundRuntime) { int n = left.Length; int m = right.Length; int max = CeilNPlusMOverTwo(n, m); if (boundRuntime && ((long) n) * ((long) m) > TooLong) max = (int) Math.Pow(max, PowLimit - 1.0); DiffAlgorithm algorithm = new DiffAlgorithm(diffs, left.Range.StartIndex, right.Range.StartIndex, max); algorithm.ComputeLCS(left, right); algorithm.FlushDiffs(left.Range.EndIndex, right.Range.EndIndex); }
/// <summary> /// Executes the /// <code>Diff</code> /// command with all the options and parameters /// collected by the setter methods (e.g. /// <see cref="SetCached(bool)">SetCached(bool)</see> /// of this /// class. Each instance of this class should only be used for one invocation /// of the command. Don't call this method twice on an instance. /// </summary> /// <returns>a DiffEntry for each path which is different</returns> /// <exception cref="NGit.Api.Errors.GitAPIException"></exception> public override IList <DiffEntry> Call() { DiffFormatter diffFmt; if (@out != null && !showNameAndStatusOnly) { diffFmt = new DiffFormatter(new BufferedOutputStream(@out)); } else { diffFmt = new DiffFormatter(NullOutputStream.INSTANCE); } try { diffFmt.SetRepository(repo); } catch (ArgumentException) { // This means diff algorithm is not supported. } finally { diffFmt.SetDiffAlgorithm(DiffAlgorithm.GetAlgorithm(DiffAlgorithm.SupportedAlgorithm.MYERS)); } diffFmt.SetProgressMonitor(monitor); try { if (cached) { if (oldTree == null) { ObjectId head = repo.Resolve(Constants.HEAD + "^{tree}"); if (head == null) { throw new NoHeadException(JGitText.Get().cannotReadTree); } CanonicalTreeParser p = new CanonicalTreeParser(); ObjectReader reader = repo.NewObjectReader(); try { p.Reset(reader, head); } finally { reader.Release(); } oldTree = p; } newTree = new DirCacheIterator(repo.ReadDirCache()); } else { if (oldTree == null) { oldTree = new DirCacheIterator(repo.ReadDirCache()); } if (newTree == null) { newTree = new FileTreeIterator(repo); } } diffFmt.SetPathFilter(pathFilter); IList <DiffEntry> result = diffFmt.Scan(oldTree, newTree); if (showNameAndStatusOnly) { return(result); } else { if (contextLines >= 0) { diffFmt.SetContext(contextLines); } if (destinationPrefix != null) { diffFmt.SetNewPrefix(destinationPrefix); } if (sourcePrefix != null) { diffFmt.SetOldPrefix(sourcePrefix); } diffFmt.Format(result); diffFmt.Flush(); return(result); } } catch (IOException e) { throw new JGitInternalException(e.Message, e); } finally { diffFmt.Release(); } }
/// <summary>Set diff algorithm</summary> /// <param name="diffAlgorithm"></param> /// <returns>this command</returns> public virtual NGit.Api.BlameCommand SetDiffAlgorithm(DiffAlgorithm diffAlgorithm ) { this.diffAlgorithm = diffAlgorithm; return(this); }
private static void SlowDiff(IList <Diff> diffs, Substring left, Substring right, bool boundRuntime) { DiffAlgorithm.PopulateDiffs(diffs, left, right, boundRuntime); }