List of usage examples for org.eclipse.jgit.diff HistogramDiff HistogramDiff
HistogramDiff
From source file:com.google.gerrit.server.patch.PatchListLoader.java
License:Apache License
private FileHeader toFileHeaderWithoutMyersDiff(DiffFormatter diffFormatter, DiffEntry diffEntry) throws IOException { HistogramDiff histogramDiff = new HistogramDiff(); histogramDiff.setFallbackAlgorithm(null); diffFormatter.setDiffAlgorithm(histogramDiff); return diffFormatter.toFileHeader(diffEntry); }
From source file:com.google.gerrit.server.patch.PatchListLoader.java
License:Apache License
private PatchListEntry newCommitMessage(final RawTextComparator cmp, final ObjectReader reader, final RevCommit aCommit, final RevCommit bCommit) throws IOException { StringBuilder hdr = new StringBuilder(); hdr.append("diff --git"); if (aCommit != null) { hdr.append(" a/").append(Patch.COMMIT_MSG); } else {//w w w.java2s. co m hdr.append(" ").append(FileHeader.DEV_NULL); } hdr.append(" b/").append(Patch.COMMIT_MSG); hdr.append("\n"); if (aCommit != null) { hdr.append("--- a/").append(Patch.COMMIT_MSG).append("\n"); } else { hdr.append("--- ").append(FileHeader.DEV_NULL).append("\n"); } hdr.append("+++ b/").append(Patch.COMMIT_MSG).append("\n"); Text aText = aCommit != null ? Text.forCommit(reader, aCommit) : Text.EMPTY; Text bText = Text.forCommit(reader, bCommit); byte[] rawHdr = hdr.toString().getBytes("UTF-8"); RawText aRawText = new RawText(aText.getContent()); RawText bRawText = new RawText(bText.getContent()); EditList edits = new HistogramDiff().diff(cmp, aRawText, bRawText); FileHeader fh = new FileHeader(rawHdr, edits, PatchType.UNIFIED); return new PatchListEntry(fh, edits); }
From source file:com.wira.ews.test.textDiff.TestJGit.java
License:Apache License
@SuppressWarnings("resource") @Test//ww w .ja v a 2 s . c om public void tesGetDiff() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // RawText rt1 = new RawText(new File("/home/wladek/Downloads/t1.txt")); // RawText rt2 = new RawText(new File("/home/wladek/Downloads/t2.txt")); RawText rt1 = new RawText("Testing diffs".getBytes()); RawText rt2 = new RawText("Testing diffs2".getBytes()); EditList diffList = new EditList(); diffList.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, rt2, rt1)); new DiffFormatter(out).format(diffList, rt2, rt1); } catch (IOException e) { e.printStackTrace(); } String output = out.toString(); // // File fileTo = new File("/home/wladek/Downloads/testjGIT.txt"); // // if (!fileTo.exists()) { // fileTo.createNewFile(); // } // // FileWriter fw = new FileWriter(fileTo.getAbsoluteFile()); // // BufferedWriter bw = new BufferedWriter(fw); // // // bw.write(output); // // bw.flush(); if (output.isEmpty()) { logger.info("Empty === "); } else { logger.info(" NOT EMPTY "); } System.out.println(" DIFFERENCE " + output); }
From source file:org.apache.nifi.persistence.TemplateSerializerTest.java
License:Apache License
@Test public void validateDiffWithChangingComponentIdAndAdditionalElements() throws Exception { // Create initial template (TemplateDTO) FlowSnippetDTO snippet = new FlowSnippetDTO(); Set<ProcessorDTO> procs = new HashSet<>(); for (int i = 4; i > 0; i--) { ProcessorDTO procDTO = new ProcessorDTO(); procDTO.setType("Processor" + i + ".class"); procDTO.setId(ComponentIdGenerator.generateId().toString()); procs.add(procDTO);//from www . j a v a 2 s . c o m } snippet.setProcessors(procs); TemplateDTO origTemplate = new TemplateDTO(); origTemplate.setDescription("MyTemplate"); origTemplate.setId("MyTemplate"); origTemplate.setSnippet(snippet); byte[] serTemplate = TemplateSerializer.serialize(origTemplate); // Deserialize Template into TemplateDTO ByteArrayInputStream in = new ByteArrayInputStream(serTemplate); JAXBContext context = JAXBContext.newInstance(TemplateDTO.class); Unmarshaller unmarshaller = context.createUnmarshaller(); XMLStreamReader xsr = XmlUtils.createSafeReader(in); JAXBElement<TemplateDTO> templateElement = unmarshaller.unmarshal(xsr, TemplateDTO.class); TemplateDTO deserTemplate = templateElement.getValue(); // Modify deserialized template FlowSnippetDTO deserSnippet = deserTemplate.getSnippet(); Set<ProcessorDTO> deserProcs = deserSnippet.getProcessors(); int c = 0; for (ProcessorDTO processorDTO : deserProcs) { if (c % 2 == 0) { processorDTO.setName("Hello-" + c); } c++; } // add new Processor ProcessorDTO procDTO = new ProcessorDTO(); procDTO.setType("ProcessorNew" + ".class"); procDTO.setId(ComponentIdGenerator.generateId().toString()); deserProcs.add(procDTO); // Serialize modified template byte[] serTemplate2 = TemplateSerializer.serialize(deserTemplate); RawText rt1 = new RawText(serTemplate); RawText rt2 = new RawText(serTemplate2); EditList diffList = new EditList(); diffList.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, rt1, rt2)); ByteArrayOutputStream out = new ByteArrayOutputStream(); try (DiffFormatter diff = new DiffFormatter(out)) { diff.format(diffList, rt1, rt2); BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(out.toByteArray()), StandardCharsets.UTF_8)); List<String> changes = reader.lines().peek(System.out::println) .filter(line -> line.startsWith("+") || line.startsWith("-")).collect(Collectors.toList()); assertEquals("+ <name>Hello-0</name>", changes.get(0)); assertEquals("+ <name>Hello-2</name>", changes.get(1)); assertEquals("+ <processors>", changes.get(2)); assertEquals("+ <type>ProcessorNew.class</type>", changes.get(4)); assertEquals("+ </processors>", changes.get(5)); } }
From source file:org.apache.oozie.command.coord.CoordUpdateXCommand.java
License:Apache License
/** * Get the differences in git format./*from www .j a va 2 s. c om*/ * * @param string1 the string1 * @param string2 the string2 * @return the diff * @throws IOException Signals that an I/O exception has occurred. */ private String getDiffinGitFormat(String string1, String string2) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); RawText rt1 = new RawText(string1.getBytes()); RawText rt2 = new RawText(string2.getBytes()); EditList diffList = new EditList(); diffList.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, rt1, rt2)); new DiffFormatter(out).format(diffList, rt1, rt2); return out.toString(); }
From source file:org.gitective.core.BlobUtils.java
License:Open Source License
/** * Diff the blobs at the given object ids. * <p>/* w ww . ja v a 2s . co m*/ * This method will return an empty list if the content of either blob is * binary. * * @param repository * @param blob1 * @param blob2 * @param comparator * @return list of edits, never null */ public static Collection<Edit> diff(final Repository repository, final ObjectId blob1, final ObjectId blob2, final RawTextComparator comparator) { if (repository == null) throw new IllegalArgumentException(Assert.formatNotNull("Repository")); if (blob1 == null) throw new IllegalArgumentException(Assert.formatNotNull("Blob id 1")); if (blob2 == null) throw new IllegalArgumentException(Assert.formatNotNull("Blob id 2")); if (comparator == null) throw new IllegalArgumentException(Assert.formatNotNull("Comparator")); if (blob1.equals(blob2)) return Collections.emptyList(); final byte[] data1; if (!blob1.equals(ObjectId.zeroId())) { data1 = getBytes(repository, blob1); if (RawText.isBinary(data1)) return Collections.emptyList(); } else data1 = new byte[0]; final byte[] data2; if (!blob2.equals(ObjectId.zeroId())) { data2 = getBytes(repository, blob2); if (RawText.isBinary(data2)) return Collections.emptyList(); } else data2 = new byte[0]; return new HistogramDiff().diff(comparator, // data1.length > 0 ? new RawText(data1) : EMPTY_TEXT, // data2.length > 0 ? new RawText(data2) : EMPTY_TEXT); }
From source file:org.gitective.core.BlobUtils.java
License:Open Source License
/** * Diff the blobs at the given object ids. * <p>// ww w . j a v a 2 s.c o m * This method will return an empty list if the content of either blob is * binary. * * @param reader * @param blob1 * @param blob2 * @param comparator * @return list of edits, never null */ public static Collection<Edit> diff(final ObjectReader reader, final ObjectId blob1, final ObjectId blob2, final RawTextComparator comparator) { if (reader == null) throw new IllegalArgumentException(Assert.formatNotNull("Reader")); if (blob1 == null) throw new IllegalArgumentException(Assert.formatNotNull("Blob id 1")); if (blob2 == null) throw new IllegalArgumentException(Assert.formatNotNull("Blob id 2")); if (comparator == null) throw new IllegalArgumentException(Assert.formatNotNull("Comparator")); if (blob1.equals(blob2)) return Collections.emptyList(); final byte[] data1; if (!blob1.equals(ObjectId.zeroId())) { data1 = getBytes(reader, blob1); if (RawText.isBinary(data1)) return Collections.emptyList(); } else data1 = new byte[0]; final byte[] data2; if (!blob2.equals(ObjectId.zeroId())) { data2 = getBytes(reader, blob2); if (RawText.isBinary(data2)) return Collections.emptyList(); } else data2 = new byte[0]; return new HistogramDiff().diff(comparator, // data1.length > 0 ? new RawText(data1) : EMPTY_TEXT, // data2.length > 0 ? new RawText(data2) : EMPTY_TEXT); }