Home | History | Annotate | Download | only in plaintext

Lines Matching refs:Patch

2  * Diff Match and Patch
5 * http://code.google.com/p/google-diff-match-patch/
40 * Functions for diff, match and patch.
41 * Computes the difference between two texts to create a patch.
42 * Applies the patch onto another text, allowing for errors.
48 * Class containing the diff, match and patch methods.
1685 // PATCH FUNCTIONS
1691 * @param patch The patch to grow.
1694 protected void patch_addContext(Patch patch, String text) {
1698 String pattern = text.substring(patch.start2, patch.start2 + patch.length1);
1706 pattern = text.substring(Math.max(0, patch.start2 - padding),
1707 Math.min(text.length(), patch.start2 + patch.length1 + padding));
1713 String prefix = text.substring(Math.max(0, patch.start2 - padding),
1714 patch.start2);
1716 patch.diffs.addFirst(new Diff(Operation.EQUAL, prefix));
1719 String suffix = text.substring(patch.start2 + patch.length1,
1720 Math.min(text.length(), patch.start2 + patch.length1 + padding));
1722 patch.diffs.addLast(new Diff(Operation.EQUAL, suffix));
1726 patch.start1 -= prefix.length();
1727 patch.start2 -= prefix.length();
1729 patch.length1 += prefix.length() + suffix.length();
1730 patch.length2 += prefix.length() + suffix.length();
1739 * @return LinkedList of Patch objects.
1741 public LinkedList<Patch> patch_make(String text1, String text2) {
1759 * @return LinkedList of Patch objects.
1761 public LinkedList<Patch> patch_make(LinkedList<Diff> diffs) {
1777 * @return LinkedList of Patch objects.
1780 public LinkedList<Patch> patch_make(String text1, String text2,
1791 * @return LinkedList of Patch objects.
1793 public LinkedList<Patch> patch_make(String text1, LinkedList<Diff> diffs) {
1798 LinkedList<Patch> patches = new LinkedList<Patch>();
1802 Patch patch = new Patch();
1811 if (patch.diffs.isEmpty() && aDiff.operation != Operation.EQUAL) {
1812 // A new patch starts here.
1813 patch.start1 = char_count1;
1814 patch.start2 = char_count2;
1819 patch.diffs.add(aDiff);
1820 patch.length2 += aDiff.text.length();
1825 patch.length1 += aDiff.text.length();
1826 patch.diffs.add(aDiff);
1832 && !patch.diffs.isEmpty() && aDiff != diffs.getLast()) {
1833 // Small equality inside a patch.
1834 patch.diffs.add(aDiff);
1835 patch.length1 += aDiff.text.length();
1836 patch.length2 += aDiff.text.length();
1840 // Time for a new patch.
1841 if (!patch.diffs.isEmpty()) {
1842 patch_addContext(patch, prepatch_text);
1843 patches.add(patch);
1844 patch = new Patch();
1845 // Unlike Unidiff, our patch lists have a rolling context.
1846 patch/wiki/Unidiff
1848 // just completed patch.
1864 // Pick up the leftover patch if not empty.
1865 if (!patch.diffs.isEmpty()) {
1866 patch_addContext(patch, prepatch_text);
1867 patches.add(patch);
1876 * @param patches Array of patch objects.
1877 * @return Array of patch objects.
1879 public LinkedList<Patch> patch_deepCopy(LinkedList<Patch> patches) {
1880 LinkedList<Patch> patchesCopy = new LinkedList<Patch>();
1881 for (Patch aPatch : patches) {
1882 Patch patchCopy = new Patch();
1900 * @param patches Array of patch objects
1905 public Object[] patch_apply(LinkedList<Patch> patches, String text) {
1919 // of the previous patch. If there are patches expected at positions 10 and
1920 // 20, but the first patch was found at 12, delta is 2 and the second patch
1924 for (Patch aPatch : patches) {
1939 // Can't find valid trailing context. Drop this patch.
1949 // Subtract the delta for this failed patch from subsequent patches.
2012 * @param patches Array of patch objects.
2015 public String patch_addPadding(LinkedList<Patch> patches) {
2023 for (Patch aPatch : patches) {
2029 Patch patch = patches.getFirst();
2030 LinkedList<Diff> diffs = patch.diffs;
2034 patch.start1 -= paddingLength; // Should be 0.
2035 patch.start2 -= paddingLength; // Should be 0.
2036 patch.length1 += paddingLength;
2037 patch.length2 += paddingLength;
2044 patch.start1 -= extraLength;
2045 patch.start2 -= extraLength;
2046 patch.length1 += extraLength;
2047 patch.length2 += extraLength;
2051 patch = patches.getLast();
2052 diffs = patch.diffs;
2056 patch.length1 += paddingLength;
2057 patch.length2 += paddingLength;
2063 patch.length1 += extraLength;
2064 patch.length2 += extraLength;
2074 * @param patches LinkedList of Patch objects.
2076 public void patch_splitMax(LinkedList<Patch> patches) {
2079 Patch patch;
2084 ListIterator<Patch> pointer = patches.listIterator();
2085 Patch bigpatch = pointer.hasNext() ? pointer.next() : null;
2091 // Remove the big old patch.
2099 patch = new Patch();
2101 patch.start1 = start1 - precontext.length();
2102 patch.start2 = start2 - precontext.length();
2104 patch.length1 = patch.length2 = precontext.length();
2105 patch.diffs.add(new Diff(Operation.EQUAL, precontext));
2108 && patch.length1 < patch_size - Patch_Margin) {
2113 patch.length2 += diff_text.length();
2115 patch.diffs.addLast(bigpatch.diffs.removeFirst());
2117 } else if (diff_type == Operation.DELETE && patch.diffs.size() == 1
2118 && patch.diffs.getFirst().operation == Operation.EQUAL
2121 patch.length1 += diff_text.length();
2124 patch.diffs.add(new Diff(diff_type, diff_text));
2129 patch_size - patch.length1 - Patch_Margin));
2130 patch.length1 += diff_text.length();
2133 patch.length2 += diff_text.length();
2138 patch.diffs.add(new Diff(diff_type, diff_text));
2147 // Compute the head context for the next patch.
2148 precontext = diff_text2(patch.diffs);
2151 // Append the end context for this patch.
2158 patch.length1 += postcontext.length();
2159 patch.length2 += postcontext.length();
2160 if (!patch.diffs.isEmpty()
2161 && patch.diffs.getLast().operation == Operation.EQUAL) {
2162 patch.diffs.getLast().text += postcontext;
2164 patch.diffs.add(new Diff(Operation.EQUAL, postcontext));
2168 pointer.add(patch);
2178 * @param patches List of Patch objects.
2181 public String patch_toText(List<Patch> patches) {
2183 for (Patch aPatch : patches) {
2191 * Parse a textual representation of patches and return a List of Patch
2194 * @return List of Patch objects.
2197 public List<Patch> patch_fromText(String textline)
2199 List<Patch> patches = new LinkedList<Patch>();
2205 Patch patch;
2215 "Invalid patch string: " + text.getFirst());
2217 patch = new Patch();
2218 patches.add(patch);
2219 patch.start1 = Integer.parseInt(m.group(1));
2221 patch.start1--;
2222 patch.length1 = 1;
2224 patch.length1 = 0;
2226 patch.start1--;
2227 patch.length1 = Integer.parseInt(m.group(2));
2230 patch.start2 = Integer.parseInt(m.group(3));
2232 patch.start2--;
2233 patch.length2 = 1;
2235 patch.length2 = 0;
2237 patch.start2--;
2238 patch.length2 = Integer.parseInt(m.group(4));
2264 patch.diffs.add(new Diff(Operation.DELETE, line));
2267 patch.diffs.add(new Diff(Operation.INSERT, line));
2270 patch.diffs.add(new Diff(Operation.EQUAL, line));
2272 // Start of next patch.
2277 "Invalid patch mode '" + sign + "' in: " + line);
2338 * Class representing one patch operation.
2340 public static class Patch {
2351 public Patch() {
2381 // Escape the body of the patch with %xx notation.