diff options
author | Marc Strapetz <marc.strapetz@syntevo.com> | 2012-10-29 16:34:33 +0100 |
---|---|---|
committer | Chris Aniszczyk <zx@twitter.com> | 2012-11-21 10:46:02 -0600 |
commit | 67edd3eda77fb98673065501a2cf7c9d39db668c (patch) | |
tree | 7ec3b83428de58b84343cc6707cab187398e513f /org.eclipse.jgit.test | |
parent | 8eb4d926371edea2d58dc598e3ebcddacbdc326e (diff) | |
download | jgit-67edd3eda77fb98673065501a2cf7c9d39db668c.tar.gz jgit-67edd3eda77fb98673065501a2cf7c9d39db668c.zip |
RevWalk support for shallow clones
StartGenerator now processes .git/shallow to have the
RevWalk stop for shallow commits.
See RevWalkShallowTest for tests.
Bug: 394543
CQ: 6908
Change-Id: Ia5af1dab3fe9c7888f44eeecab1e1bcf2e8e48fe
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java | 42 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java | 195 |
2 files changed, 216 insertions, 21 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java index 7f440df22a..1720b26bbc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java @@ -48,7 +48,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; - +import java.io.IOException; import java.util.List; import org.eclipse.jgit.lib.Constants; @@ -58,7 +58,7 @@ import org.junit.Test; public class FooterLineTest extends RepositoryTestCase { @Test - public void testNoFooters_EmptyBody() { + public void testNoFooters_EmptyBody() throws IOException { final RevCommit commit = parse(""); final List<FooterLine> footers = commit.getFooterLines(); assertNotNull(footers); @@ -66,7 +66,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testNoFooters_NewlineOnlyBody1() { + public void testNoFooters_NewlineOnlyBody1() throws IOException { final RevCommit commit = parse("\n"); final List<FooterLine> footers = commit.getFooterLines(); assertNotNull(footers); @@ -74,7 +74,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testNoFooters_NewlineOnlyBody5() { + public void testNoFooters_NewlineOnlyBody5() throws IOException { final RevCommit commit = parse("\n\n\n\n\n"); final List<FooterLine> footers = commit.getFooterLines(); assertNotNull(footers); @@ -82,7 +82,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testNoFooters_OneLineBodyNoLF() { + public void testNoFooters_OneLineBodyNoLF() throws IOException { final RevCommit commit = parse("this is a commit"); final List<FooterLine> footers = commit.getFooterLines(); assertNotNull(footers); @@ -90,7 +90,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testNoFooters_OneLineBodyWithLF() { + public void testNoFooters_OneLineBodyWithLF() throws IOException { final RevCommit commit = parse("this is a commit\n"); final List<FooterLine> footers = commit.getFooterLines(); assertNotNull(footers); @@ -98,7 +98,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testNoFooters_ShortBodyNoLF() { + public void testNoFooters_ShortBodyNoLF() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit"); final List<FooterLine> footers = commit.getFooterLines(); assertNotNull(footers); @@ -106,7 +106,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testNoFooters_ShortBodyWithLF() { + public void testNoFooters_ShortBodyWithLF() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n"); final List<FooterLine> footers = commit.getFooterLines(); assertNotNull(footers); @@ -114,7 +114,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testSignedOffBy_OneUserNoLF() { + public void testSignedOffBy_OneUserNoLF() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Signed-off-by: A. U. Thor <a@example.com>"); final List<FooterLine> footers = commit.getFooterLines(); @@ -130,7 +130,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testSignedOffBy_OneUserWithLF() { + public void testSignedOffBy_OneUserWithLF() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Signed-off-by: A. U. Thor <a@example.com>\n"); final List<FooterLine> footers = commit.getFooterLines(); @@ -146,7 +146,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testSignedOffBy_IgnoreWhitespace() { + public void testSignedOffBy_IgnoreWhitespace() throws IOException { // We only ignore leading whitespace on the value, trailing // is assumed part of the value. // @@ -165,7 +165,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testEmptyValueNoLF() { + public void testEmptyValueNoLF() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Signed-off-by:"); final List<FooterLine> footers = commit.getFooterLines(); @@ -181,7 +181,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testEmptyValueWithLF() { + public void testEmptyValueWithLF() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Signed-off-by:\n"); final List<FooterLine> footers = commit.getFooterLines(); @@ -197,7 +197,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testShortKey() { + public void testShortKey() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "K:V\n"); final List<FooterLine> footers = commit.getFooterLines(); @@ -213,7 +213,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testNonDelimtedEmail() { + public void testNonDelimtedEmail() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Acked-by: re@example.com\n"); final List<FooterLine> footers = commit.getFooterLines(); @@ -229,7 +229,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testNotEmail() { + public void testNotEmail() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Acked-by: Main Tain Er\n"); final List<FooterLine> footers = commit.getFooterLines(); @@ -245,7 +245,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testSignedOffBy_ManyUsers() { + public void testSignedOffBy_ManyUsers() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "Not-A-Footer-Line: this line must not be read as a footer\n" + "\n" // paragraph break, now footers appear in final block @@ -281,7 +281,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testSignedOffBy_SkipNonFooter() { + public void testSignedOffBy_SkipNonFooter() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "Not-A-Footer-Line: this line must not be read as a footer\n" + "\n" // paragraph break, now footers appear in final block @@ -314,7 +314,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testFilterFootersIgnoreCase() { + public void testFilterFootersIgnoreCase() throws IOException { final RevCommit commit = parse("subject\n\nbody of commit\n" + "Not-A-Footer-Line: this line must not be read as a footer\n" + "\n" // paragraph break, now footers appear in final block @@ -332,7 +332,7 @@ public class FooterLineTest extends RepositoryTestCase { } @Test - public void testMatchesBugId() { + public void testMatchesBugId() throws IOException { final RevCommit commit = parse("this is a commit subject for test\n" + "\n" // paragraph break, now footers appear in final block + "Simple-Bug-Id: 42\n"); @@ -352,7 +352,7 @@ public class FooterLineTest extends RepositoryTestCase { assertFalse("not CC", line.matches(FooterKey.CC)); } - private RevCommit parse(final String msg) { + private RevCommit parse(final String msg) throws IOException { final StringBuilder buf = new StringBuilder(); buf.append("tree " + ObjectId.zeroId().name() + "\n"); buf.append("author A. U. Thor <a@example.com> 1 +0000\n"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java new file mode 100644 index 0000000000..479d9d304a --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2012, Marc Strapetz <marc.strapetz@syntevo.com> + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.revwalk; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jgit.junit.JGitTestUtil; +import org.eclipse.jgit.lib.*; +import org.junit.*; + +import static org.junit.Assert.*; + +public class RevWalkShallowTest extends RevWalkTestCase { + + // Accessing ============================================================== + + @Test + public void testDepth1() throws Exception { + final RevCommit a = commit(); + final RevCommit b = commit(a); + final RevCommit c = commit(b); + final RevCommit d = commit(c); + + createShallowFile(d); + + rw.reset(); + markStart(d); + assertCommit(d, rw.next()); + assertNull(rw.next()); + } + + @Test + public void testDepth2() throws Exception { + final RevCommit a = commit(); + final RevCommit b = commit(a); + final RevCommit c = commit(b); + final RevCommit d = commit(c); + + createShallowFile(c); + + rw.reset(); + markStart(d); + assertCommit(d, rw.next()); + assertCommit(c, rw.next()); + assertNull(rw.next()); + } + + @Test + public void testDepth3() throws Exception { + final RevCommit a = commit(); + final RevCommit b = commit(a); + final RevCommit c = commit(b); + final RevCommit d = commit(c); + + createShallowFile(b); + + rw.reset(); + markStart(d); + assertCommit(d, rw.next()); + assertCommit(c, rw.next()); + assertCommit(b, rw.next()); + assertNull(rw.next()); + } + + @Test + public void testMergeCommitOneParentShallow() throws Exception { + final RevCommit a = commit(); + final RevCommit b = commit(a); + final RevCommit c = commit(b); + final RevCommit d = commit(b); + final RevCommit e = commit(d); + final RevCommit merge = commit(c, e); + + createShallowFile(e); + + rw.reset(); + markStart(merge); + assertCommit(merge, rw.next()); + assertCommit(e, rw.next()); + assertCommit(c, rw.next()); + assertCommit(b, rw.next()); + assertCommit(a, rw.next()); + assertNull(rw.next()); + } + + @Test + public void testMergeCommitEntirelyShallow() throws Exception { + final RevCommit a = commit(); + final RevCommit b = commit(a); + final RevCommit c = commit(b); + final RevCommit d = commit(b); + final RevCommit e = commit(d); + final RevCommit merge = commit(c, e); + + createShallowFile(c, e); + + rw.reset(); + markStart(merge); + assertCommit(merge, rw.next()); + assertCommit(e, rw.next()); + assertCommit(c, rw.next()); + assertNull(rw.next()); + } + + @Test + public void testObjectDirectorySnapshot() throws Exception { + RevCommit a = commit(); + RevCommit b = commit(a); + RevCommit c = commit(b); + RevCommit d = commit(c); + + createShallowFile(d); + + rw.reset(); + markStart(d); + assertCommit(d, rw.next()); + assertNull(rw.next()); + + rw = createRevWalk(); + a = rw.lookupCommit(a); + b = rw.lookupCommit(b); + c = rw.lookupCommit(c); + d = rw.lookupCommit(d); + + rw.reset(); + markStart(d); + assertCommit(d, rw.next()); + assertNull(rw.next()); + + createShallowFile(c); + + rw = createRevWalk(); + a = rw.lookupCommit(a); + b = rw.lookupCommit(b); + c = rw.lookupCommit(c); + d = rw.lookupCommit(d); + + rw.reset(); + markStart(d); + assertCommit(d, rw.next()); + assertCommit(c, rw.next()); + assertNull(rw.next()); + } + + private void createShallowFile(ObjectId... shallowCommits) + throws IOException { + final StringBuilder builder = new StringBuilder(); + for (ObjectId commit : shallowCommits) + builder.append(commit.getName() + "\n"); + JGitTestUtil.write(new File(rw.repository.getDirectory(), "shallow"), + builder.toString()); + } +} |