View Javadoc
1   /*
2    * Copyright (C) 2009, Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.revwalk;
12  
13  import static org.junit.Assert.assertNull;
14  
15  import org.junit.Test;
16  
17  public class RevWalkCullTest extends RevWalkTestCase {
18  	@Test
19  	public void testProperlyCullAllAncestors1() throws Exception {
20  		// Credit goes to Junio C Hamano <gitster@pobox.com> for this
21  		// test case in git-core (t/t6009-rev-list-parent.sh)
22  		//
23  		// We induce a clock skew so two is dated before one.
24  		//
25  		final RevCommit a = commit();
26  		final RevCommit b = commit(-2400, a);
27  		final RevCommit c = commit(b);
28  		final RevCommit d = commit(c);
29  
30  		markStart(a);
31  		markUninteresting(d);
32  		assertNull(rw.next());
33  	}
34  
35  	@Test
36  	public void testProperlyCullAllAncestors2() throws Exception {
37  		// Despite clock skew on c1 being very old it should not
38  		// produce, neither should a or b, or any part of that chain.
39  		//
40  		final RevCommit a = commit();
41  		final RevCommit b = commit(a);
42  		final RevCommit c1 = commit(-5, b);
43  		final RevCommit c2 = commit(10, b);
44  		final RevCommit d = commit(c1, c2);
45  
46  		markStart(d);
47  		markUninteresting(c1);
48  		assertCommit(d, rw.next());
49  		assertCommit(c2, rw.next());
50  		assertNull(rw.next());
51  	}
52  
53  	@Test
54  	public void testProperlyCullAllAncestors_LongHistory() throws Exception {
55  		RevCommit a = commit();
56  		RevCommit b = commit(a);
57  		for (int i = 0; i < 24; i++) {
58  			b = commit(b);
59  			if ((i & 2) == 0)
60  				markUninteresting(b);
61  		}
62  		final RevCommit c = commit(b);
63  
64  		// TestRepository eagerly parses newly created objects. The current rw
65  		// is caching that parsed state. To verify that RevWalk itself is lazy,
66  		// set up a new one.
67  		rw.close();
68  		rw = createRevWalk();
69  		RevCommit a2 = rw.lookupCommit(a);
70  		markStart(c);
71  		markUninteresting(b);
72  		assertCommit(c, rw.next());
73  		assertNull(rw.next());
74  
75  		// We should have aborted before we got back so far that "a"
76  		// would be parsed. Thus, its parents shouldn't be allocated.
77  		//
78  		assertNull(a2.parents);
79  	}
80  }