annotate src/org/tmatesoft/hg/internal/Patch.java @ 552:45751456b471

Annotate file changes through few revisions, walking either direction (old to new and vice versa)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 20 Feb 2013 22:23:50 +0100
parents 243202f1bda5
children 47dfa0ec7e35
rev   line source
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
533
e6f72c9829a6 Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 532
diff changeset
2 * Copyright (c) 2011-2013 TMate Software Ltd
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.io.IOException;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.util.ArrayList;
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
21 import java.util.Formatter;
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 /**
419
7f136a3fa671 Clean javadoc to fix obvious warnings
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 330
diff changeset
24 * @see http://mercurial.selenic.com/wiki/BundleFormat
7f136a3fa671 Clean javadoc to fix obvious warnings
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 330
diff changeset
25 * in Changelog group description
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 *
533
e6f72c9829a6 Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 532
diff changeset
27 * range [start..end) in original source gets replaced with data of length (do not keep, use data.length instead)
e6f72c9829a6 Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 532
diff changeset
28 * range [end(i)..start(i+1)) is copied from the source
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 *
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 * @author Artem Tikhomirov
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 * @author TMate Software Ltd.
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 */
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 public final class Patch {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 private final IntVector starts, ends;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 private final ArrayList<byte[]> data;
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
36
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
37 private static byte[] generate(int c) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
38 byte[] rv = new byte[c];
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
39 for (int i = 0; i < c; i++) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
40 byte x = (byte) ('a' + i);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
41 rv[i] = x;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
42 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
43 return rv;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
44 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
45
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
46 public static void main(String[] args) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
47 Patch p1 = new Patch(), p2 = new Patch();
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
48 // simple cases (one element in either patch)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
49 // III: (1,10 20) & (5,15,15) p2End from [p1End..p1AppliedEnd] (i.e. within p1 range but index is past p2 end index)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
50 // II: (1,10,7) & (3,15,15) insideP2 = true and no more p1 entries
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
51 // II: (1,1,10) & (3,11,15)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
52 // independent: (1,10,10) & (15,25,10); (15, 25, 10) & (1, 10, 10)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
53 // I: (15, 25, 10) & (10, 20, 10). result: [10, 20, 10] [20, 25, 5]
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
54 // IV: (15, 25, 10) & (10, 30, 20)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
55 //
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
56 // cycle with insideP2
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
57 //
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
58 // cycle with insideP1
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
59 //
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
60 // multiple elements in patches (offsets)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
61 p1.add(15, 25, generate(10));
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
62 p2.add(10, 30, generate(20));
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
63 System.out.println("p1: " + p1);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
64 System.out.println("p2: " + p2);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
65 Patch r = p1.apply(p2);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
66 System.out.println("r: " + r);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
67 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
68
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 public Patch() {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 starts = new IntVector();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 ends = new IntVector();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 data = new ArrayList<byte[]>();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
75 public String toString() {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
76 StringBuilder sb = new StringBuilder();
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
77 Formatter f = new Formatter(sb);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
78 for (int i = 0; i < count(); i++) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
79 f.format("[%d, %d, %d] ", starts.get(i), ends.get(i), data.get(i).length);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
80 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
81 return sb.toString();
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
82 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
83
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 public int count() {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 return data.size();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 // number of bytes this patch will add (or remove, if negative) from the base revision
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 private int patchSizeDelta() {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 int rv = 0;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 int prevEnd = 0;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 for (int i = 0, x = data.size(); i < x; i++) {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 final int start = starts.get(i);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 final int len = data.get(i).length;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 rv += start - prevEnd; // would copy from original
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 rv += len; // and add new
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 prevEnd = ends.get(i);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 rv -= prevEnd;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 return rv;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 public byte[] apply(DataAccess baseRevisionContent, int outcomeLen) throws IOException {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 if (outcomeLen == -1) {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 outcomeLen = baseRevisionContent.length() + patchSizeDelta();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 int prevEnd = 0, destIndex = 0;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 byte[] rv = new byte[outcomeLen];
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 for (int i = 0, x = data.size(); i < x; i++) {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 final int start = starts.get(i);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 baseRevisionContent.seek(prevEnd);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 // copy source bytes that were not modified (up to start of the record)
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 baseRevisionContent.readBytes(rv, destIndex, start - prevEnd);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 destIndex += start - prevEnd;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 // insert new data from the patch, if any
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 byte[] d = data.get(i);
532
688c1ab113bb Introduce explicit reference to base patch in bundle's group element, use it when cloning to fix defect when few revisions list null,null parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 530
diff changeset
117 System.arraycopy(d, 0, rv, destIndex, d.length);
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 destIndex += d.length;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 prevEnd = ends.get(i);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 baseRevisionContent.seek(prevEnd);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 // copy everything in the source past last record's end
420
6c22bdc0bdfd Respect long offsets in revlogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 419
diff changeset
123 baseRevisionContent.readBytes(rv, destIndex, (baseRevisionContent.length() - prevEnd));
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 return rv;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 public void clear() {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 starts.clear();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 ends.clear();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 data.clear();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 /**
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 * Initialize instance from stream. Any previous patch information (i.e. if instance if reused) is cleared first.
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 * Read up to the end of DataAccess and interpret data as patch records.
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 */
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 public void read(DataAccess da) throws IOException {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 clear();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 while (!da.isEmpty()) {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 readOne(da);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 /**
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 * Caller is responsible to ensure stream got some data to read
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 */
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 public void readOne(DataAccess da) throws IOException {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 int s = da.readInt();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 int e = da.readInt();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 int len = da.readInt();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 byte[] src = new byte[len];
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 da.readBytes(src, 0, len);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 starts.add(s);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 ends.add(e);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 data.add(src);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 }
534
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
157
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
158 /**
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
159 * @return how many bytes the patch would take if written down using BundleFormat structure (start, end, length, data)
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
160 */
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
161 public int serializedLength() {
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
162 int totalDataLen = 0;
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
163 for (byte[] d : data) {
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
164 totalDataLen += d.length;
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
165 }
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
166 int prefix = 3 * 4 * count(); // 3 integer fields per entry * sizeof(int) * number of entries
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
167 return prefix + totalDataLen;
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
168 }
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
169
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
170 /*package-local*/ void serialize(DataSerializer out) throws IOException {
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
171 for (int i = 0, x = data.size(); i < x; i++) {
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
172 final int start = starts.get(i);
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
173 final int end = ends.get(i);
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
174 byte[] d = data.get(i);
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
175 out.writeInt(start, end, d.length);
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
176 out.write(d, 0, d.length);
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
177 }
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
178 }
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
179
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
180 private void add(Patch p, int i) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
181 add(p.starts.get(i), p.ends.get(i), p.data.get(i));
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
182 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
183
533
e6f72c9829a6 Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 532
diff changeset
184 /*package-local*/ void add(int start, int end, byte[] d) {
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
185 starts.add(start);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
186 ends.add(end);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
187 data.add(d);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
188 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
189
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
190 private static byte[] subarray(byte[] d, int start, int end) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
191 byte[] r = new byte[end-start+1];
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
192 System.arraycopy(d, start, r, 0, r.length);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
193 return r;
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 /**
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 * Modify this patch with subsequent patch
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
198 */
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
199 private /*SHALL BE PUBLIC ONCE TESTING ENDS*/ Patch apply(Patch another) {
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 Patch r = new Patch();
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
201 int p1TotalAppliedDelta = 0; // value to add to start and end indexes of the older patch to get their values as if
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
202 // in the patched text, iow, directly comparable with respective indexes from the newer patch.
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
203 int p1EntryStart = 0, p1EntryEnd = 0, p1EntryLen = 0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
204 byte[] p1Data = null;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
205 boolean insideP1entry = false;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
206 int p2 = 0, p1 = 0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
207 final int p2Max = another.count(), p1Max = this.count();
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
208 L0: for (; p2 < p2Max; p2++) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
209 int p2EntryStart = another.starts.get(p2);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
210 int p2EntryEnd = another.ends.get(p2);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
211 final int p2EntryRange = p2EntryEnd - p2EntryStart;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
212 final byte[] p2Data = another.data.get(p2);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
213 boolean insideP2entry = false;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
214 int p2EntryStartOffset = -1;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
215 ///
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
216 p1EntryStart = p1EntryEnd = p1EntryLen = 0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
217 p1Data = null;
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
219 L1: while (p1 < p1Max) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
220 if (!insideP1entry) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
221 p1EntryStart = starts.get(p1);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
222 p1EntryEnd = ends.get(p1);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
223 p1Data = data.get(p1);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
224 p1EntryLen = p1Data.length;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
225 }// else keep values
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
226
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
227 final int p1EntryDelta = p1EntryLen - (p1EntryEnd - p1EntryStart); // number of actually inserted(+) or deleted(-) chars
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
228 final int p1EntryAppliedStart = p1TotalAppliedDelta + p1EntryStart;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
229 final int p1EntryAppliedEnd = p1EntryAppliedStart + p1EntryLen; // end of j'th patch entry in the text which is source for p2
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
230
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
231 if (insideP2entry) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
232 if (p2EntryEnd < p1EntryAppliedStart) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
233 r.add(p2EntryStart - p2EntryStartOffset, p2EntryEnd - p1TotalAppliedDelta, p2Data);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
234 insideP2entry = false;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
235 continue L0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
236 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
237 if (p2EntryEnd >= p1EntryAppliedEnd) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
238 // when p2EntryEnd == p1EntryAppliedEnd, I assume p1TotalAppliedDelta can't be used for p2EntryEnd to get it to p1 range, but rather shall be
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
239 // augmented with current p1 entry and at the next p1 entry (likely to hit p1EntryAppliedStart > p2EntryEnd above) would do the rest
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
240 insideP1entry = false;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
241 p1++;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
242 p1TotalAppliedDelta += p1EntryDelta;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
243 continue L1;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
244 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
245 // p1EntryAppliedStart <= p2EntryEnd < p1EntryAppliedEnd
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
246 r.add(p2EntryStart - p2EntryStartOffset, p2EntryEnd - p1TotalAppliedDelta, p2Data);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
247 p1EntryStart = p2EntryEnd - p1TotalAppliedDelta;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
248 final int p1DataPartShift = p2EntryEnd - p1EntryAppliedStart + 1;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
249 if (p1DataPartShift >= p1EntryLen) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
250 p1EntryLen = 0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
251 p1Data = new byte[0];
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
252 } else {
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
253 p1EntryLen -= p1DataPartShift;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
254 p1Data = subarray(p1Data, p1DataPartShift, p1Data.length);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
255 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
256 insideP1entry = true;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
257 insideP2entry = false;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
258 continue L0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
259 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
260
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
261 if (p1EntryAppliedStart < p2EntryStart) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
262 if (p1EntryAppliedEnd <= p2EntryStart) { // p1EntryAppliedEnd in fact index of the first char *after* patch
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
263 // completely independent, copy and continue
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
264 r.add(p1EntryStart, p1EntryEnd, p1Data);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
265 insideP1entry = false;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
266 p1++;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
267 // fall-through to get p1TotalAppliedDelta incremented
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
268 } else { // SKETCH: II or III
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
269 // remember, p1EntryDelta may be negative
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
270 // shall break j'th entry into few
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
271 // fix p1's end/length
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
272 // p1EntryAppliedStart < p2EntryStart < p1EntryAppliedEnd
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
273 int s = p2EntryStart - p1TotalAppliedDelta; // p2EntryStart in p1 scale. Is within p1 range
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
274 if (s > p1EntryEnd) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
275 s = p1EntryEnd;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
276 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
277 int p1DataPartEnd = p2EntryStart - p1EntryAppliedStart; // index, not count. <= (p1EntryEnd-p1EntryStart).
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
278 // add what left from p1
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
279 if (p1DataPartEnd < p1EntryLen) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
280 r.add(p1EntryStart, s, subarray(p1Data, 0, p1DataPartEnd));
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
281 } else {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
282 p1DataPartEnd = p1EntryLen-1; // record factual number of p1 bytes we consumed.
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
283 r.add(p1EntryStart, s, p1Data);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
284 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
285 p1TotalAppliedDelta += p1DataPartEnd - (s - p1EntryStart); // (s2 - (s1+delta)) - (s2 - delta - s1) = s2-s1-delta-s2+delta+s1 = 0, unless p1DataPartEnd >= p1Data.length
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
286 p1EntryLen -= (p1DataPartEnd+1);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
287 if (p2EntryEnd < p1EntryAppliedEnd) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
288 // SKETCH: III
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
289 insideP1entry = true;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
290 // p2 completely fits into changes of p1
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
291 int e = p2EntryEnd - p1TotalAppliedDelta; // p2EntryEnd in p1 scale
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
292 if (e > p1EntryEnd) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
293 // any index past p1 end shall be calculated with respect to p1 end, thus it's unsafe to go past p1 end (there may be more p1 entries there)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
294 e = p1EntryEnd;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
295 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
296 r.add(s, e, p2Data); // add p2
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
297 // modify p1 leftover
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
298 p1EntryStart = e;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
299 if (p2EntryRange >= p1EntryLen) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
300 p1EntryLen = 0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
301 p1Data = new byte[0];
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
302 } else {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
303 p1Data = subarray(p1Data, p1DataPartEnd + p2EntryRange, p1Data.length-1 /*up to the last one*/);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
304 p1EntryLen -= p2EntryRange;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
305 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
306 // p2 is handled, but there are leftovers of p1
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
307 continue L0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
308 } else { // p2EntryEnd >= p1EntryAppliedEnd
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
309 // SKETCH: II
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
310 insideP1entry = false;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
311 p1++;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
312 if (p1EntryAppliedStart + p1EntryDelta >= p2EntryEnd) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
313 // here we know next p1 entry would be past p2 entry and thus can put p2 right away
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
314 r.add(p2EntryStart - p1TotalAppliedDelta, p1EntryEnd, p2Data);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
315 p1TotalAppliedDelta += p1EntryDelta;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
316 continue L0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
317 } else {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
318 // there are chances there are more p1 entries till p2 ends
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
319 insideP2entry = true;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
320 p2EntryStartOffset = p1TotalAppliedDelta;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
321 // p2EntryEnd is past delta, no chances for p1Data leftovers to be in use
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
322 // p2 processing is not over, need to fix end, depending on what else fits into p2 range (if nothing, can put p2.end right away)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
323 // fall-through to get p1TotalAppliedDelta incremented;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
324 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
325 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
326 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
327 } else { // p1EntryAppliedStart >= p2EntryStart
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
328 if (p2EntryEnd < p1EntryAppliedStart) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
329 // newer patch completely fits between two older patches
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
330 r.add(p2EntryStart - p1TotalAppliedDelta, p2EntryEnd - p1TotalAppliedDelta, p2Data);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
331 // SHALL NOT increment p1TotalAppliedDelta as we didn't use any of p1
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
332 continue L0; // next p2
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
333 } else { // p2EntryEnd >= p1EntryAppliedStart
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
334 // SKETCH: I or IV
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
335 // p2EntryEnd is either < p1EntryAppliedEnd or past it
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
336 if (p2EntryEnd <= p1EntryAppliedEnd) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
337 // SKETCH: I: copy p2, strip p1 to start from p2EntryEnd, next i (p2)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
338 insideP1entry = true;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
339 int e = p2EntryEnd - p1TotalAppliedDelta;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
340 if (e > p1EntryEnd) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
341 e = p1EntryEnd; // added by analogy with above. Is needed?
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
342 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
343 r.add(p2EntryStart - p1TotalAppliedDelta, e, p2Data);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
344 p1EntryStart = e;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
345 int p1DataShift = p2EntryEnd - p1EntryAppliedStart;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
346 if (p1DataShift >= p1EntryLen) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
347 p1EntryLen = 0;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
348 p1Data = new byte[0];
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
349 } else {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
350 p1EntryLen -= p1DataShift;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
351 p1Data = subarray(p1Data, p1DataShift, p1Data.length - 1);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
352 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
353 // p1TotalAppliedDelta would get incremented once this modified p1 is handled
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
354 continue L0; // next p2;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
355 } else {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
356 // p2EntryEnd > p1EntryAppliedEnd
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
357 // SKETCH IV: skip (rest of) p1 completely, continue the same unless found p1 with start or end past p2EntryEnd.
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
358 insideP1entry = false;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
359 p1++;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
360 insideP2entry = true;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
361 p2EntryStartOffset = p1TotalAppliedDelta;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
362 // fall-through to get p1TotalAppliedDelta incremented
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
363 }
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
364 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
365 }
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
366 p1TotalAppliedDelta += p1EntryDelta;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
367 } // while (p1 < p1Max)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
368 {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
369 // no more p1 entries, shall close p2 (if it's handled, code above jumps directly to L0)
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
370 // regardless of whether insideP2 is .t
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
371 int s = p2EntryStart;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
372 // p2EntryStartOffset != -1 when we started p2 entry processing, but not completed
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
373 // if we handled last p1 entry but didn't start with p2 entry processing, it's -1 and regular p1 delta shall be used
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
374 s -= p2EntryStartOffset == -1 ? p1TotalAppliedDelta : p2EntryStartOffset;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
375 r.add(s, p2EntryEnd - p1TotalAppliedDelta, p2Data);
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
376 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
377 }
330
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
378 if (p1 < p1Max && insideP1entry) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
379 r.add(p1EntryStart, p1EntryEnd, p1Data);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
380 p1++;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
381 }
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
382 while (p1 < p1Max) {
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
383 r.add(this, p1);
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
384 p1++;
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
385 };
9747a786a34d Patch merging algorithm complete trial
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 329
diff changeset
386 return r;
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
387 }
534
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
388
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
389 public class PatchDataSource implements DataSerializer.DataSource {
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
390
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
391 public void serialize(DataSerializer out) throws IOException {
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
392 Patch.this.serialize(out);
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
393 }
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
394
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
395 public int serializeLength() {
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
396 return Patch.this.serializedLength();
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
397 }
243202f1bda5 Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 533
diff changeset
398 }
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
399 }