Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/Patch.java @ 534:243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 04 Feb 2013 18:00:55 +0100 |
parents | e6f72c9829a6 |
children | 47dfa0ec7e35 |
comparison
equal
deleted
inserted
replaced
533:e6f72c9829a6 | 534:243202f1bda5 |
---|---|
152 da.readBytes(src, 0, len); | 152 da.readBytes(src, 0, len); |
153 starts.add(s); | 153 starts.add(s); |
154 ends.add(e); | 154 ends.add(e); |
155 data.add(src); | 155 data.add(src); |
156 } | 156 } |
157 | 157 |
158 /** | |
159 * @return how many bytes the patch would take if written down using BundleFormat structure (start, end, length, data) | |
160 */ | |
161 public int serializedLength() { | |
162 int totalDataLen = 0; | |
163 for (byte[] d : data) { | |
164 totalDataLen += d.length; | |
165 } | |
166 int prefix = 3 * 4 * count(); // 3 integer fields per entry * sizeof(int) * number of entries | |
167 return prefix + totalDataLen; | |
168 } | |
169 | |
170 /*package-local*/ void serialize(DataSerializer out) throws IOException { | |
171 for (int i = 0, x = data.size(); i < x; i++) { | |
172 final int start = starts.get(i); | |
173 final int end = ends.get(i); | |
174 byte[] d = data.get(i); | |
175 out.writeInt(start, end, d.length); | |
176 out.write(d, 0, d.length); | |
177 } | |
178 } | |
179 | |
158 private void add(Patch p, int i) { | 180 private void add(Patch p, int i) { |
159 add(p.starts.get(i), p.ends.get(i), p.data.get(i)); | 181 add(p.starts.get(i), p.ends.get(i), p.data.get(i)); |
160 } | 182 } |
161 | 183 |
162 /*package-local*/ void add(int start, int end, byte[] d) { | 184 /*package-local*/ void add(int start, int end, byte[] d) { |
361 r.add(this, p1); | 383 r.add(this, p1); |
362 p1++; | 384 p1++; |
363 }; | 385 }; |
364 return r; | 386 return r; |
365 } | 387 } |
388 | |
389 public class PatchDataSource implements DataSerializer.DataSource { | |
390 | |
391 public void serialize(DataSerializer out) throws IOException { | |
392 Patch.this.serialize(out); | |
393 } | |
394 | |
395 public int serializeLength() { | |
396 return Patch.this.serializedLength(); | |
397 } | |
398 } | |
366 } | 399 } |