Ensure parsed RevCommitCG has derived data from commit-graph
If a RevCommitCG was newly created and called #parseCanonical(RevWalk, byte[]) method immediately, its flag was marked as PARSED, but no derived data was obtained from the commit-graph. This is different from what we expected. Change-Id: I5d417efa3c42d211f19e6acf255f761e84d84450 Signed-off-by: kylezhao <kylezhao@tencent.com>
This commit is contained in:
parent
17fac8a27e
commit
d3ba40c803
|
@ -83,6 +83,42 @@ public void testParseHeaders() throws Exception {
|
|||
assertArrayEquals(notParseInGraph.getParents(), noBody.getParents());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCanonical() throws Exception {
|
||||
RevCommit c1 = commitFile("file1", "1", "master");
|
||||
enableAndWriteCommitGraph();
|
||||
|
||||
RevCommit notParseInGraph = rw.lookupCommit(c1);
|
||||
rw.parseHeaders(notParseInGraph);
|
||||
|
||||
reinitializeRevWalk();
|
||||
RevCommit parseInGraph = rw.lookupCommit(c1);
|
||||
parseInGraph.parseCanonical(rw, rw.getCachedBytes(c1));
|
||||
|
||||
assertTrue(parseInGraph instanceof RevCommitCG);
|
||||
assertNotNull(parseInGraph.getRawBuffer());
|
||||
assertEquals(1, parseInGraph.getGeneration());
|
||||
assertEquals(notParseInGraph.getId(), parseInGraph.getId());
|
||||
assertEquals(notParseInGraph.getTree(), parseInGraph.getTree());
|
||||
assertEquals(notParseInGraph.getCommitTime(),
|
||||
parseInGraph.getCommitTime());
|
||||
assertArrayEquals(notParseInGraph.getParents(),
|
||||
parseInGraph.getParents());
|
||||
|
||||
reinitializeRevWalk();
|
||||
rw.setRetainBody(false);
|
||||
RevCommit noBody = rw.lookupCommit(c1);
|
||||
noBody.parseCanonical(rw, rw.getCachedBytes(c1));
|
||||
|
||||
assertTrue(noBody instanceof RevCommitCG);
|
||||
assertNull(noBody.getRawBuffer());
|
||||
assertEquals(1, noBody.getGeneration());
|
||||
assertEquals(notParseInGraph.getId(), noBody.getId());
|
||||
assertEquals(notParseInGraph.getTree(), noBody.getTree());
|
||||
assertEquals(notParseInGraph.getCommitTime(), noBody.getCommitTime());
|
||||
assertArrayEquals(notParseInGraph.getParents(), noBody.getParents());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializeShallowCommits() throws Exception {
|
||||
RevCommit c1 = commit(commit());
|
||||
|
|
|
@ -125,7 +125,15 @@ public static RevCommit parse(RevWalk rw, byte[] raw) throws IOException {
|
|||
|
||||
int inDegree;
|
||||
|
||||
private byte[] buffer;
|
||||
/**
|
||||
* Raw unparsed commit body of the commit. Populated only
|
||||
* after {@link #parseCanonical(RevWalk, byte[])} with
|
||||
* {@link RevWalk#isRetainBody()} enable or after
|
||||
* {@link #parseBody(RevWalk)} and {@link #parse(RevWalk, byte[])}.
|
||||
*
|
||||
* @since 6.5.1
|
||||
*/
|
||||
protected byte[] buffer;
|
||||
|
||||
/**
|
||||
* Create a new commit reference.
|
||||
|
|
|
@ -44,10 +44,27 @@ protected RevCommitCG(AnyObjectId id, int graphPosition) {
|
|||
this.graphPosition = graphPosition;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
void parseCanonical(RevWalk walk, byte[] raw) throws IOException {
|
||||
if (walk.isRetainBody()) {
|
||||
buffer = raw;
|
||||
}
|
||||
parseInGraph(walk);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
void parseHeaders(RevWalk walk) throws MissingObjectException,
|
||||
IncorrectObjectTypeException, IOException {
|
||||
if (walk.isRetainBody()) {
|
||||
super.parseBody(walk); // This parses header and body
|
||||
return;
|
||||
}
|
||||
parseInGraph(walk);
|
||||
}
|
||||
|
||||
private void parseInGraph(RevWalk walk) throws IOException {
|
||||
CommitGraph graph = walk.commitGraph();
|
||||
CommitGraph.CommitData data = graph.getCommitData(graphPosition);
|
||||
if (data == null) {
|
||||
|
@ -78,11 +95,7 @@ void parseHeaders(RevWalk walk) throws MissingObjectException,
|
|||
this.parents = pList;
|
||||
}
|
||||
}
|
||||
|
||||
flags |= PARSED;
|
||||
if (walk.isRetainBody()) {
|
||||
super.parseBody(walk);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
Loading…
Reference in New Issue