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));
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 {
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));
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));
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_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"));
@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));
}
/**
- * 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));
@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));
@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));
@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"));
--- /dev/null
+/*
+ * 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);
+ }
+}
// 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());
}
}
* 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;
}
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);
}
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
return null;
}
- for (RevCommit p : c.parents) {
+ for (RevCommit p : c.getParents()) {
if ((p.flags & IN_PENDING) != 0)
continue;
if ((p.flags & PARSED) == 0)
private void carryOntoHistoryInnerLoop(RevCommit c, int carry) {
for (;;) {
- RevCommit[] parents = c.parents;
+ RevCommit[] parents = c.getParents();
if (parents == null || parents.length == 0) {
break;
}
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) {
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
tree = walk.lookupTree(idBuffer);
int ptr = 46;
- if (parents == null) {
+ if (getParents() == null) {
RevCommit[] pList = new RevCommit[1];
int nParents = 0;
for (;;) {
}
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) {
// 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);
}
}
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);
}
}
*
* @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;
}
/**
* @throws java.lang.ArrayIndexOutOfBoundsException
* an invalid parent index was specified.
*/
- public final RevCommit getParent(int nth) {
+ public RevCommit getParent(int nth) {
return parents[nth];
}
*
* @return the array of parents.
*/
- public final RevCommit[] getParents() {
+ public RevCommit[] getParents() {
return parents;
}
* 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;
*/
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;
*/
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);
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
}
/**
*
* @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);
* @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);
/**
* 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
* @since 5.12
*/
public List<Ref> getMergedInto(RevCommit commit, Collection<Ref> refs)
- throws IOException{
+ throws IOException {
return getMergedInto(commit, refs, NullProgressMonitor.INSTANCE);
}
* @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);
}
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<>();
reset(~freeFlags & APP_FLAGS);
filter = RevFilter.ALL;
treeFilter = TreeFilter.ALL;
- for (Ref r: haystacks) {
+ for (Ref r : haystacks) {
if (monitor.isCancelled()) {
return result;
}
break;
}
}
- if(!commitFound){
+ if (!commitFound) {
markUninteresting(c);
uninteresting.add(c);
if (returnStrategy == GetMergedIntoStrategy.RETURN_ON_FIRST_NOT_FOUND) {
* 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(),
* 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;
* @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();
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;
*/
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;
}
*/
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;
}
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;
* 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
protected void assertNotStarted() {
if (isNotStarted())
return;
- throw new IllegalStateException(JGitText.get().outputHasAlreadyBeenStarted);
+ throw new IllegalStateException(
+ JGitText.get().outputHasAlreadyBeenStarted);
}
/**
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];
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();
IncorrectObjectTypeException, IOException {
for (;;) {
- if (p.parents.length > 1) {
+ if (p.getParentCount() > 1) {
// This parent is a merge, so keep it.
//
return p;
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);
}
}
break;
}
if ((c.flags & TOPO_QUEUED) == 0) {
- for (RevCommit p : c.parents) {
+ for (RevCommit p : c.getParents()) {
p.inDegree++;
if (firstParent) {
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
if (c == null) {
break;
}
- for (RevCommit p : c.parents) {
+ for (RevCommit p : c.getParents()) {
p.inDegree++;
if (firstParent) {
break;
// 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
private static final int FILTER_APPLIED = RevWalk.TREE_REV_FILTER_APPLIED;
private final int rewriteFlag;
+
private final TreeWalk pathFilter;
/**
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.
* @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.
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);
}