Mercurial > jhg
comparison src/com/tmate/hgkit/ll/RevlogStream.java @ 43:1b26247d7367
Calculate result length of the patch operarion, when unknown
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 14 Jan 2011 04:41:05 +0100 |
parents | e45e75e22523 |
children | b79cf0118dd3 |
comparison
equal
deleted
inserted
replaced
42:92c3d0920d58 | 43:1b26247d7367 |
---|---|
284 | 284 |
285 // mpatch.c : apply() | 285 // mpatch.c : apply() |
286 // FIXME need to implement patch merge (fold, combine, gather and discard from aforementioned mpatch.[c|py]), also see Revlog and Mercurial PDF | 286 // FIXME need to implement patch merge (fold, combine, gather and discard from aforementioned mpatch.[c|py]), also see Revlog and Mercurial PDF |
287 // FIXME why 2 arrays (rv and tempBuf)???. Think over in-place merging (perhaps some sparse byte chunk list?) - to minimize mem use. | 287 // FIXME why 2 arrays (rv and tempBuf)???. Think over in-place merging (perhaps some sparse byte chunk list?) - to minimize mem use. |
288 /*package-local for HgBundle; until moved to better place*/static byte[] apply(byte[] baseRevisionContent, int outcomeLen, List<PatchRecord> patch) { | 288 /*package-local for HgBundle; until moved to better place*/static byte[] apply(byte[] baseRevisionContent, int outcomeLen, List<PatchRecord> patch) { |
289 byte[] tempBuf = new byte[outcomeLen]; // XXX | |
290 int last = 0, destIndex = 0; | 289 int last = 0, destIndex = 0; |
290 if (outcomeLen == -1) { | |
291 outcomeLen = baseRevisionContent.length; | |
292 for (PatchRecord pr : patch) { | |
293 outcomeLen += pr.start - last + pr.len; | |
294 last = pr.end; | |
295 } | |
296 outcomeLen -= last; | |
297 last = 0; | |
298 } | |
299 byte[] rv = new byte[outcomeLen]; | |
291 for (PatchRecord pr : patch) { | 300 for (PatchRecord pr : patch) { |
292 System.arraycopy(baseRevisionContent, last, tempBuf, destIndex, pr.start-last); | 301 System.arraycopy(baseRevisionContent, last, rv, destIndex, pr.start-last); |
293 destIndex += pr.start - last; | 302 destIndex += pr.start - last; |
294 System.arraycopy(pr.data, 0, tempBuf, destIndex, pr.data.length); | 303 System.arraycopy(pr.data, 0, rv, destIndex, pr.data.length); |
295 destIndex += pr.data.length; | 304 destIndex += pr.data.length; |
296 last = pr.end; | 305 last = pr.end; |
297 } | 306 } |
298 System.arraycopy(baseRevisionContent, last, tempBuf, destIndex, baseRevisionContent.length - last); | 307 System.arraycopy(baseRevisionContent, last, rv, destIndex, baseRevisionContent.length - last); |
299 destIndex += baseRevisionContent.length - last; // total length | |
300 byte[] rv = new byte[destIndex]; | |
301 System.arraycopy(tempBuf, 0, rv, 0, destIndex); | |
302 return rv; | 308 return rv; |
303 } | 309 } |
304 | 310 |
305 // @see http://mercurial.selenic.com/wiki/BundleFormat, in Changelog group description | 311 // @see http://mercurial.selenic.com/wiki/BundleFormat, in Changelog group description |
306 /*package-local*/ static class PatchRecord { // copy of struct frag from mpatch.c | 312 /*package-local*/ static class PatchRecord { // copy of struct frag from mpatch.c |