Mercurial > hg4j
comparison src/com/tmate/hgkit/ll/Revlog.java @ 51:9429c7bd1920 wrap-data-access
Try DataAccess to reach revision data instead of plain byte arrays
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 16 Jan 2011 01:20:26 +0100 |
parents | 26e3eeaa3962 |
children |
comparison
equal
deleted
inserted
replaced
50:f1db8610da62 | 51:9429c7bd1920 |
---|---|
7 import java.util.Collections; | 7 import java.util.Collections; |
8 import java.util.HashMap; | 8 import java.util.HashMap; |
9 import java.util.LinkedHashSet; | 9 import java.util.LinkedHashSet; |
10 import java.util.Map; | 10 import java.util.Map; |
11 import java.util.Set; | 11 import java.util.Set; |
12 | |
13 import com.tmate.hgkit.fs.DataAccess; | |
12 | 14 |
13 /** | 15 /** |
14 * | 16 * |
15 * @author artem | 17 * @author artem |
16 */ | 18 */ |
68 * @param revision - repo-local index of this file change (not a changelog revision number!) | 70 * @param revision - repo-local index of this file change (not a changelog revision number!) |
69 */ | 71 */ |
70 public byte[] content(int revision) { | 72 public byte[] content(int revision) { |
71 final byte[][] dataPtr = new byte[1][]; | 73 final byte[][] dataPtr = new byte[1][]; |
72 Revlog.Inspector insp = new Revlog.Inspector() { | 74 Revlog.Inspector insp = new Revlog.Inspector() { |
73 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | 75 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
74 dataPtr[0] = data; | 76 dataPtr[0] = data.byteArray(); |
75 } | 77 } |
76 }; | 78 }; |
77 content.iterate(revision, revision, true, insp); | 79 content.iterate(revision, revision, true, insp); |
78 return dataPtr[0]; | 80 return dataPtr[0]; |
79 } | 81 } |
82 // instantly - e.g. calculate hash, or comparing two revisions | 84 // instantly - e.g. calculate hash, or comparing two revisions |
83 // XXX seems that RevlogStream is better place for this class. | 85 // XXX seems that RevlogStream is better place for this class. |
84 public interface Inspector { | 86 public interface Inspector { |
85 // XXX boolean retVal to indicate whether to continue? | 87 // XXX boolean retVal to indicate whether to continue? |
86 // TODO specify nodeid and data length, and reuse policy (i.e. if revlog stream doesn't reuse nodeid[] for each call) | 88 // TODO specify nodeid and data length, and reuse policy (i.e. if revlog stream doesn't reuse nodeid[] for each call) |
87 void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[/*20*/] nodeid, byte[] data); | 89 void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[/*20*/] nodeid, DataAccess data); |
88 } | 90 } |
89 | 91 |
90 /* | 92 /* |
91 * XXX think over if it's better to do either: | 93 * XXX think over if it's better to do either: |
92 * pw = getChangelog().new ParentWalker(); pw.init() and pass pw instance around as needed | 94 * pw = getChangelog().new ParentWalker(); pw.init() and pass pw instance around as needed |
113 allNodes = new LinkedHashSet<Nodeid>(); | 115 allNodes = new LinkedHashSet<Nodeid>(); |
114 | 116 |
115 Inspector insp = new Inspector() { | 117 Inspector insp = new Inspector() { |
116 final Nodeid[] sequentialRevisionNodeids = new Nodeid[revisionCount]; | 118 final Nodeid[] sequentialRevisionNodeids = new Nodeid[revisionCount]; |
117 int ix = 0; | 119 int ix = 0; |
118 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | 120 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
119 if (ix != revisionNumber) { | 121 if (ix != revisionNumber) { |
120 // XXX temp code, just to make sure I understand what's going on here | 122 // XXX temp code, just to make sure I understand what's going on here |
121 throw new IllegalStateException(); | 123 throw new IllegalStateException(); |
122 } | 124 } |
123 if (parent1Revision >= revisionNumber || parent2Revision >= revisionNumber) { | 125 if (parent1Revision >= revisionNumber || parent2Revision >= revisionNumber) { |