You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DiffFormatter.java 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Copyright (C) 2009, Google Inc.
  3. * Copyright (C) 2008-2009, Johannes E. Schindelin <johannes.schindelin@gmx.de>
  4. * and other copyright owners as documented in the project's IP log.
  5. *
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Distribution License v1.0 which
  8. * accompanies this distribution, is reproduced below, and is
  9. * available at http://www.eclipse.org/org/documents/edl-v10.php
  10. *
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials provided
  23. * with the distribution.
  24. *
  25. * - Neither the name of the Eclipse Foundation, Inc. nor the
  26. * names of its contributors may be used to endorse or promote
  27. * products derived from this software without specific prior
  28. * written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  31. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  32. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  33. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  39. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  42. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. */
  44. package org.eclipse.jgit.diff;
  45. import static org.eclipse.jgit.lib.Constants.encode;
  46. import static org.eclipse.jgit.lib.Constants.encodeASCII;
  47. import static org.eclipse.jgit.lib.FileMode.GITLINK;
  48. import java.io.ByteArrayOutputStream;
  49. import java.io.IOException;
  50. import java.io.OutputStream;
  51. import java.util.Collection;
  52. import java.util.List;
  53. import org.eclipse.jgit.JGitText;
  54. import org.eclipse.jgit.errors.AmbiguousObjectException;
  55. import org.eclipse.jgit.errors.CorruptObjectException;
  56. import org.eclipse.jgit.errors.MissingObjectException;
  57. import org.eclipse.jgit.lib.AbbreviatedObjectId;
  58. import org.eclipse.jgit.lib.Constants;
  59. import org.eclipse.jgit.lib.CoreConfig;
  60. import org.eclipse.jgit.lib.FileMode;
  61. import org.eclipse.jgit.lib.ObjectId;
  62. import org.eclipse.jgit.lib.ObjectLoader;
  63. import org.eclipse.jgit.lib.ObjectReader;
  64. import org.eclipse.jgit.lib.Repository;
  65. import org.eclipse.jgit.patch.FileHeader;
  66. import org.eclipse.jgit.patch.HunkHeader;
  67. import org.eclipse.jgit.patch.FileHeader.PatchType;
  68. import org.eclipse.jgit.util.QuotedString;
  69. import org.eclipse.jgit.util.io.DisabledOutputStream;
  70. /**
  71. * Format a Git style patch script.
  72. */
  73. public class DiffFormatter {
  74. private static final byte[] noNewLine = encodeASCII("\\ No newline at end of file\n");
  75. private final OutputStream out;
  76. private Repository db;
  77. private int context = 3;
  78. private int abbreviationLength = 7;
  79. private RawText.Factory rawTextFactory = RawText.FACTORY;
  80. private int bigFileThreshold = 50 * 1024 * 1024;
  81. /**
  82. * Create a new formatter with a default level of context.
  83. *
  84. * @param out
  85. * the stream the formatter will write line data to. This stream
  86. * should have buffering arranged by the caller, as many small
  87. * writes are performed to it.
  88. */
  89. public DiffFormatter(OutputStream out) {
  90. this.out = out;
  91. }
  92. /** @return the stream we are outputting data to. */
  93. protected OutputStream getOutputStream() {
  94. return out;
  95. }
  96. /**
  97. * Set the repository the formatter can load object contents from.
  98. *
  99. * @param repository
  100. * source repository holding referenced objects.
  101. */
  102. public void setRepository(Repository repository) {
  103. db = repository;
  104. CoreConfig cfg = db.getConfig().get(CoreConfig.KEY);
  105. bigFileThreshold = cfg.getStreamFileThreshold();
  106. }
  107. /**
  108. * Change the number of lines of context to display.
  109. *
  110. * @param lineCount
  111. * number of lines of context to see before the first
  112. * modification and after the last modification within a hunk of
  113. * the modified file.
  114. */
  115. public void setContext(final int lineCount) {
  116. if (lineCount < 0)
  117. throw new IllegalArgumentException(
  118. JGitText.get().contextMustBeNonNegative);
  119. context = lineCount;
  120. }
  121. /**
  122. * Change the number of digits to show in an ObjectId.
  123. *
  124. * @param count
  125. * number of digits to show in an ObjectId.
  126. */
  127. public void setAbbreviationLength(final int count) {
  128. if (count < 0)
  129. throw new IllegalArgumentException(
  130. JGitText.get().abbreviationLengthMustBeNonNegative);
  131. abbreviationLength = count;
  132. }
  133. /**
  134. * Set the helper that constructs difference output.
  135. *
  136. * @param type
  137. * the factory to create different output. Different types of
  138. * factories can produce different whitespace behavior, for
  139. * example.
  140. * @see RawText#FACTORY
  141. * @see RawTextIgnoreAllWhitespace#FACTORY
  142. * @see RawTextIgnoreLeadingWhitespace#FACTORY
  143. * @see RawTextIgnoreTrailingWhitespace#FACTORY
  144. * @see RawTextIgnoreWhitespaceChange#FACTORY
  145. */
  146. public void setRawTextFactory(RawText.Factory type) {
  147. rawTextFactory = type;
  148. }
  149. /**
  150. * Set the maximum file size that should be considered for diff output.
  151. * <p>
  152. * Text files that are larger than this size will not have a difference
  153. * generated during output.
  154. *
  155. * @param bigFileThreshold
  156. * the limit, in bytes.
  157. */
  158. public void setBigFileThreshold(int bigFileThreshold) {
  159. this.bigFileThreshold = bigFileThreshold;
  160. }
  161. /**
  162. * Flush the underlying output stream of this formatter.
  163. *
  164. * @throws IOException
  165. * the stream's own flush method threw an exception.
  166. */
  167. public void flush() throws IOException {
  168. out.flush();
  169. }
  170. /**
  171. * Format a patch script from a list of difference entries.
  172. *
  173. * @param entries
  174. * entries describing the affected files.
  175. * @throws IOException
  176. * a file's content cannot be read, or the output stream cannot
  177. * be written to.
  178. */
  179. public void format(List<? extends DiffEntry> entries) throws IOException {
  180. for (DiffEntry ent : entries)
  181. format(ent);
  182. }
  183. /**
  184. * Format a patch script for one file entry.
  185. *
  186. * @param ent
  187. * the entry to be formatted.
  188. * @throws IOException
  189. * a file's content cannot be read, or the output stream cannot
  190. * be written to.
  191. */
  192. public void format(DiffEntry ent) throws IOException {
  193. writeDiffHeader(out, ent);
  194. if (ent.getOldMode() == GITLINK || ent.getNewMode() == GITLINK) {
  195. writeGitLinkDiffText(out, ent);
  196. } else {
  197. if (db == null)
  198. throw new IllegalStateException(
  199. JGitText.get().repositoryIsRequired);
  200. ObjectReader reader = db.newObjectReader();
  201. byte[] aRaw, bRaw;
  202. try {
  203. aRaw = open(reader, ent.getOldMode(), ent.getOldId());
  204. bRaw = open(reader, ent.getNewMode(), ent.getNewId());
  205. } finally {
  206. reader.release();
  207. }
  208. if (RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {
  209. out.write(encodeASCII("Binary files differ\n"));
  210. } else {
  211. RawText a = rawTextFactory.create(aRaw);
  212. RawText b = rawTextFactory.create(bRaw);
  213. formatEdits(a, b, new MyersDiff(a, b).getEdits());
  214. }
  215. }
  216. }
  217. private void writeGitLinkDiffText(OutputStream o, DiffEntry ent)
  218. throws IOException {
  219. if (ent.getOldMode() == GITLINK) {
  220. o.write(encodeASCII("-Subproject commit " + ent.getOldId().name()
  221. + "\n"));
  222. }
  223. if (ent.getNewMode() == GITLINK) {
  224. o.write(encodeASCII("+Subproject commit " + ent.getNewId().name()
  225. + "\n"));
  226. }
  227. }
  228. private void writeDiffHeader(OutputStream o, DiffEntry ent)
  229. throws IOException {
  230. String oldName = quotePath("a/" + ent.getOldPath());
  231. String newName = quotePath("b/" + ent.getNewPath());
  232. o.write(encode("diff --git " + oldName + " " + newName + "\n"));
  233. switch (ent.getChangeType()) {
  234. case ADD:
  235. o.write(encodeASCII("new file mode "));
  236. ent.getNewMode().copyTo(o);
  237. o.write('\n');
  238. break;
  239. case DELETE:
  240. o.write(encodeASCII("deleted file mode "));
  241. ent.getOldMode().copyTo(o);
  242. o.write('\n');
  243. break;
  244. case RENAME:
  245. o.write(encodeASCII("similarity index " + ent.getScore() + "%"));
  246. o.write('\n');
  247. o.write(encode("rename from " + quotePath(ent.getOldPath())));
  248. o.write('\n');
  249. o.write(encode("rename to " + quotePath(ent.getNewPath())));
  250. o.write('\n');
  251. break;
  252. case COPY:
  253. o.write(encodeASCII("similarity index " + ent.getScore() + "%"));
  254. o.write('\n');
  255. o.write(encode("copy from " + quotePath(ent.getOldPath())));
  256. o.write('\n');
  257. o.write(encode("copy to " + quotePath(ent.getNewPath())));
  258. o.write('\n');
  259. if (!ent.getOldMode().equals(ent.getNewMode())) {
  260. o.write(encodeASCII("new file mode "));
  261. ent.getNewMode().copyTo(o);
  262. o.write('\n');
  263. }
  264. break;
  265. case MODIFY:
  266. int score = ent.getScore();
  267. if (0 < score && score <= 100) {
  268. o.write(encodeASCII("dissimilarity index " + (100 - score)
  269. + "%"));
  270. o.write('\n');
  271. }
  272. break;
  273. }
  274. switch (ent.getChangeType()) {
  275. case RENAME:
  276. case MODIFY:
  277. if (!ent.getOldMode().equals(ent.getNewMode())) {
  278. o.write(encodeASCII("old mode "));
  279. ent.getOldMode().copyTo(o);
  280. o.write('\n');
  281. o.write(encodeASCII("new mode "));
  282. ent.getNewMode().copyTo(o);
  283. o.write('\n');
  284. }
  285. }
  286. o.write(encodeASCII("index " //
  287. + format(ent.getOldId()) //
  288. + ".." //
  289. + format(ent.getNewId())));
  290. if (ent.getOldMode().equals(ent.getNewMode())) {
  291. o.write(' ');
  292. ent.getNewMode().copyTo(o);
  293. }
  294. o.write('\n');
  295. o.write(encode("--- " + oldName + '\n'));
  296. o.write(encode("+++ " + newName + '\n'));
  297. }
  298. private String format(AbbreviatedObjectId id) {
  299. if (id.isComplete() && db != null) {
  300. ObjectReader reader = db.newObjectReader();
  301. try {
  302. id = reader.abbreviate(id.toObjectId(), abbreviationLength);
  303. } catch (IOException cannotAbbreviate) {
  304. // Ignore this. We'll report the full identity.
  305. } finally {
  306. reader.release();
  307. }
  308. }
  309. return id.name();
  310. }
  311. private static String quotePath(String name) {
  312. String q = QuotedString.GIT_PATH.quote(name);
  313. return ('"' + name + '"').equals(q) ? name : q;
  314. }
  315. private byte[] open(ObjectReader reader, FileMode mode,
  316. AbbreviatedObjectId id) throws IOException {
  317. if (mode == FileMode.MISSING)
  318. return new byte[] {};
  319. if (mode.getObjectType() != Constants.OBJ_BLOB)
  320. return new byte[] {};
  321. if (!id.isComplete()) {
  322. Collection<ObjectId> ids = reader.resolve(id);
  323. if (ids.size() == 1)
  324. id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
  325. else if (ids.size() == 0)
  326. throw new MissingObjectException(id, Constants.OBJ_BLOB);
  327. else
  328. throw new AmbiguousObjectException(id, ids);
  329. }
  330. ObjectLoader ldr = reader.open(id.toObjectId());
  331. return ldr.getCachedBytes(bigFileThreshold);
  332. }
  333. /**
  334. * Format a patch script, reusing a previously parsed FileHeader.
  335. * <p>
  336. * This formatter is primarily useful for editing an existing patch script
  337. * to increase or reduce the number of lines of context within the script.
  338. * All header lines are reused as-is from the supplied FileHeader.
  339. *
  340. * @param head
  341. * existing file header containing the header lines to copy.
  342. * @param a
  343. * text source for the pre-image version of the content. This
  344. * must match the content of {@link FileHeader#getOldId()}.
  345. * @param b
  346. * text source for the post-image version of the content. This
  347. * must match the content of {@link FileHeader#getNewId()}.
  348. * @throws IOException
  349. * writing to the supplied stream failed.
  350. */
  351. public void format(final FileHeader head, final RawText a, final RawText b)
  352. throws IOException {
  353. // Reuse the existing FileHeader as-is by blindly copying its
  354. // header lines, but avoiding its hunks. Instead we recreate
  355. // the hunks from the text instances we have been supplied.
  356. //
  357. final int start = head.getStartOffset();
  358. int end = head.getEndOffset();
  359. if (!head.getHunks().isEmpty())
  360. end = head.getHunks().get(0).getStartOffset();
  361. out.write(head.getBuffer(), start, end - start);
  362. formatEdits(a, b, head.toEditList());
  363. }
  364. /**
  365. * Formats a list of edits in unified diff format
  366. *
  367. * @param a
  368. * the text A which was compared
  369. * @param b
  370. * the text B which was compared
  371. * @param edits
  372. * some differences which have been calculated between A and B
  373. * @throws IOException
  374. */
  375. public void formatEdits(final RawText a, final RawText b,
  376. final EditList edits) throws IOException {
  377. for (int curIdx = 0; curIdx < edits.size();) {
  378. Edit curEdit = edits.get(curIdx);
  379. final int endIdx = findCombinedEnd(edits, curIdx);
  380. final Edit endEdit = edits.get(endIdx);
  381. int aCur = Math.max(0, curEdit.getBeginA() - context);
  382. int bCur = Math.max(0, curEdit.getBeginB() - context);
  383. final int aEnd = Math.min(a.size(), endEdit.getEndA() + context);
  384. final int bEnd = Math.min(b.size(), endEdit.getEndB() + context);
  385. writeHunkHeader(aCur, aEnd, bCur, bEnd);
  386. while (aCur < aEnd || bCur < bEnd) {
  387. if (aCur < curEdit.getBeginA() || endIdx + 1 < curIdx) {
  388. writeContextLine(a, aCur);
  389. if (isEndOfLineMissing(a, aCur))
  390. out.write(noNewLine);
  391. aCur++;
  392. bCur++;
  393. } else if (aCur < curEdit.getEndA()) {
  394. writeRemovedLine(a, aCur);
  395. if (isEndOfLineMissing(a, aCur))
  396. out.write(noNewLine);
  397. aCur++;
  398. } else if (bCur < curEdit.getEndB()) {
  399. writeAddedLine(b, bCur);
  400. if (isEndOfLineMissing(b, bCur))
  401. out.write(noNewLine);
  402. bCur++;
  403. }
  404. if (end(curEdit, aCur, bCur) && ++curIdx < edits.size())
  405. curEdit = edits.get(curIdx);
  406. }
  407. }
  408. }
  409. /**
  410. * Output a line of context (unmodified line).
  411. *
  412. * @param text
  413. * RawText for accessing raw data
  414. * @param line
  415. * the line number within text
  416. * @throws IOException
  417. */
  418. protected void writeContextLine(final RawText text, final int line)
  419. throws IOException {
  420. writeLine(' ', text, line);
  421. }
  422. private boolean isEndOfLineMissing(final RawText text, final int line) {
  423. return line + 1 == text.size() && text.isMissingNewlineAtEnd();
  424. }
  425. /**
  426. * Output an added line.
  427. *
  428. * @param text
  429. * RawText for accessing raw data
  430. * @param line
  431. * the line number within text
  432. * @throws IOException
  433. */
  434. protected void writeAddedLine(final RawText text, final int line)
  435. throws IOException {
  436. writeLine('+', text, line);
  437. }
  438. /**
  439. * Output a removed line
  440. *
  441. * @param text
  442. * RawText for accessing raw data
  443. * @param line
  444. * the line number within text
  445. * @throws IOException
  446. */
  447. protected void writeRemovedLine(final RawText text, final int line)
  448. throws IOException {
  449. writeLine('-', text, line);
  450. }
  451. /**
  452. * Output a hunk header
  453. *
  454. * @param aStartLine
  455. * within first source
  456. * @param aEndLine
  457. * within first source
  458. * @param bStartLine
  459. * within second source
  460. * @param bEndLine
  461. * within second source
  462. * @throws IOException
  463. */
  464. protected void writeHunkHeader(int aStartLine, int aEndLine,
  465. int bStartLine, int bEndLine) throws IOException {
  466. out.write('@');
  467. out.write('@');
  468. writeRange('-', aStartLine + 1, aEndLine - aStartLine);
  469. writeRange('+', bStartLine + 1, bEndLine - bStartLine);
  470. out.write(' ');
  471. out.write('@');
  472. out.write('@');
  473. out.write('\n');
  474. }
  475. private void writeRange(final char prefix, final int begin, final int cnt)
  476. throws IOException {
  477. out.write(' ');
  478. out.write(prefix);
  479. switch (cnt) {
  480. case 0:
  481. // If the range is empty, its beginning number must be the
  482. // line just before the range, or 0 if the range is at the
  483. // start of the file stream. Here, begin is always 1 based,
  484. // so an empty file would produce "0,0".
  485. //
  486. out.write(encodeASCII(begin - 1));
  487. out.write(',');
  488. out.write('0');
  489. break;
  490. case 1:
  491. // If the range is exactly one line, produce only the number.
  492. //
  493. out.write(encodeASCII(begin));
  494. break;
  495. default:
  496. out.write(encodeASCII(begin));
  497. out.write(',');
  498. out.write(encodeASCII(cnt));
  499. break;
  500. }
  501. }
  502. /**
  503. * Write a standard patch script line.
  504. *
  505. * @param prefix
  506. * prefix before the line, typically '-', '+', ' '.
  507. * @param text
  508. * the text object to obtain the line from.
  509. * @param cur
  510. * line number to output.
  511. * @throws IOException
  512. * the stream threw an exception while writing to it.
  513. */
  514. protected void writeLine(final char prefix, final RawText text,
  515. final int cur) throws IOException {
  516. out.write(prefix);
  517. text.writeLine(out, cur);
  518. out.write('\n');
  519. }
  520. /**
  521. * Creates a {@link FileHeader} representing the given {@link DiffEntry}
  522. * <p>
  523. * This method does not use the OutputStream associated with this
  524. * DiffFormatter instance. It is therefore safe to instantiate this
  525. * DiffFormatter instance with a {@link DisabledOutputStream} if this method
  526. * is the only one that will be used.
  527. *
  528. * @param ent
  529. * the DiffEntry to create the FileHeader for
  530. * @return a FileHeader representing the DiffEntry. The FileHeader's buffer
  531. * will contain only the header of the diff output. It will also
  532. * contain one {@link HunkHeader}.
  533. * @throws IOException
  534. * the stream threw an exception while writing to it, or one of
  535. * the blobs referenced by the DiffEntry could not be read.
  536. * @throws CorruptObjectException
  537. * one of the blobs referenced by the DiffEntry is corrupt.
  538. * @throws MissingObjectException
  539. * one of the blobs referenced by the DiffEntry is missing.
  540. */
  541. public FileHeader createFileHeader(DiffEntry ent) throws IOException,
  542. CorruptObjectException, MissingObjectException {
  543. ByteArrayOutputStream buf = new ByteArrayOutputStream();
  544. final EditList editList;
  545. final FileHeader.PatchType type;
  546. writeDiffHeader(buf, ent);
  547. if (ent.getOldMode() == GITLINK || ent.getNewMode() == GITLINK) {
  548. writeGitLinkDiffText(buf, ent);
  549. editList = new EditList();
  550. type = PatchType.UNIFIED;
  551. } else {
  552. if (db == null)
  553. throw new IllegalStateException(
  554. JGitText.get().repositoryIsRequired);
  555. ObjectReader reader = db.newObjectReader();
  556. byte[] aRaw, bRaw;
  557. try {
  558. aRaw = open(reader, ent.getOldMode(), ent.getOldId());
  559. bRaw = open(reader, ent.getNewMode(), ent.getNewId());
  560. } finally {
  561. reader.release();
  562. }
  563. if (RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {
  564. buf.write(encodeASCII("Binary files differ\n"));
  565. editList = new EditList();
  566. type = PatchType.BINARY;
  567. } else {
  568. RawText a = rawTextFactory.create(aRaw);
  569. RawText b = rawTextFactory.create(bRaw);
  570. editList = new MyersDiff(a, b).getEdits();
  571. type = PatchType.UNIFIED;
  572. }
  573. }
  574. return new FileHeader(buf.toByteArray(), editList, type);
  575. }
  576. private int findCombinedEnd(final List<Edit> edits, final int i) {
  577. int end = i + 1;
  578. while (end < edits.size()
  579. && (combineA(edits, end) || combineB(edits, end)))
  580. end++;
  581. return end - 1;
  582. }
  583. private boolean combineA(final List<Edit> e, final int i) {
  584. return e.get(i).getBeginA() - e.get(i - 1).getEndA() <= 2 * context;
  585. }
  586. private boolean combineB(final List<Edit> e, final int i) {
  587. return e.get(i).getBeginB() - e.get(i - 1).getEndB() <= 2 * context;
  588. }
  589. private static boolean end(final Edit edit, final int a, final int b) {
  590. return edit.getEndA() <= a && edit.getEndB() <= b;
  591. }
  592. }