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  /**
20   * A queue of commits in LIFO order.
21   */
22  public class LIFORevQueue extends BlockRevQueue {
23  	private Block head;
24  
25  	/**
26  	 * Create an empty LIFO queue.
27  	 */
28  	public LIFORevQueue() {
29  		super(false);
30  	}
31  
32  	LIFORevQueue(Generator s) throws MissingObjectException,
33  			IncorrectObjectTypeException, IOException {
34  		super(s);
35  	}
36  
37  	/** {@inheritDoc} */
38  	@Override
39  	public void add(RevCommit c) {
40  		Block b = head;
41  		if (b == null || !b.canUnpop()) {
42  			b = free.newBlock();
43  			b.resetToEnd();
44  			b.next = head;
45  			head = b;
46  		}
47  		b.unpop(c);
48  	}
49  
50  	/** {@inheritDoc} */
51  	@Override
52  	public RevCommit next() {
53  		final Block b = head;
54  		if (b == null)
55  			return null;
56  
57  		final RevCommit c = b.pop();
58  		if (b.isEmpty()) {
59  			head = b.next;
60  			free.freeBlock(b);
61  		}
62  		return c;
63  	}
64  
65  	/** {@inheritDoc} */
66  	@Override
67  	public void clear() {
68  		head = null;
69  		free.clear();
70  	}
71  
72  	@Override
73  	boolean everbodyHasFlag(int f) {
74  		for (Block b = head; b != null; b = b.next) {
75  			for (int i = b.headIndex; i < b.tailIndex; i++)
76  				if ((b.commits[i].flags & f) == 0)
77  					return false;
78  		}
79  		return true;
80  	}
81  
82  	@Override
83  	boolean anybodyHasFlag(int f) {
84  		for (Block b = head; b != null; b = b.next) {
85  			for (int i = b.headIndex; i < b.tailIndex; i++)
86  				if ((b.commits[i].flags & f) != 0)
87  					return true;
88  		}
89  		return false;
90  	}
91  
92  	/** {@inheritDoc} */
93  	@Override
94  	public String toString() {
95  		final StringBuilder s = new StringBuilder();
96  		for (Block q = head; q != null; q = q.next) {
97  			for (int i = q.headIndex; i < q.tailIndex; i++)
98  				describe(s, q.commits[i]);
99  		}
100 		return s.toString();
101 	}
102 }