Mercurial > jhg
annotate src/org/tmatesoft/hg/repo/RevlogStream.java @ 74:6f1b88693d48
Complete refactoring to org.tmatesoft
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Mon, 24 Jan 2011 03:14:45 +0100 | 
| parents | src/com/tmate/hgkit/ll/RevlogStream.java@30bd38978846 | 
| children | 
| rev | line source | 
|---|---|
| 10 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 1 /* | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 2 * Copyright (c) 2010-2011 TMate Software Ltd | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 3 * | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 4 * This program is free software; you can redistribute it and/or modify | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 5 * it under the terms of the GNU General Public License as published by | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 6 * the Free Software Foundation; version 2 of the License. | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 7 * | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 8 * This program is distributed in the hope that it will be useful, | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 11 * GNU General Public License for more details. | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 12 * | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 13 * For information on how to redistribute this software under | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 14 * the terms of a license other than GNU General Public License | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 15 * contact TMate Software at support@svnkit.com | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 16 */ | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 17 package org.tmatesoft.hg.repo; | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 18 | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 19 import static org.tmatesoft.hg.repo.HgRepository.TIP; | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 20 | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 21 import java.io.File; | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 22 import java.io.IOException; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 23 import java.util.ArrayList; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 24 import java.util.Collections; | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 25 import java.util.LinkedList; | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 26 import java.util.List; | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 27 import java.util.zip.DataFormatException; | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 28 import java.util.zip.Inflater; | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 29 | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 30 import org.tmatesoft.hg.core.Nodeid; | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 31 import org.tmatesoft.hg.internal.DataAccess; | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 32 import org.tmatesoft.hg.internal.DataAccessProvider; | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 33 | 
| 10 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 34 | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 35 /** | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 36 * XXX move to .internal? | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 37 * ? Single RevlogStream per file per repository with accessor to record access session (e.g. with back/forward operations), | 
| 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 38 * or numerous RevlogStream with separate representation of the underlaying data (cached, lazy ChunkStream)? | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 39 * | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 40 * @see http://mercurial.selenic.com/wiki/Revlog | 
| 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 41 * @see http://mercurial.selenic.com/wiki/RevlogNG | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 42 * | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 43 * @author Artem Tikhomirov | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
52diff
changeset | 44 * @author TMate Software Ltd. | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 45 */ | 
| 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 46 public class RevlogStream { | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 47 | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 48 private List<IndexEntry> index; // indexed access highly needed | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 49 private boolean inline = false; | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 50 private final File indexFile; | 
| 10 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 51 private final DataAccessProvider dataAccess; | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 52 | 
| 10 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 53 // if we need anything else from HgRepo, might replace DAP parameter with HgRepo and query it for DAP. | 
| 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 54 RevlogStream(DataAccessProvider dap, File indexFile) { | 
| 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 55 this.dataAccess = dap; | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 56 this.indexFile = indexFile; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 57 } | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 58 | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 59 /*package*/ DataAccess getIndexStream() { | 
| 10 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 60 return dataAccess.create(indexFile); | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 61 } | 
| 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 62 | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 63 /*package*/ DataAccess getDataStream() { | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 64 final String indexName = indexFile.getName(); | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 65 File dataFile = new File(indexFile.getParentFile(), indexName.substring(0, indexName.length() - 1) + "d"); | 
| 10 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 66 return dataAccess.create(dataFile); | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 67 } | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 68 | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 69 public int revisionCount() { | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 70 initOutline(); | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 71 return index.size(); | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 72 } | 
| 22 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 73 | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 74 public int dataLength(int revision) { | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 75 // XXX in fact, use of iterate() instead of this implementation may be quite reasonable. | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 76 // | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 77 final int indexSize = revisionCount(); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 78 DataAccess daIndex = getIndexStream(); // XXX may supply a hint that I'll need really few bytes of data (although at some offset) | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 79 if (revision == TIP) { | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 80 revision = indexSize - 1; | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 81 } | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 82 try { | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 83 int recordOffset = inline ? (int) index.get(revision).offset : revision * REVLOGV1_RECORD_SIZE; | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 84 daIndex.seek(recordOffset + 12); // 6+2+4 | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 85 int actualLen = daIndex.readInt(); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 86 return actualLen; | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 87 } catch (IOException ex) { | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 88 ex.printStackTrace(); // log error. FIXME better handling | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 89 throw new IllegalStateException(ex); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 90 } finally { | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 91 daIndex.done(); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 92 } | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 93 } | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 94 | 
| 49 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 95 // Perhaps, RevlogStream should be limited to use of plain int revisions for access, | 
| 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 96 // while Nodeids should be kept on the level up, in Revlog. Guess, Revlog better keep | 
| 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 97 // map of nodeids, and once this comes true, we may get rid of this method. | 
| 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 98 // Unlike its counterpart, Revlog#getLocalRevisionNumber, doesn't fail with exception if node not found, | 
| 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 99 // returns a predefined constant instead | 
| 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 100 /*package-local*/ int findLocalRevisionNumber(Nodeid nodeid) { | 
| 22 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 101 // XXX this one may be implemented with iterate() once there's mechanism to stop iterations | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 102 final int indexSize = revisionCount(); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 103 DataAccess daIndex = getIndexStream(); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 104 try { | 
| 24 
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
22diff
changeset | 105 byte[] nodeidBuf = new byte[20]; | 
| 22 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 106 for (int i = 0; i < indexSize; i++) { | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 107 daIndex.skip(8); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 108 int compressedLen = daIndex.readInt(); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 109 daIndex.skip(20); | 
| 24 
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
22diff
changeset | 110 daIndex.readBytes(nodeidBuf, 0, 20); | 
| 
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
22diff
changeset | 111 if (nodeid.equalsTo(nodeidBuf)) { | 
| 22 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 112 return i; | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 113 } | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 114 daIndex.skip(inline ? 12 + compressedLen : 12); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 115 } | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 116 } catch (IOException ex) { | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 117 ex.printStackTrace(); // log error. FIXME better handling | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 118 throw new IllegalStateException(ex); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 119 } finally { | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 120 daIndex.done(); | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 121 } | 
| 49 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 122 return Integer.MIN_VALUE; | 
| 22 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 123 } | 
| 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 124 | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 125 | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 126 private final int REVLOGV1_RECORD_SIZE = 64; | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 127 | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 128 // should be possible to use TIP, ALL, or -1, -2, -n notation of Hg | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 129 // ? boolean needsNodeid | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 130 public void iterate(int start, int end, boolean needData, Revlog.Inspector inspector) { | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 131 initOutline(); | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 132 final int indexSize = index.size(); | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 133 if (indexSize == 0) { | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 134 return; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 135 } | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 136 if (end == TIP) { | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 137 end = indexSize - 1; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 138 } | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 139 if (start == TIP) { | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 140 start = indexSize - 1; | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 141 } | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 142 if (start < 0 || start >= indexSize) { | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 143 throw new IllegalArgumentException("Bad left range boundary " + start); | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 144 } | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 145 if (end < start || end >= indexSize) { | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 146 throw new IllegalArgumentException("Bad right range boundary " + end); | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 147 } | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 148 // XXX may cache [start .. end] from index with a single read (pre-read) | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 149 | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 150 DataAccess daIndex = null, daData = null; | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 151 daIndex = getIndexStream(); | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 152 if (needData && !inline) { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 153 daData = getDataStream(); | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 154 } | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 155 try { | 
| 24 
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
22diff
changeset | 156 byte[] nodeidBuf = new byte[20]; | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 157 byte[] lastData = null; | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 158 int i; | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 159 boolean extraReadsToBaseRev = false; | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 160 if (needData && index.get(start).baseRevision < start) { | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 161 i = index.get(start).baseRevision; | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 162 extraReadsToBaseRev = true; | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 163 } else { | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 164 i = start; | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 165 } | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 166 | 
| 22 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 167 daIndex.seek(inline ? (int) index.get(i).offset : i * REVLOGV1_RECORD_SIZE); | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 168 for (; i <= end; i++ ) { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 169 long l = daIndex.readLong(); | 
| 49 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 170 @SuppressWarnings("unused") | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 171 long offset = l >>> 16; | 
| 49 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 172 @SuppressWarnings("unused") | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 173 int flags = (int) (l & 0X0FFFF); | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 174 int compressedLen = daIndex.readInt(); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 175 int actualLen = daIndex.readInt(); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 176 int baseRevision = daIndex.readInt(); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 177 int linkRevision = daIndex.readInt(); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 178 int parent1Revision = daIndex.readInt(); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 179 int parent2Revision = daIndex.readInt(); | 
| 24 
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
22diff
changeset | 180 // Hg has 32 bytes here, uses 20 for nodeid, and keeps 12 last bytes empty | 
| 
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
22diff
changeset | 181 daIndex.readBytes(nodeidBuf, 0, 20); | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 182 daIndex.skip(12); | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 183 byte[] data = null; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 184 if (needData) { | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 185 byte[] dataBuf = new byte[compressedLen]; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 186 if (inline) { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 187 daIndex.readBytes(dataBuf, 0, compressedLen); | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 188 } else { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 189 daData.seek(index.get(i).offset); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 190 daData.readBytes(dataBuf, 0, compressedLen); | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 191 } | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 192 if (dataBuf[0] == 0x78 /* 'x' */) { | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 193 try { | 
| 33 
565ce0835674
TODO added, to try stream for unzip in revlog
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
24diff
changeset | 194 Inflater zlib = new Inflater(); // XXX Consider reuse of Inflater, and/or stream alternative | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 195 zlib.setInput(dataBuf, 0, compressedLen); | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 196 byte[] result = new byte[actualLen*2]; // FIXME need to use zlib.finished() instead | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 197 int resultLen = zlib.inflate(result); | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 198 zlib.end(); | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 199 data = new byte[resultLen]; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 200 System.arraycopy(result, 0, data, 0, resultLen); | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 201 } catch (DataFormatException ex) { | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 202 ex.printStackTrace(); | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 203 data = new byte[0]; // FIXME need better failure strategy | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 204 } | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 205 } else if (dataBuf[0] == 0x75 /* 'u' */) { | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 206 data = new byte[dataBuf.length - 1]; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 207 System.arraycopy(dataBuf, 1, data, 0, data.length); | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 208 } else { | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 209 // XXX Python impl in fact throws exception when there's not 'x', 'u' or '0' | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 210 // but I don't see reason not to return data as is | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 211 data = dataBuf; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 212 } | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 213 // XXX | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 214 if (baseRevision != i) { // XXX not sure if this is the right way to detect a patch | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 215 // this is a patch | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 216 LinkedList<PatchRecord> patches = new LinkedList<PatchRecord>(); | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 217 int patchElementIndex = 0; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 218 do { | 
| 36 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 219 PatchRecord pr = PatchRecord.read(data, patchElementIndex); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 220 patches.add(pr); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 221 patchElementIndex += 12 + pr.len; | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 222 } while (patchElementIndex < data.length); | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 223 // | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 224 byte[] baseRevContent = lastData; | 
| 6 
5abe5af181bd
Ant script to build commands and run sample
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
5diff
changeset | 225 data = apply(baseRevContent, actualLen, patches); | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 226 } | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 227 } else { | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 228 if (inline) { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 229 daIndex.skip(compressedLen); | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 230 } | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 231 } | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 232 if (!extraReadsToBaseRev || i >= start) { | 
| 24 
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
22diff
changeset | 233 inspector.next(i, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, nodeidBuf, data); | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 234 } | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 235 lastData = data; | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 236 } | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 237 } catch (IOException ex) { | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 238 throw new IllegalStateException(ex); // FIXME need better handling | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 239 } finally { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 240 daIndex.done(); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 241 if (daData != null) { | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 242 daData.done(); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 243 } | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 244 } | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 245 } | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 246 | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 247 private void initOutline() { | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 248 if (index != null && !index.isEmpty()) { | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 249 return; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 250 } | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 251 ArrayList<IndexEntry> res = new ArrayList<IndexEntry>(); | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 252 DataAccess da = getIndexStream(); | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 253 try { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 254 int versionField = da.readInt(); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 255 da.readInt(); // just to skip next 2 bytes of offset + flags | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 256 final int INLINEDATA = 1 << 16; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 257 inline = (versionField & INLINEDATA) != 0; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 258 long offset = 0; // first offset is always 0, thus Hg uses it for other purposes | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 259 while(true) { | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 260 int compressedLen = da.readInt(); | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 261 // 8+4 = 12 bytes total read here | 
| 49 
26e3eeaa3962
branch and user filtering for log operation
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
44diff
changeset | 262 @SuppressWarnings("unused") | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 263 int actualLen = da.readInt(); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 264 int baseRevision = da.readInt(); | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 265 // 12 + 8 = 20 bytes read here | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 266 // int linkRevision = di.readInt(); | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 267 // int parent1Revision = di.readInt(); | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 268 // int parent2Revision = di.readInt(); | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 269 // byte[] nodeid = new byte[32]; | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 270 if (inline) { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 271 res.add(new IndexEntry(offset + REVLOGV1_RECORD_SIZE * res.size(), baseRevision)); | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 272 da.skip(3*4 + 32 + compressedLen); // Check: 44 (skip) + 20 (read) = 64 (total RevlogNG record size) | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 273 } else { | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 274 res.add(new IndexEntry(offset, baseRevision)); | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 275 da.skip(3*4 + 32); | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 276 } | 
| 10 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 277 if (da.isEmpty()) { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 278 // fine, done then | 
| 22 
603806cd2dc6
Status of local working dir against non-tip base revision
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
10diff
changeset | 279 res.trimToSize(); | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 280 index = res; | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 281 break; | 
| 10 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 282 } else { | 
| 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 283 // start reading next record | 
| 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 284 long l = da.readLong(); | 
| 
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
9diff
changeset | 285 offset = l >>> 16; | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 286 } | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 287 } | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 288 } catch (IOException ex) { | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 289 ex.printStackTrace(); // log error | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 290 // too bad, no outline then. | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 291 index = Collections.emptyList(); | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 292 } finally { | 
| 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 293 da.done(); | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 294 } | 
| 9 
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
6diff
changeset | 295 | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 296 } | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 297 | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 298 | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 299 // perhaps, package-local or protected, if anyone else from low-level needs them | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 300 // XXX think over if we should keep offset in case of separate data file - we read the field anyway. Perhaps, distinct entry classes for Inline and non-inline indexes? | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 301 private static class IndexEntry { | 
| 4 
aa1912c70b36
Fix offset issue for inline revlogs. Commandline processing.
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
3diff
changeset | 302 public final long offset; // for separate .i and .d - copy of index record entry, for inline index - actual offset of the record in the .i file (record entry + revision * record size)) | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 303 //public final int length; // data past fixed record (need to decide whether including header size or not), and whether length is of compressed data or not | 
| 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 304 public final int baseRevision; | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 305 | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 306 public IndexEntry(long o, int baseRev) { | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 307 offset = o; | 
| 5 
fc265ddeab26
File content and non-effective, although working, patch application
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
4diff
changeset | 308 baseRevision = baseRev; | 
| 2 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 309 } | 
| 
08db726a0fb7
Shaping out low-level Hg structures
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
0diff
changeset | 310 } | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 311 | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 312 // mpatch.c : apply() | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 313 // FIXME need to implement patch merge (fold, combine, gather and discard from aforementioned mpatch.[c|py]), also see Revlog and Mercurial PDF | 
| 37 
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
36diff
changeset | 314 /*package-local for HgBundle; until moved to better place*/static byte[] apply(byte[] baseRevisionContent, int outcomeLen, List<PatchRecord> patch) { | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 315 int last = 0, destIndex = 0; | 
| 43 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 316 if (outcomeLen == -1) { | 
| 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 317 outcomeLen = baseRevisionContent.length; | 
| 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 318 for (PatchRecord pr : patch) { | 
| 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 319 outcomeLen += pr.start - last + pr.len; | 
| 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 320 last = pr.end; | 
| 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 321 } | 
| 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 322 outcomeLen -= last; | 
| 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 323 last = 0; | 
| 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 324 } | 
| 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 325 byte[] rv = new byte[outcomeLen]; | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 326 for (PatchRecord pr : patch) { | 
| 43 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 327 System.arraycopy(baseRevisionContent, last, rv, destIndex, pr.start-last); | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 328 destIndex += pr.start - last; | 
| 43 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 329 System.arraycopy(pr.data, 0, rv, destIndex, pr.data.length); | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 330 destIndex += pr.data.length; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 331 last = pr.end; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 332 } | 
| 43 
1b26247d7367
Calculate result length of the patch operarion, when unknown
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
37diff
changeset | 333 System.arraycopy(baseRevisionContent, last, rv, destIndex, baseRevisionContent.length - last); | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 334 return rv; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 335 } | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 336 | 
| 35 
6061aa826a9e
Complete parsing of the bundle format
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
33diff
changeset | 337 // @see http://mercurial.selenic.com/wiki/BundleFormat, in Changelog group description | 
| 36 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 338 /*package-local*/ static class PatchRecord { // copy of struct frag from mpatch.c | 
| 52 
30bd38978846
brief explanation of patch record
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
49diff
changeset | 339 /* | 
| 
30bd38978846
brief explanation of patch record
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
49diff
changeset | 340 Given there are pr1 and pr2: | 
| 
30bd38978846
brief explanation of patch record
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
49diff
changeset | 341 pr1.start to pr1.end will be replaced with pr's data (of pr1.len) | 
| 
30bd38978846
brief explanation of patch record
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
49diff
changeset | 342 pr1.end to pr2.start gets copied from base | 
| 
30bd38978846
brief explanation of patch record
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
49diff
changeset | 343 */ | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 344 int start, end, len; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 345 byte[] data; | 
| 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 346 | 
| 36 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 347 // TODO consider PatchRecord that only records data position (absolute in data source), and acquires data as needed | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 348 private PatchRecord(int p1, int p2, int length, byte[] src) { | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 349 start = p1; | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 350 end = p2; | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 351 len = length; | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 352 data = src; | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 353 } | 
| 36 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 354 | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 355 /*package-local*/ static PatchRecord read(byte[] data, int offset) { | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 356 final int x = offset; // shorthand | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 357 int p1 = ((data[x] & 0xFF)<< 24) | ((data[x+1] & 0xFF) << 16) | ((data[x+2] & 0xFF) << 8) | (data[x+3] & 0xFF); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 358 int p2 = ((data[x+4] & 0xFF) << 24) | ((data[x+5] & 0xFF) << 16) | ((data[x+6] & 0xFF) << 8) | (data[x+7] & 0xFF); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 359 int len = ((data[x+8] & 0xFF) << 24) | ((data[x+9] & 0xFF) << 16) | ((data[x+10] & 0xFF) << 8) | (data[x+11] & 0xFF); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 360 byte[] dataCopy = new byte[len]; | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 361 System.arraycopy(data, x+12, dataCopy, 0, len); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 362 return new PatchRecord(p1, p2, len, dataCopy); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 363 } | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 364 | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 365 /*package-local*/ static PatchRecord read(DataAccess da) throws IOException { | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 366 int p1 = da.readInt(); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 367 int p2 = da.readInt(); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 368 int len = da.readInt(); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 369 byte[] src = new byte[len]; | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 370 da.readBytes(src, 0, len); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 371 return new PatchRecord(p1, p2, len, src); | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 372 } | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 373 | 
| 
205f9b59b400
Strip parsing logic out from console frontend
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
35diff
changeset | 374 | 
| 3 
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
2diff
changeset | 375 } | 
| 0 
dbd663faec1f
Basic changelog parsing
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 376 } | 
