View Javadoc
1   /*
2    * Copyright (C) 2011, Garmin International
3    * Copyright (C) 2011, Jesse Greenwald <jesse.greenwald@gmail.com> and others
4    *
5    * This program and the accompanying materials are made available under the
6    * terms of the Eclipse Distribution License v. 1.0 which is available at
7    * https://www.eclipse.org/org/documents/edl-v10.php.
8    *
9    * SPDX-License-Identifier: BSD-3-Clause
10   */
11  
12  package org.eclipse.jgit.revwalk;
13  
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertTrue;
16  
17  import java.io.IOException;
18  import java.util.concurrent.atomic.AtomicBoolean;
19  
20  import org.eclipse.jgit.errors.IncorrectObjectTypeException;
21  import org.eclipse.jgit.errors.MissingObjectException;
22  import org.eclipse.jgit.errors.StopWalkException;
23  import org.eclipse.jgit.revwalk.filter.RevFilter;
24  import org.junit.Test;
25  
26  public class RevWalkResetTest extends RevWalkTestCase {
27  
28  	@Test
29  	public void testRevFilterReceivesParsedCommits() throws Exception {
30  		final RevCommit a = commit();
31  		final RevCommit b = commit(a);
32  		final RevCommit c = commit(b);
33  
34  		final AtomicBoolean filterRan = new AtomicBoolean();
35  		RevFilter testFilter = new RevFilter() {
36  
37  			@Override
38  			public boolean include(RevWalk walker, RevCommit cmit)
39  					throws StopWalkException, MissingObjectException,
40  					IncorrectObjectTypeException, IOException {
41  				assertNotNull("commit is parsed", cmit.getRawBuffer());
42  				filterRan.set(true);
43  				return true;
44  			}
45  
46  			@Override
47  			public RevFilter clone() {
48  				return this;
49  			}
50  
51  			@Override
52  			public boolean requiresCommitBody() {
53  				return true;
54  			}
55  		};
56  
57  		// Do an initial run through the walk
58  		filterRan.set(false);
59  		rw.setRevFilter(testFilter);
60  		markStart(c);
61  		rw.markUninteresting(b);
62  		for (RevCommit cmit = rw.next(); cmit != null; cmit = rw.next()) {
63  			// Don't dispose the body here, because we want to test the effect
64  			// of marking 'b' as uninteresting.
65  		}
66  		assertTrue("filter ran", filterRan.get());
67  
68  		// Run through the walk again, this time disposing of all commits.
69  		filterRan.set(false);
70  		rw.reset();
71  		markStart(c);
72  		for (RevCommit cmit = rw.next(); cmit != null; cmit = rw.next()) {
73  			cmit.disposeBody();
74  		}
75  		assertTrue("filter ran", filterRan.get());
76  
77  		// Do the third run through the reused walk. Test that the explicitly
78  		// disposed commits are parsed on this walk.
79  		filterRan.set(false);
80  		rw.reset();
81  		markStart(c);
82  		for (RevCommit cmit = rw.next(); cmit != null; cmit = rw.next()) {
83  			// spin through the walk.
84  		}
85  		assertTrue("filter ran", filterRan.get());
86  
87  	}
88  }