View Javadoc
1   /*
2    * Copyright (C) 2016, Christian Halstrick <christian.halstrick@sap.com>
3    * and other copyright owners as documented in the project's IP log.
4    *
5    * This program and the accompanying materials are made available
6    * under the terms of the Eclipse Distribution License v1.0 which
7    * accompanies this distribution, is reproduced below, and is
8    * available at http://www.eclipse.org/org/documents/edl-v10.php
9    *
10   * All rights reserved.
11   *
12   * Redistribution and use in source and binary forms, with or
13   * without modification, are permitted provided that the following
14   * conditions are met:
15   *
16   * - Redistributions of source code must retain the above copyright
17   *   notice, this list of conditions and the following disclaimer.
18   *
19   * - Redistributions in binary form must reproduce the above
20   *   copyright notice, this list of conditions and the following
21   *   disclaimer in the documentation and/or other materials provided
22   *   with the distribution.
23   *
24   * - Neither the name of the Eclipse Foundation, Inc. nor the
25   *   names of its contributors may be used to endorse or promote
26   *   products derived from this software without specific prior
27   *   written permission.
28   *
29   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30   * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42   */
43  
44  package org.eclipse.jgit.revwalk;
45  
46  import static org.junit.Assert.assertNull;
47  import static org.junit.Assert.assertTrue;
48  
49  import org.junit.Test;
50  
51  public class RevWalkCarryFlagsTest extends RevWalkTestCase {
52  	/**
53  	 * Test that the uninteresting flag is carried over correctly. Every commit
54  	 * should have the uninteresting flag resulting in a RevWalk returning no
55  	 * commit.
56  	 *
57  	 * @throws Exception
58  	 */
59  	@Test
60  	public void testRevWalkCarryUninteresting_fastClock() throws Exception {
61  		final RevCommit a = commit();
62  		final RevCommit b = commit(a);
63  		final RevCommit c = commit(a);
64  		final RevCommit d = commit(c);
65  		final RevCommit e = commit(b, d);
66  
67  		markStart(d);
68  		markUninteresting(e);
69  		assertNull("Found an unexpected commit", rw.next());
70  	}
71  
72  	/**
73  	 * Similar to {@link #testRevWalkCarryUninteresting_fastClock()} but the
74  	 * last merge commit is created so fast that he has the same creationdate as
75  	 * the previous commit. This will cause the underlying {@link DateRevQueue}
76  	 * is not able to sort the commits in a way matching the topology. A parent
77  	 * (one of the commits which are merged) is handled before the child (the
78  	 * merge commit). This makes carrying over flags more complicated
79  	 *
80  	 * @throws Exception
81  	 */
82  	@Test
83  	public void testRevWalkCarryUninteresting_SlowClock() throws Exception {
84  		final RevCommit a = commit();
85  		final RevCommit b = commit(a);
86  		final RevCommit c = commit(a);
87  		final RevCommit d = commit(c);
88  		final RevCommit e = commit(0, b, d);
89  
90  		markStart(d);
91  		markUninteresting(e);
92  		assertNull("Found an unexpected commit", rw.next());
93  	}
94  
95  	/**
96  	 * Similar to {@link #testRevWalkCarryUninteresting_SlowClock()} but the
97  	 * last merge commit is created with a inconsistent creationdate. The merge
98  	 * commit has a older creationdate then one of the commits he is merging.
99  	 *
100 	 * @throws Exception
101 	 */
102 	@Test
103 	public void testRevWalkCarryUninteresting_WrongClock() throws Exception {
104 		final RevCommit a = commit();
105 		final RevCommit b = commit(a);
106 		final RevCommit c = commit(a);
107 		final RevCommit d = commit(c);
108 		final RevCommit e = commit(-1, b, d);
109 
110 		markStart(d);
111 		markUninteresting(e);
112 		assertNull("Found an unexpected commit", rw.next());
113 	}
114 
115 	/**
116 	 * Same as {@link #testRevWalkCarryUninteresting_SlowClock()} but this time
117 	 * we focus on the carrying over a custom flag.
118 	 *
119 	 * @throws Exception
120 	 */
121 	@Test
122 	public void testRevWalkCarryCustom_SlowClock() throws Exception {
123 		final RevCommit a = commit();
124 		final RevCommit b = commit(a);
125 		final RevCommit c = commit(a);
126 		final RevCommit d = commit(c);
127 		final RevCommit e = commit(0, b, d);
128 
129 		markStart(d);
130 		markStart(e);
131 		RevFlag customFlag = rw.newFlag("CUSTOM");
132 		e.flags |= customFlag.mask;
133 		rw.carry(customFlag);
134 
135 		// the merge commit has the flag and it should be carried over -> every
136 		// commit should have this flag
137 		int count = 0;
138 		for (RevCommit cm : rw) {
139 			assertTrue(
140 					"Found a commit which doesn't have the custom flag: " + cm,
141 					cm.has(customFlag));
142 			count++;
143 		}
144 		assertTrue("Didn't walked over all commits", count == 5);
145 	}
146 }