]> source.dussan.org Git - jgit.git/commitdiff
Add the ability to override parents on RevCommit. 04/194204/26
authorRonald Bhuleskar <funronald@google.com>
Wed, 15 Jun 2022 21:37:21 +0000 (14:37 -0700)
committerRonald Bhuleskar <funronald@google.com>
Tue, 2 Aug 2022 17:50:16 +0000 (10:50 -0700)
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

14 files changed:
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitWithOverriddenParentTest.java [new file with mode: 0644]
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/AbstractRevQueue.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BoundaryGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/MergeBaseGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PendingGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoNonIntermixSortGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoSortGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java

index 0e4c05d792356092f6d6ff0eeb0db168932494a5..82af34ded2d3ffcd23d6d3257616f649503f2b21 100644 (file)
@@ -78,7 +78,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
 
                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 class RevCommitParseTest extends RepositoryTestCase {
                        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 class RevCommitParseTest extends RepositoryTestCase {
                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 class RevCommitParseTest extends RepositoryTestCase {
                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 class RevCommitParseTest extends RepositoryTestCase {
                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 class RevCommitParseTest extends RepositoryTestCase {
        @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 class RevCommitParseTest extends RepositoryTestCase {
        @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 class RevCommitParseTest extends RepositoryTestCase {
        }
 
        /**
-        * 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 class RevCommitParseTest extends RepositoryTestCase {
        @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 class RevCommitParseTest extends RepositoryTestCase {
        @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 @@ public class RevCommitParseTest extends RepositoryTestCase {
 
        @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"));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitWithOverriddenParentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitWithOverriddenParentTest.java
new file mode 100644 (file)
index 0000000..b06f9fc
--- /dev/null
@@ -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);
+       }
+}
index 722b2d2927ad77b9f40bc523997d0b78a8aa019c..7b0e2b22672ff897e141cf43d17ac9b4aeac0ef7 100644 (file)
@@ -75,6 +75,6 @@ public class RevWalkCullTest extends RevWalkTestCase {
                // 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());
        }
 }
index e0c7bdd39683f9768719ec5570524c27817fec7c..dda108bc6957ad828d08acccd760cb0ae1d5bcac 100644 (file)
@@ -66,7 +66,7 @@ abstract class AbstractRevQueue extends Generator {
         *            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;
                }
index 8b78d062b5326c876339e699e3e5c1f4bd46393d..bdf63ff10bad75e6c88ed76f92132b2004b86491 100644 (file)
@@ -76,11 +76,12 @@ class BoundaryGenerator extends Generator {
                                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);
                                        }
index 3a2cb8b0f938f9597ee2ac8d6a6d6851c0d825a5..ec0824cb0bc9d51bdef8c7611bd30ed198329961 100644 (file)
@@ -164,11 +164,12 @@ class DepthGenerator extends Generator {
 
                        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
index c0fea75777bf1a2499d02f8477b7c311f49acff2..a213dd47c69387bad9496dd487157b1c55286286 100644 (file)
@@ -114,7 +114,7 @@ class MergeBaseGenerator extends Generator {
                                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 @@ class MergeBaseGenerator extends Generator {
 
        private void carryOntoHistoryInnerLoop(RevCommit c, int carry) {
                for (;;) {
-                       RevCommit[] parents = c.parents;
+                       RevCommit[] parents = c.getParents();
                        if (parents == null || parents.length == 0) {
                                break;
                        }
index add387de039d7136db99d819bf494b790f7c02ed..a49f787316069c13b49999296ffd64b4f956a43f 100644 (file)
@@ -108,8 +108,9 @@ class PendingGenerator extends Generator {
                                        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) {
index 82725f3db97cc52d09aeeb928a22407b66e081da..7a74e314f6b41ee5d9b913eb2951e1bec1ac9204 100644 (file)
@@ -102,7 +102,12 @@ public class RevCommit extends RevObject {
 
        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 @@ public class RevCommit extends RevObject {
                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 @@ public class RevCommit extends RevObject {
        }
 
        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 @@ public class RevCommit extends RevObject {
                // 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 @@ public class RevCommit extends RevObject {
        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 class RevCommit extends RevObject {
         *
         * @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 class RevCommit extends RevObject {
         * @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 class RevCommit extends RevObject {
         *
         * @return the array of parents.
         */
-       public final RevCommit[] getParents() {
+       public RevCommit[] getParents() {
                return parents;
        }
 
@@ -353,9 +358,9 @@ public class RevCommit extends RevObject {
         * 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 class RevCommit extends RevObject {
         */
        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;
index a25948e50b6bc2b57fd8b23c591e5b660b4c958d..8da36c52438feec09b7212a99ba18db7d0bfc7fd 100644 (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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         *
         * @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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         * @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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
        /**
         * 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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         * @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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         * @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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
                        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 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
                        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 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
                                                break;
                                        }
                                }
-                               if(!commitFound){
+                               if (!commitFound) {
                                        markUninteresting(c);
                                        uninteresting.add(c);
                                        if (returnStrategy == GetMergedIntoStrategy.RETURN_ON_FIRST_NOT_FOUND) {
@@ -990,9 +987,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         *             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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         *             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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         * @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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
 
        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 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         */
        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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         */
        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 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
                        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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
         * 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 class RevWalk implements Iterable<RevCommit>, AutoCloseable {
        protected void assertNotStarted() {
                if (isNotStarted())
                        return;
-               throw new IllegalStateException(JGitText.get().outputHasAlreadyBeenStarted);
+               throw new IllegalStateException(
+                               JGitText.get().outputHasAlreadyBeenStarted);
        }
 
        /**
index 1adef07ad9d3f5aaecd85d71f399c3ccf5690867..2c88bb872e9c3c4f201641fb52664fe7738a4f75 100644 (file)
@@ -72,7 +72,7 @@ class RewriteGenerator extends Generator {
                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 @@ class RewriteGenerator extends Generator {
        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 @@ class RewriteGenerator extends Generator {
                        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 @@ class RewriteGenerator extends Generator {
                                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);
 
                }
        }
index 4f6d417ed1df679b3a280a5b263c71fdeeebe61d..452545a04e72755352ec0fa59d4ebd7f438d7574 100644 (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 @@ class TopoNonIntermixSortGenerator extends Generator {
                                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
index 7a5db43a7a60f0aceacd2f38c4becee67fcb7222..4739f78fc0f426617e050e4fb51d64ff74990a41 100644 (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 @@ class TopoSortGenerator extends Generator {
                        // 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
index 92d72268d116afa463d898b55d4eaf8c2d998398..f921449ffa03e024522a068182abbe075ff9f079 100644 (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 class TreeRevFilter extends RevFilter {
                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 class TreeRevFilter extends RevFilter {
         * @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
+        *            {@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 class TreeRevFilter extends RevFilter {
                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);
                        }