Add the ability to override parents on RevCommit.

This makes RevCommit extensible to allow having different structure of
child-parent relationship. This change is a pre-requsite for having a
FilteredRevCommit that overrides parents from the RevCommit. That then
provides a cheaper way to walk over a subset of RevCommits instead of
an expensive way that applies filters while walking over selected
commits. Useful with Blame which works on a single file and that can be
made performant, if we know all the commits needed by the Blame
algorithm. So Blame algorithm can avoid walking over finding what
commits to blame on.

This change makes parents field on RevCommit private and exposes it
thrrough overrideable methods such as getParents, getParent at index,
getParentCount and setParents. All other files other than RevCommit are
updating the usages of accessing RevCommits parents.

Change-Id: I2d13b001c599cc4ebc92d1ab6e07b07acb3b7fe5
This commit is contained in:
Ronald Bhuleskar 2022-06-15 14:37:21 -07:00
parent b544da795b
commit 61b4d105e4
14 changed files with 333 additions and 129 deletions

View File

@ -78,7 +78,7 @@ public void testParse_NoParents() throws Exception {
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
assertNull(c.getTree());
assertNull(c.parents);
assertNull(c.getParents());
try (RevWalk rw = new RevWalk(db)) {
c.parseCanonical(rw, body.toString().getBytes(UTF_8));
@ -86,23 +86,26 @@ public void testParse_NoParents() throws Exception {
assertEquals(treeId, c.getTree().getId());
assertSame(rw.lookupTree(treeId), c.getTree());
}
assertNotNull(c.parents);
assertEquals(0, c.parents.length);
assertNotNull(c.getParents());
assertEquals(0, c.getParentCount());
assertEquals("", c.getFullMessage());
final PersonIdent cAuthor = c.getAuthorIdent();
assertNotNull(cAuthor);
assertEquals(authorName, cAuthor.getName());
assertEquals(authorEmail, cAuthor.getEmailAddress());
assertEquals((long)authorTime * 1000, cAuthor.getWhen().getTime());
assertEquals(TimeZone.getTimeZone("GMT" + authorTimeZone), cAuthor.getTimeZone());
assertEquals((long) authorTime * 1000, cAuthor.getWhen().getTime());
assertEquals(TimeZone.getTimeZone("GMT" + authorTimeZone),
cAuthor.getTimeZone());
final PersonIdent cCommitter = c.getCommitterIdent();
assertNotNull(cCommitter);
assertEquals(committerName, cCommitter.getName());
assertEquals(committerEmail, cCommitter.getEmailAddress());
assertEquals((long)committerTime * 1000, cCommitter.getWhen().getTime());
assertEquals(TimeZone.getTimeZone("GMT" + committerTimeZone), cCommitter.getTimeZone());
assertEquals((long) committerTime * 1000,
cCommitter.getWhen().getTime());
assertEquals(TimeZone.getTimeZone("GMT" + committerTimeZone),
cCommitter.getTimeZone());
}
private RevCommit create(String msg) throws Exception {
@ -149,16 +152,22 @@ public void testParse_incompleteAuthorAndCommitter() throws Exception {
try (RevWalk rw = new RevWalk(db)) {
c.parseCanonical(rw, b.toString().getBytes(UTF_8));
}
assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent());
assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent());
assertEquals(
new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7),
c.getAuthorIdent());
assertEquals(new PersonIdent("", "", 1218123390000l, -5),
c.getCommitterIdent());
}
@Test
public void testParse_implicit_UTF8_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes(UTF_8));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n"
.getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
@ -171,15 +180,19 @@ public void testParse_implicit_UTF8_encoded() throws Exception {
assertSame(UTF_8, c.getEncoding());
assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName());
assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage());
assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage());
assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n",
c.getFullMessage());
}
@Test
public void testParse_implicit_mixed_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes(ISO_8859_1));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n"
.getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
@ -192,7 +205,8 @@ public void testParse_implicit_mixed_encoded() throws Exception {
assertSame(UTF_8, c.getEncoding());
assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName());
assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage());
assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage());
assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n",
c.getFullMessage());
}
/**
@ -203,9 +217,12 @@ public void testParse_implicit_mixed_encoded() throws Exception {
@Test
public void testParse_explicit_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("EUC-JP"));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("EUC-JP"));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("EUC-JP"));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes("EUC-JP"));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes("EUC-JP"));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n"
.getBytes("EUC-JP"));
b.write("encoding euc_JP\n".getBytes("EUC-JP"));
b.write("\n".getBytes("EUC-JP"));
b.write("\u304d\u308c\u3044\n".getBytes("EUC-JP"));
@ -235,9 +252,12 @@ public void testParse_explicit_encoded() throws Exception {
@Test
public void testParse_explicit_bad_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes(ISO_8859_1));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n"
.getBytes(UTF_8));
b.write("encoding EUC-JP\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
@ -256,21 +276,25 @@ public void testParse_explicit_bad_encoded() throws Exception {
}
/**
* This is a twisted case too, but show what we expect here. We can revise the
* expectations provided this case is updated.
* This is a twisted case too, but show what we expect here. We can revise
* the expectations provided this case is updated.
*
* What happens here is that an encoding us given, but data is not encoded
* that way (and we can detect it), so we try other encodings. Here data could
* actually be decoded in the stated encoding, but we override using UTF-8.
* that way (and we can detect it), so we try other encodings. Here data
* could actually be decoded in the stated encoding, but we override using
* UTF-8.
*
* @throws Exception
*/
@Test
public void testParse_explicit_bad_encoded2() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes(UTF_8));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n"
.getBytes(UTF_8));
b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
@ -319,9 +343,11 @@ public void testParse_incorrectUtf8Name() throws Exception {
@Test
public void testParse_illegalEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes(UTF_8));
b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("committer co <c@example.com> 1218123390 -0500\n"
.getBytes(UTF_8));
b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("message\n".getBytes(UTF_8));
@ -348,9 +374,11 @@ public void testParse_illegalEncoding() throws Exception {
@Test
public void testParse_unsupportedEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes(UTF_8));
b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("committer co <c@example.com> 1218123390 -0500\n"
.getBytes(UTF_8));
b.write("encoding it_IT.UTF8\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("message\n".getBytes(UTF_8));
@ -474,21 +502,18 @@ private static ObjectId id(String str) {
@Test
public void testParse_gpgSig() throws Exception {
String commit = "tree e3a1035abd2b319bb01e57d69b0ba6cab289297e\n" +
"parent 54e895b87c0768d2317a2b17062e3ad9f76a8105\n" +
"committer A U Thor <author@xample.com 1528968566 +0200\n" +
"gpgsig -----BEGIN PGP SIGNATURE-----\n" +
" \n" +
" wsBcBAABCAAQBQJbGB4pCRBK7hj4Ov3rIwAAdHIIAENrvz23867ZgqrmyPemBEZP\n" +
" U24B1Tlq/DWvce2buaxmbNQngKZ0pv2s8VMc11916WfTIC9EKvioatmpjduWvhqj\n" +
" znQTFyiMor30pyYsfrqFuQZvqBW01o8GEWqLg8zjf9Rf0R3LlOEw86aT8CdHRlm6\n" +
" wlb22xb8qoX4RB+LYfz7MhK5F+yLOPXZdJnAVbuyoMGRnDpwdzjL5Hj671+XJxN5\n" +
" SasRdhxkkfw/ZnHxaKEc4juMz8Nziz27elRwhOQqlTYoXNJnsV//wy5Losd7aKi1\n" +
" xXXyUpndEOmT0CIcKHrN/kbYoVL28OJaxoBuva3WYQaRrzEe3X02NMxZe9gkSqA=\n" +
" =TClh\n" +
" -----END PGP SIGNATURE-----\n" +
"some other header\n\n" +
"commit message";
String commit = "tree e3a1035abd2b319bb01e57d69b0ba6cab289297e\n"
+ "parent 54e895b87c0768d2317a2b17062e3ad9f76a8105\n"
+ "committer A U Thor <author@xample.com 1528968566 +0200\n"
+ "gpgsig -----BEGIN PGP SIGNATURE-----\n" + " \n"
+ " wsBcBAABCAAQBQJbGB4pCRBK7hj4Ov3rIwAAdHIIAENrvz23867ZgqrmyPemBEZP\n"
+ " U24B1Tlq/DWvce2buaxmbNQngKZ0pv2s8VMc11916WfTIC9EKvioatmpjduWvhqj\n"
+ " znQTFyiMor30pyYsfrqFuQZvqBW01o8GEWqLg8zjf9Rf0R3LlOEw86aT8CdHRlm6\n"
+ " wlb22xb8qoX4RB+LYfz7MhK5F+yLOPXZdJnAVbuyoMGRnDpwdzjL5Hj671+XJxN5\n"
+ " SasRdhxkkfw/ZnHxaKEc4juMz8Nziz27elRwhOQqlTYoXNJnsV//wy5Losd7aKi1\n"
+ " xXXyUpndEOmT0CIcKHrN/kbYoVL28OJaxoBuva3WYQaRrzEe3X02NMxZe9gkSqA=\n"
+ " =TClh\n" + " -----END PGP SIGNATURE-----\n"
+ "some other header\n\n" + "commit message";
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));

View File

@ -0,0 +1,170 @@
/*
* Copyright (C) 2022, Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.revwalk;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.junit.Before;
import org.junit.Test;
public class RevCommitWithOverriddenParentTest {
private TestRepository<InMemoryRepository> tr;
private RevWalk rw;
@Before
public void setUp() throws Exception {
tr = new TestRepository<>(
new InMemoryRepository(new DfsRepositoryDescription("test")));
rw = tr.getRevWalk();
}
@Test
public void testParseBody() throws Exception {
RevCommit a = tr.commit().add("a", "foo").create();
RevCommit b = tr.commit().parent(a).add("b", "bar").create();
RevCommit c = tr.commit().parent(b).message("commit3").add("a", "foo'")
.create();
RevCommit cBar = new RevCommit(c.getId()) {
@Override
public int getParentCount() {
return 1;
}
@Override
public RevCommit getParent(int nth) {
return a;
}
@Override
public RevCommit[] getParents() {
return new RevCommit[] { a };
}
};
rw.parseBody(cBar);
assertEquals(a, cBar.getParents()[0]);
assertEquals("commit3", cBar.getFullMessage());
assertEquals("foo'", blobAsString(cBar, "a"));
}
@Test
public void testParseHeader() throws Exception {
RevCommit a = tr.commit().add("a", "foo").create();
RevCommit b = tr.commit().parent(a).add("b", "bar").create();
RevCommit c = tr.commit().parent(b).message("commit3").add("a", "foo'")
.create();
RevCommit cBar = new RevCommit(c.getId()) {
@Override
public int getParentCount() {
return 1;
}
@Override
public RevCommit getParent(int nth) {
return a;
}
@Override
public RevCommit[] getParents() {
return new RevCommit[] { a };
}
};
RevCommit parsed = rw.parseCommit(cBar.getId());
rw.parseHeaders(cBar);
assertEquals(c.getId(), parsed.getId());
assertEquals(parsed.getTree(), cBar.getTree());
assertEquals(parsed.getCommitTime(), cBar.getCommitTime());
assertEquals(parsed.getAuthorIdent(), cBar.getAuthorIdent());
}
@Test
public void testFilter() throws Exception {
RevCommit a = tr.commit().add("a", "foo").create();
RevCommit b = tr.commit().parent(a).add("b", "bar").create();
RevCommit c = tr.commit().parent(b).message("commit3").add("a", "foo'")
.create();
RevCommit cBar = new RevCommit(c.getId()) {
@Override
public int getParentCount() {
return 1;
}
@Override
public RevCommit getParent(int nth) {
return a;
}
@Override
public RevCommit[] getParents() {
return new RevCommit[] { a };
}
};
rw.setRevFilter(RevFilter.ALL);
rw.markStart(cBar);
assertSame(cBar, rw.next());
assertSame(a, rw.next());
assertNull(rw.next());
}
@Test
public void testFlag() throws Exception {
RevCommit root = tr.commit().add("todelete", "to be deleted").create();
RevCommit orig = tr.commit().parent(root).rm("todelete")
.add("foo", "foo contents").add("bar", "bar contents")
.add("dir/baz", "baz contents").create();
RevCommit commitOrigBar = new RevCommit(orig.getId()) {
@Override
public int getParentCount() {
return 1;
}
@Override
public RevCommit getParent(int nth) {
return root;
}
@Override
public RevCommit[] getParents() {
return new RevCommit[] { root };
}
};
assertEquals(RevObject.PARSED, orig.flags);
assertEquals(0, commitOrigBar.flags);
commitOrigBar.parseBody(rw);
assertEquals(RevObject.PARSED, commitOrigBar.flags);
}
private String blobAsString(AnyObjectId treeish, String path)
throws Exception {
RevObject obj = tr.get(rw.parseTree(treeish), path);
assertSame(RevBlob.class, obj.getClass());
ObjectLoader loader = rw.getObjectReader().open(obj);
return new String(loader.getCachedBytes(), UTF_8);
}
}

View File

@ -75,6 +75,6 @@ public void testProperlyCullAllAncestors_LongHistory() throws Exception {
// We should have aborted before we got back so far that "a"
// would be parsed. Thus, its parents shouldn't be allocated.
//
assertNull(a2.parents);
assertNull(a2.getParents());
}
}

View File

@ -66,7 +66,7 @@ public final void add(RevCommit c, RevFlag queueControl) {
* flag that controls admission to the queue.
*/
public final void addParents(RevCommit c, RevFlag queueControl) {
final RevCommit[] pList = c.parents;
final RevCommit[] pList = c.getParents();
if (pList == null) {
return;
}

View File

@ -76,11 +76,12 @@ RevCommit next() throws MissingObjectException,
IncorrectObjectTypeException, IOException {
RevCommit c = source.next();
if (c != null) {
for (int i = 0; i < c.parents.length; i++) {
int n = c.getParentCount();
for (int i = 0; i < n; i++) {
if (firstParent && i > 0) {
break;
}
RevCommit p = c.parents[i];
RevCommit p = c.getParent(i);
if ((p.flags & UNINTERESTING) != 0) {
held.add(p);
}

View File

@ -164,11 +164,12 @@ RevCommit next() throws MissingObjectException,
int newDepth = c.depth + 1;
for (int i = 0; i < c.parents.length; i++) {
int n = c.getParentCount();
for (int i = 0; i < n; i++) {
if (firstParent && i > 0) {
break;
}
RevCommit p = c.parents[i];
RevCommit p = c.getParent(i);
DepthWalk.Commit dp = (DepthWalk.Commit) p;
// If no depth has been assigned to this commit, assign

View File

@ -114,7 +114,7 @@ private RevCommit _next() throws MissingObjectException,
return null;
}
for (RevCommit p : c.parents) {
for (RevCommit p : c.getParents()) {
if ((p.flags & IN_PENDING) != 0)
continue;
if ((p.flags & PARSED) == 0)
@ -180,7 +180,7 @@ private void carryOntoHistory(RevCommit c, int carry) {
private void carryOntoHistoryInnerLoop(RevCommit c, int carry) {
for (;;) {
RevCommit[] parents = c.parents;
RevCommit[] parents = c.getParents();
if (parents == null || parents.length == 0) {
break;
}

View File

@ -108,8 +108,9 @@ RevCommit next() throws MissingObjectException,
produce = filter.include(walker, c);
}
for (int i = 0; i < c.parents.length; i++) {
RevCommit p = c.parents[i];
int parentCount = c.getParentCount();
for (int i = 0; i < parentCount; i++) {
RevCommit p = c.getParent(i);
// If the commit is uninteresting, don't try to prune
// parents because we want the maximal uninteresting set.
if (firstParent && i > 0 && (c.flags & UNINTERESTING) == 0) {

View File

@ -102,7 +102,12 @@ public static RevCommit parse(RevWalk rw, byte[] raw) throws IOException {
private RevTree tree;
RevCommit[] parents;
/**
* Avoid accessing this field directly. Use method
* {@link RevCommit#getParents()} instead. RevCommit does not allow parents
* to be overridden and altering parent(s) is not supported.
*/
protected RevCommit[] parents;
int commitTime; // An int here for performance, overflows in 2038
@ -146,7 +151,7 @@ void parseCanonical(RevWalk walk, byte[] raw) throws IOException {
tree = walk.lookupTree(idBuffer);
int ptr = 46;
if (parents == null) {
if (getParents() == null) {
RevCommit[] pList = new RevCommit[1];
int nParents = 0;
for (;;) {
@ -210,8 +215,8 @@ static void carryFlags(RevCommit c, int carry) {
}
private static FIFORevQueue carryFlags1(RevCommit c, int carry, int depth) {
for(;;) {
RevCommit[] pList = c.parents;
for (;;) {
RevCommit[] pList = c.getParents();
if (pList == null || pList.length == 0)
return null;
if (pList.length != 1) {
@ -259,7 +264,7 @@ private static void slowCarryFlags(FIFORevQueue q, int carry) {
// Commits in q have non-null parent arrays and have set all
// flags in carry. This loop finishes copying over the graph.
for (RevCommit c; (c = q.next()) != null;) {
for (RevCommit p : c.parents)
for (RevCommit p : c.getParents())
carryOneStep(q, carry, p);
}
}
@ -267,7 +272,7 @@ private static void slowCarryFlags(FIFORevQueue q, int carry) {
private static void carryOneStep(FIFORevQueue q, int carry, RevCommit c) {
if ((c.flags & carry) != carry) {
c.flags |= carry;
if (c.parents != null)
if (c.getParents() != null)
q.add(c);
}
}
@ -313,8 +318,8 @@ public final RevTree getTree() {
*
* @return number of parents; always a positive value but can be 0.
*/
public final int getParentCount() {
return parents.length;
public int getParentCount() {
return parents == null ? 0 : parents.length;
}
/**
@ -327,7 +332,7 @@ public final int getParentCount() {
* @throws java.lang.ArrayIndexOutOfBoundsException
* an invalid parent index was specified.
*/
public final RevCommit getParent(int nth) {
public RevCommit getParent(int nth) {
return parents[nth];
}
@ -341,7 +346,7 @@ public final RevCommit getParent(int nth) {
*
* @return the array of parents.
*/
public final RevCommit[] getParents() {
public RevCommit[] getParents() {
return parents;
}
@ -353,9 +358,9 @@ public final RevCommit[] getParents() {
* this buffer should be very careful to ensure they do not modify its
* contents during their use of it.
*
* @return the raw unparsed commit body. This is <b>NOT A COPY</b>.
* Altering the contents of this buffer may alter the walker's
* knowledge of this commit, and the results it produces.
* @return the raw unparsed commit body. This is <b>NOT A COPY</b>. Altering
* the contents of this buffer may alter the walker's knowledge of
* this commit, and the results it produces.
*/
public final byte[] getRawBuffer() {
return buffer;
@ -380,7 +385,7 @@ public final byte[] getRawBuffer() {
*/
public final byte[] getRawGpgSignature() {
final byte[] raw = buffer;
final byte[] header = {'g', 'p', 'g', 's', 'i', 'g'};
final byte[] header = { 'g', 'p', 'g', 's', 'i', 'g' };
final int start = RawParseUtils.headerStart(header, raw, 0);
if (start < 0) {
return null;

View File

@ -154,7 +154,9 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
*/
static final int TREE_REV_FILTER_APPLIED = 1 << 7;
/** Number of flag bits we keep internal for our own use. See above flags. */
/**
* Number of flag bits we keep internal for our own use. See above flags.
*/
static final int RESERVED_FLAGS = 8;
private static final int APP_FLAGS = -1 & ~((1 << RESERVED_FLAGS) - 1);
@ -196,9 +198,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
boolean shallowCommitsInitialized;
private enum GetMergedIntoStrategy {
RETURN_ON_FIRST_FOUND,
RETURN_ON_FIRST_NOT_FOUND,
EVALUATE_ALL
RETURN_ON_FIRST_FOUND, RETURN_ON_FIRST_NOT_FOUND, EVALUATE_ALL
}
/**
@ -219,8 +219,8 @@ public RevWalk(Repository repo) {
*
* @param or
* the reader the walker will obtain data from. The reader is not
* closed when the walker is closed (but is closed by {@link
* #dispose()}.
* closed when the walker is closed (but is closed by
* {@link #dispose()}.
*/
public RevWalk(ObjectReader or) {
this(or, false);
@ -381,9 +381,8 @@ public void markStart(Collection<RevCommit> list)
* @throws java.io.IOException
* a pack file or loose object could not be read.
*/
public void markUninteresting(RevCommit c)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
public void markUninteresting(RevCommit c) throws MissingObjectException,
IncorrectObjectTypeException, IOException {
c.flags |= UNINTERESTING;
carryFlagsImpl(c);
markStart(c);
@ -392,8 +391,8 @@ public void markUninteresting(RevCommit c)
/**
* Determine if a commit is reachable from another commit.
* <p>
* A commit <code>base</code> is an ancestor of <code>tip</code> if we
* can find a path of commits that leads from <code>tip</code> and ends at
* A commit <code>base</code> is an ancestor of <code>tip</code> if we can
* find a path of commits that leads from <code>tip</code> and ends at
* <code>base</code>.
* <p>
* This utility function resets the walker, inserts the two supplied
@ -462,7 +461,7 @@ public boolean isMergedInto(RevCommit base, RevCommit tip)
* @since 5.12
*/
public List<Ref> getMergedInto(RevCommit commit, Collection<Ref> refs)
throws IOException{
throws IOException {
return getMergedInto(commit, refs, NullProgressMonitor.INSTANCE);
}
@ -486,9 +485,8 @@ public List<Ref> getMergedInto(RevCommit commit, Collection<Ref> refs)
* @since 5.12
*/
public List<Ref> getMergedInto(RevCommit commit, Collection<Ref> refs,
ProgressMonitor monitor) throws IOException{
return getMergedInto(commit, refs,
GetMergedIntoStrategy.EVALUATE_ALL,
ProgressMonitor monitor) throws IOException {
return getMergedInto(commit, refs, GetMergedIntoStrategy.EVALUATE_ALL,
monitor);
}
@ -531,12 +529,11 @@ public boolean isMergedIntoAll(RevCommit commit, Collection<Ref> refs)
throws IOException {
return getMergedInto(commit, refs,
GetMergedIntoStrategy.RETURN_ON_FIRST_NOT_FOUND,
NullProgressMonitor.INSTANCE).size()
== refs.size();
NullProgressMonitor.INSTANCE).size() == refs.size();
}
private List<Ref> getMergedInto(RevCommit needle, Collection<Ref> haystacks,
Enum returnStrategy, ProgressMonitor monitor) throws IOException {
Enum returnStrategy, ProgressMonitor monitor) throws IOException {
List<Ref> result = new ArrayList<>();
List<RevCommit> uninteresting = new ArrayList<>();
List<RevCommit> marked = new ArrayList<>();
@ -547,7 +544,7 @@ private List<Ref> getMergedInto(RevCommit needle, Collection<Ref> haystacks,
reset(~freeFlags & APP_FLAGS);
filter = RevFilter.ALL;
treeFilter = TreeFilter.ALL;
for (Ref r: haystacks) {
for (Ref r : haystacks) {
if (monitor.isCancelled()) {
return result;
}
@ -574,7 +571,7 @@ private List<Ref> getMergedInto(RevCommit needle, Collection<Ref> haystacks,
break;
}
}
if(!commitFound){
if (!commitFound) {
markUninteresting(c);
uninteresting.add(c);
if (returnStrategy == GetMergedIntoStrategy.RETURN_ON_FIRST_NOT_FOUND) {
@ -990,9 +987,8 @@ public RevObject lookupOrNull(AnyObjectId id) {
* a pack file or loose object could not be read.
*/
@NonNull
public RevCommit parseCommit(AnyObjectId id)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
public RevCommit parseCommit(AnyObjectId id) throws MissingObjectException,
IncorrectObjectTypeException, IOException {
RevObject c = peel(parseAny(id));
if (!(c instanceof RevCommit))
throw new IncorrectObjectTypeException(id.toObjectId(),
@ -1018,9 +1014,8 @@ public RevCommit parseCommit(AnyObjectId id)
* a pack file or loose object could not be read.
*/
@NonNull
public RevTree parseTree(AnyObjectId id)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
public RevTree parseTree(AnyObjectId id) throws MissingObjectException,
IncorrectObjectTypeException, IOException {
RevObject c = peel(parseAny(id));
final RevTree t;
@ -1274,8 +1269,8 @@ public void parseBody(RevObject obj)
* @throws java.io.IOException
* a pack file or loose object could not be read.
*/
public RevObject peel(RevObject obj) throws MissingObjectException,
IOException {
public RevObject peel(RevObject obj)
throws MissingObjectException, IOException {
while (obj instanceof RevTag) {
parseHeaders(obj);
obj = ((RevTag) obj).getObject();
@ -1304,9 +1299,9 @@ public RevFlag newFlag(String name) {
int allocFlag() {
if (freeFlags == 0)
throw new IllegalArgumentException(MessageFormat.format(
JGitText.get().flagsAlreadyCreated,
Integer.valueOf(32 - RESERVED_FLAGS)));
throw new IllegalArgumentException(
MessageFormat.format(JGitText.get().flagsAlreadyCreated,
Integer.valueOf(32 - RESERVED_FLAGS)));
final int m = Integer.lowestOneBit(freeFlags);
freeFlags &= ~m;
return m;
@ -1323,9 +1318,11 @@ int allocFlag() {
*/
public void carry(RevFlag flag) {
if ((freeFlags & flag.mask) != 0)
throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name));
throw new IllegalArgumentException(MessageFormat
.format(JGitText.get().flagIsDisposed, flag.name));
if (flag.walker != this)
throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagNotFromThis, flag.name));
throw new IllegalArgumentException(MessageFormat
.format(JGitText.get().flagNotFromThis, flag.name));
carryFlags |= flag.mask;
}
@ -1359,9 +1356,11 @@ public void carry(Collection<RevFlag> set) {
*/
public final void retainOnReset(RevFlag flag) {
if ((freeFlags & flag.mask) != 0)
throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name));
throw new IllegalArgumentException(MessageFormat
.format(JGitText.get().flagIsDisposed, flag.name));
if (flag.walker != this)
throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagNotFromThis, flag.name));
throw new IllegalArgumentException(MessageFormat
.format(JGitText.get().flagNotFromThis, flag.name));
retainOnReset |= flag.mask;
}
@ -1496,9 +1495,9 @@ protected void reset(int retainFlags) {
final RevCommit c = q.next();
if (c == null)
break;
if (c.parents == null)
if (c.getParents() == null)
continue;
for (RevCommit p : c.parents) {
for (RevCommit p : c.getParents()) {
if ((p.flags & clearFlags) == 0)
continue;
p.flags &= retainFlags;
@ -1538,7 +1537,8 @@ public void dispose() {
* Like {@link #next()}, but if a checked exception is thrown during the
* walk it is rethrown as a {@link RevWalkException}.
*
* @throws RevWalkException if an {@link IOException} was thrown.
* @throws RevWalkException
* if an {@link IOException} was thrown.
* @return next most recent commit; null if traversal is over.
*/
@Nullable
@ -1598,7 +1598,8 @@ public void remove() {
protected void assertNotStarted() {
if (isNotStarted())
return;
throw new IllegalStateException(JGitText.get().outputHasAlreadyBeenStarted);
throw new IllegalStateException(
JGitText.get().outputHasAlreadyBeenStarted);
}
/**

View File

@ -72,7 +72,7 @@ RevCommit next() throws MissingObjectException,
applyFilterToParents(c);
boolean rewrote = false;
final RevCommit[] pList = c.parents;
final RevCommit[] pList = c.getParents();
final int nParents = pList.length;
for (int i = 0; i < nParents; i++) {
final RevCommit oldp = pList[i];
@ -108,7 +108,7 @@ RevCommit next() throws MissingObjectException,
private void applyFilterToParents(RevCommit c)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
for (RevCommit parent : c.parents) {
for (RevCommit parent : c.getParents()) {
while ((parent.flags & RevWalk.TREE_REV_FILTER_APPLIED) == 0) {
RevCommit n = source.next();
@ -130,7 +130,7 @@ private RevCommit rewrite(RevCommit p) throws MissingObjectException,
IncorrectObjectTypeException, IOException {
for (;;) {
if (p.parents.length > 1) {
if (p.getParentCount() > 1) {
// This parent is a merge, so keep it.
//
return p;
@ -150,15 +150,15 @@ private RevCommit rewrite(RevCommit p) throws MissingObjectException,
return p;
}
if (p.parents.length == 0) {
if (p.getParentCount() == 0) {
// We can't go back any further, other than to
// just delete the parent entirely.
//
return null;
}
applyFilterToParents(p.parents[0]);
p = p.parents[0];
applyFilterToParents(p.getParent(0));
p = p.getParent(0);
}
}

View File

@ -48,7 +48,7 @@ class TopoNonIntermixSortGenerator extends Generator {
break;
}
if ((c.flags & TOPO_QUEUED) == 0) {
for (RevCommit p : c.parents) {
for (RevCommit p : c.getParents()) {
p.inDegree++;
if (firstParent) {
@ -94,7 +94,7 @@ RevCommit next() throws MissingObjectException,
continue;
}
for (RevCommit p : c.parents) {
for (RevCommit p : c.getParents()) {
if (--p.inDegree == 0 && (p.flags & TOPO_QUEUED) != 0) {
// The parent has no unproduced interesting children. unpop
// the parent so it goes right behind this child. This means

View File

@ -47,7 +47,7 @@ class TopoSortGenerator extends Generator {
if (c == null) {
break;
}
for (RevCommit p : c.parents) {
for (RevCommit p : c.getParents()) {
p.inDegree++;
if (firstParent) {
break;
@ -86,7 +86,7 @@ RevCommit next() throws MissingObjectException,
// All of our children have already produced,
// so it is OK for us to produce now as well.
//
for (RevCommit p : c.parents) {
for (RevCommit p : c.getParents()) {
if (--p.inDegree == 0 && (p.flags & TOPO_DELAY) != 0) {
// This parent tried to come before us, but we are
// his last child. unpop the parent so it goes right

View File

@ -44,6 +44,7 @@ public class TreeRevFilter extends RevFilter {
private static final int FILTER_APPLIED = RevWalk.TREE_REV_FILTER_APPLIED;
private final int rewriteFlag;
private final TreeWalk pathFilter;
/**
@ -62,10 +63,9 @@ public TreeRevFilter(RevWalk walker, TreeFilter t) {
this(walker, t, 0);
}
/**
* Create a filter for the first phase of a parent-rewriting limited revision
* walk.
* Create a filter for the first phase of a parent-rewriting limited
* revision walk.
* <p>
* This filter is ANDed to evaluate before all other filters and ties the
* configured {@link TreeFilter} into the revision walking process.
@ -79,8 +79,8 @@ public TreeRevFilter(RevWalk walker, TreeFilter t) {
* @param walker
* walker used for reading trees.
* @param t
* filter to compare against any changed paths in each commit. If a
* {@link FollowFilter}, will be replaced with a new filter
* filter to compare against any changed paths in each commit. If
* a {@link FollowFilter}, will be replaced with a new filter
* following new paths after a rename.
* @param rewriteFlag
* flag to color commits to be removed from the simplified DAT.
@ -106,12 +106,12 @@ public boolean include(RevWalk walker, RevCommit c)
c.flags |= FILTER_APPLIED;
// Reset the tree filter to scan this commit and parents.
//
RevCommit[] pList = c.parents;
RevCommit[] pList = c.getParents();
int nParents = pList.length;
TreeWalk tw = pathFilter;
ObjectId[] trees = new ObjectId[nParents + 1];
for (int i = 0; i < nParents; i++) {
RevCommit p = c.parents[i];
RevCommit p = c.getParent(i);
if ((p.flags & PARSED) == 0) {
p.parseHeaders(walker);
}