View Javadoc
1   /*
2    * Copyright (C) 2009, Google Inc.
3    * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> 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 java.io.IOException;
15  
16  import org.eclipse.jgit.errors.IncorrectObjectTypeException;
17  import org.eclipse.jgit.errors.MissingObjectException;
18  
19  class BoundaryGenerator extends Generator {
20  	static final int UNINTERESTING = RevWalk.UNINTERESTING;
21  
22  	Generator g;
23  
24  	BoundaryGenerator(RevWalk w, Generator s) {
25  		super(s.firstParent);
26  		g = new InitialGenerator(w, s);
27  	}
28  
29  	@Override
30  	int outputType() {
31  		return g.outputType() | HAS_UNINTERESTING;
32  	}
33  
34  	@Override
35  	void shareFreeList(BlockRevQueue q) {
36  		g.shareFreeList(q);
37  	}
38  
39  	@Override
40  	RevCommit next() throws MissingObjectException,
41  			IncorrectObjectTypeException, IOException {
42  		return g.next();
43  	}
44  
45  	private class InitialGenerator extends Generator {
46  		private static final int PARSED = RevWalk.PARSED;
47  
48  		private static final int DUPLICATE = RevWalk.TEMP_MARK;
49  
50  		private final RevWalk walk;
51  
52  		private final FIFORevQueue held;
53  
54  		private final Generator source;
55  
56  		InitialGenerator(RevWalk w, Generator s) {
57  			super(s.firstParent);
58  			walk = w;
59  			held = new FIFORevQueue(firstParent);
60  			source = s;
61  			source.shareFreeList(held);
62  		}
63  
64  		@Override
65  		int outputType() {
66  			return source.outputType();
67  		}
68  
69  		@Override
70  		void shareFreeList(BlockRevQueue q) {
71  			q.shareFreeList(held);
72  		}
73  
74  		@Override
75  		RevCommit next() throws MissingObjectException,
76  				IncorrectObjectTypeException, IOException {
77  			RevCommit c = source.next();
78  			if (c != null) {
79  				for (int i = 0; i < c.parents.length; i++) {
80  					if (firstParent && i > 0) {
81  						break;
82  					}
83  					RevCommit p = c.parents[i];
84  					if ((p.flags & UNINTERESTING) != 0) {
85  						held.add(p);
86  					}
87  				}
88  				return c;
89  			}
90  
91  			final FIFORevQueuee.html#FIFORevQueue">FIFORevQueue boundary = new FIFORevQueue(firstParent);
92  			boundary.shareFreeList(held);
93  			for (;;) {
94  				c = held.next();
95  				if (c == null)
96  					break;
97  				if ((c.flags & DUPLICATE) != 0)
98  					continue;
99  				if ((c.flags & PARSED) == 0)
100 					c.parseHeaders(walk);
101 				c.flags |= DUPLICATE;
102 				boundary.add(c);
103 			}
104 			boundary.removeFlag(DUPLICATE);
105 			g = boundary;
106 			return boundary.next();
107 		}
108 	}
109 }