View Javadoc
1   /*
2    * Copyright (C) 2012, Google Inc.
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.internal.storage.pack;
45  
46  import static org.eclipse.jgit.internal.storage.file.PackBitmapIndex.FLAG_REUSE;
47  import static org.eclipse.jgit.revwalk.RevFlag.SEEN;
48  
49  import java.io.IOException;
50  import java.util.ArrayList;
51  import java.util.Collection;
52  import java.util.Collections;
53  import java.util.Comparator;
54  import java.util.HashSet;
55  import java.util.Iterator;
56  import java.util.List;
57  import java.util.Set;
58  
59  import org.eclipse.jgit.errors.IncorrectObjectTypeException;
60  import org.eclipse.jgit.errors.MissingObjectException;
61  import org.eclipse.jgit.internal.JGitText;
62  import org.eclipse.jgit.internal.revwalk.AddUnseenToBitmapFilter;
63  import org.eclipse.jgit.internal.storage.file.BitmapIndexImpl;
64  import org.eclipse.jgit.internal.storage.file.BitmapIndexImpl.CompressedBitmap;
65  import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
66  import org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder;
67  import org.eclipse.jgit.internal.storage.file.PackBitmapIndexRemapper;
68  import org.eclipse.jgit.lib.AnyObjectId;
69  import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder;
70  import org.eclipse.jgit.lib.Constants;
71  import org.eclipse.jgit.lib.ObjectId;
72  import org.eclipse.jgit.lib.ObjectReader;
73  import org.eclipse.jgit.lib.ProgressMonitor;
74  import org.eclipse.jgit.revwalk.BitmapWalker;
75  import org.eclipse.jgit.revwalk.ObjectWalk;
76  import org.eclipse.jgit.revwalk.RevCommit;
77  import org.eclipse.jgit.revwalk.RevObject;
78  import org.eclipse.jgit.revwalk.RevWalk;
79  import org.eclipse.jgit.revwalk.filter.RevFilter;
80  import org.eclipse.jgit.storage.pack.PackConfig;
81  import org.eclipse.jgit.util.BlockList;
82  import org.eclipse.jgit.util.SystemReader;
83  
84  import com.googlecode.javaewah.EWAHCompressedBitmap;
85  
86  /**
87   * Helper class for the {@link PackWriter} to select commits for which to build
88   * pack index bitmaps.
89   */
90  class PackWriterBitmapPreparer {
91  
92  	private static final int DAY_IN_SECONDS = 24 * 60 * 60;
93  
94  	private static final Comparator<RevCommit> ORDER_BY_REVERSE_TIMESTAMP = (
95  			RevCommit a, RevCommit b) -> Integer
96  					.signum(b.getCommitTime() - a.getCommitTime());
97  
98  	private final ObjectReader reader;
99  	private final ProgressMonitor pm;
100 	private final Set<? extends ObjectId> want;
101 	private final PackBitmapIndexBuilder writeBitmaps;
102 	private final BitmapIndexImpl commitBitmapIndex;
103 	private final PackBitmapIndexRemapper bitmapRemapper;
104 	private final BitmapIndexImpl bitmapIndex;
105 
106 	private final int contiguousCommitCount;
107 	private final int recentCommitCount;
108 	private final int recentCommitSpan;
109 	private final int distantCommitSpan;
110 	private final int excessiveBranchCount;
111 	private final long inactiveBranchTimestamp;
112 
113 	PackWriterBitmapPreparer(ObjectReader reader,
114 			PackBitmapIndexBuilder writeBitmaps, ProgressMonitor pm,
115 			Set<? extends ObjectId> want, PackConfig config)
116 					throws IOException {
117 		this.reader = reader;
118 		this.writeBitmaps = writeBitmaps;
119 		this.pm = pm;
120 		this.want = want;
121 		this.commitBitmapIndex = new BitmapIndexImpl(writeBitmaps);
122 		this.bitmapRemapper = PackBitmapIndexRemapper.newPackBitmapIndex(
123 				reader.getBitmapIndex(), writeBitmaps);
124 		this.bitmapIndex = new BitmapIndexImpl(bitmapRemapper);
125 		this.contiguousCommitCount = config.getBitmapContiguousCommitCount();
126 		this.recentCommitCount = config.getBitmapRecentCommitCount();
127 		this.recentCommitSpan = config.getBitmapRecentCommitSpan();
128 		this.distantCommitSpan = config.getBitmapDistantCommitSpan();
129 		this.excessiveBranchCount = config.getBitmapExcessiveBranchCount();
130 		long now = SystemReader.getInstance().getCurrentTime();
131 		long ageInSeconds = config.getBitmapInactiveBranchAgeInDays()
132 				* DAY_IN_SECONDS;
133 		this.inactiveBranchTimestamp = (now / 1000) - ageInSeconds;
134 	}
135 
136 	/**
137 	 * Returns the commit objects for which bitmap indices should be built.
138 	 *
139 	 * @param expectedCommitCount
140 	 *            count of commits in the pack
141 	 * @param excludeFromBitmapSelection
142 	 *            commits that should be excluded from bitmap selection
143 	 * @return commit objects for which bitmap indices should be built
144 	 * @throws IncorrectObjectTypeException
145 	 *             if any of the processed objects is not a commit
146 	 * @throws IOException
147 	 *             on errors reading pack or index files
148 	 * @throws MissingObjectException
149 	 *             if an expected object is missing
150 	 */
151 	Collection<BitmapCommit> selectCommits(int expectedCommitCount,
152 			Set<? extends ObjectId> excludeFromBitmapSelection)
153 			throws IncorrectObjectTypeException, IOException,
154 			MissingObjectException {
155 		/*
156 		 * Thinking of bitmap indices as a cache, if we find bitmaps at or at a
157 		 * close ancestor to 'old' and 'new' when calculating old..new, then all
158 		 * objects can be calculated with minimal graph walking. A distribution
159 		 * that favors creating bitmaps for the most recent commits maximizes
160 		 * the cache hits for clients that are close to HEAD, which is the
161 		 * majority of calculations performed.
162 		 */
163 		try (RevWalkvwalk/RevWalk.html#RevWalk">RevWalk rw = new RevWalk(reader);
164 				RevWalk rw2 = new RevWalk(reader)) {
165 			pm.beginTask(JGitText.get().selectingCommits,
166 					ProgressMonitor.UNKNOWN);
167 			rw.setRetainBody(false);
168 			CommitSelectionHelper selectionHelper = captureOldAndNewCommits(rw,
169 					expectedCommitCount, excludeFromBitmapSelection);
170 			pm.endTask();
171 
172 			// Add reused bitmaps from the previous GC pack's bitmap indices.
173 			// Currently they are always fully reused, even if their spans don't
174 			// match this run's PackConfig values.
175 			int newCommits = selectionHelper.getCommitCount();
176 			BlockList<BitmapCommit> selections = new BlockList<>(
177 					selectionHelper.reusedCommits.size()
178 							+ newCommits / recentCommitSpan + 1);
179 			for (BitmapCommit reuse : selectionHelper.reusedCommits) {
180 				selections.add(reuse);
181 			}
182 
183 			if (newCommits == 0) {
184 				for (AnyObjectId id : selectionHelper.newWants) {
185 					selections.add(new BitmapCommit(id, false, 0));
186 				}
187 				return selections;
188 			}
189 
190 			pm.beginTask(JGitText.get().selectingCommits, newCommits);
191 			int totalWants = want.size();
192 			BitmapBuilder seen = commitBitmapIndex.newBitmapBuilder();
193 			seen.or(selectionHelper.reusedCommitsBitmap);
194 			rw2.setRetainBody(false);
195 			rw2.setRevFilter(new NotInBitmapFilter(seen));
196 
197 			// For each branch, do a revwalk to enumerate its commits. Exclude
198 			// both reused commits and any commits seen in a previous branch.
199 			// Then iterate through all new commits from oldest to newest,
200 			// selecting well-spaced commits in this branch.
201 			for (RevCommit rc : selectionHelper.newWantsByNewest) {
202 				BitmapBuilder tipBitmap = commitBitmapIndex.newBitmapBuilder();
203 				rw2.markStart((RevCommit) rw2.peel(rw2.parseAny(rc)));
204 				RevCommit rc2;
205 				while ((rc2 = rw2.next()) != null) {
206 					tipBitmap.addObject(rc2, Constants.OBJ_COMMIT);
207 				}
208 				int cardinality = tipBitmap.cardinality();
209 				seen.or(tipBitmap);
210 
211 				// Within this branch, keep ordered lists of commits
212 				// representing chains in its history, where each chain is a
213 				// "sub-branch". Ordering commits by these chains makes for
214 				// fewer differences between consecutive selected commits, which
215 				// in turn provides better compression/on the run-length
216 				// encoding of the XORs between them.
217 				List<List<BitmapCommit>> chains = new ArrayList<>();
218 
219 				// Mark the current branch as inactive if its tip commit isn't
220 				// recent and there are an excessive number of branches, to
221 				// prevent memory bloat of computing too many bitmaps for stale
222 				// branches.
223 				boolean isActiveBranch = true;
224 				if (totalWants > excessiveBranchCount && !isRecentCommit(rc)) {
225 					isActiveBranch = false;
226 				}
227 
228 				// Insert bitmaps at the offsets suggested by the
229 				// nextSelectionDistance() heuristic. Only reuse bitmaps created
230 				// for more distant commits.
231 				int index = -1;
232 				int nextIn = nextSpan(cardinality);
233 				int nextFlg = nextIn == distantCommitSpan
234 						? PackBitmapIndex.FLAG_REUSE
235 						: 0;
236 
237 				// For the current branch, iterate through all commits from
238 				// oldest to newest.
239 				for (RevCommit c : selectionHelper) {
240 					// Optimization: if we have found all the commits for this
241 					// branch, stop searching
242 					int distanceFromTip = cardinality - index - 1;
243 					if (distanceFromTip == 0) {
244 						break;
245 					}
246 
247 					// Ignore commits that are not in this branch
248 					if (!tipBitmap.contains(c)) {
249 						continue;
250 					}
251 
252 					index++;
253 					nextIn--;
254 					pm.update(1);
255 
256 					// Always pick the items in wants, prefer merge commits.
257 					if (selectionHelper.newWants.remove(c)) {
258 						if (nextIn > 0) {
259 							nextFlg = 0;
260 						}
261 					} else {
262 						boolean stillInSpan = nextIn >= 0;
263 						boolean isMergeCommit = c.getParentCount() > 1;
264 						// Force selection if:
265 						// a) we have exhausted the window looking for merges
266 						// b) we are in the top commits of an active branch
267 						// c) we are at a branch tip
268 						boolean mustPick = (nextIn <= -recentCommitSpan)
269 								|| (isActiveBranch
270 										&& (distanceFromTip <= contiguousCommitCount))
271 								|| (distanceFromTip == 1); // most recent commit
272 						if (!mustPick && (stillInSpan || !isMergeCommit)) {
273 							continue;
274 						}
275 					}
276 
277 					// This commit is selected.
278 					// Calculate where to look for the next one.
279 					int flags = nextFlg;
280 					nextIn = nextSpan(distanceFromTip);
281 					nextFlg = nextIn == distantCommitSpan
282 							? PackBitmapIndex.FLAG_REUSE
283 							: 0;
284 
285 					// Create the commit bitmap for the current commit
286 					BitmapBuilder bitmap = commitBitmapIndex.newBitmapBuilder();
287 					rw.reset();
288 					rw.markStart(c);
289 					rw.setRevFilter(new AddUnseenToBitmapFilter(
290 							selectionHelper.reusedCommitsBitmap, bitmap));
291 					while (rw.next() != null) {
292 						// The filter adds the reachable commits to bitmap.
293 					}
294 
295 					// Sort the commits by independent chains in this branch's
296 					// history, yielding better compression when building
297 					// bitmaps.
298 					List<BitmapCommit> longestAncestorChain = null;
299 					for (List<BitmapCommit> chain : chains) {
300 						BitmapCommit mostRecentCommit = chain
301 								.get(chain.size() - 1);
302 						if (bitmap.contains(mostRecentCommit)) {
303 							if (longestAncestorChain == null
304 									|| longestAncestorChain.size() < chain
305 											.size()) {
306 								longestAncestorChain = chain;
307 							}
308 						}
309 					}
310 
311 					if (longestAncestorChain == null) {
312 						longestAncestorChain = new ArrayList<>();
313 						chains.add(longestAncestorChain);
314 					}
315 					longestAncestorChain.add(new BitmapCommit(c,
316 							!longestAncestorChain.isEmpty(), flags));
317 					writeBitmaps.addBitmap(c, bitmap, 0);
318 				}
319 
320 				for (List<BitmapCommit> chain : chains) {
321 					selections.addAll(chain);
322 				}
323 			}
324 			writeBitmaps.clearBitmaps(); // Remove the temporary commit bitmaps.
325 
326 			// Add the remaining peeledWant
327 			for (AnyObjectId remainingWant : selectionHelper.newWants) {
328 				selections.add(new BitmapCommit(remainingWant, false, 0));
329 			}
330 
331 			pm.endTask();
332 			return selections;
333 		}
334 	}
335 
336 	private boolean isRecentCommit(RevCommit revCommit) {
337 		return revCommit.getCommitTime() > inactiveBranchTimestamp;
338 	}
339 
340 	/**
341 	 * A RevFilter that excludes the commits named in a bitmap from the walk.
342 	 * <p>
343 	 * If a commit is in {@code bitmap} then that commit is not emitted by the
344 	 * walk and its parents are marked as SEEN so the walk can skip them.  The
345 	 * bitmaps passed in have the property that the parents of any commit in
346 	 * {@code bitmap} are also in {@code bitmap}, so marking the parents as
347 	 * SEEN speeds up the RevWalk by saving it from walking down blind alleys
348 	 * and does not change the commits emitted.
349 	 */
350 	private static class NotInBitmapFilter extends RevFilter {
351 		private final BitmapBuilder bitmap;
352 
353 		NotInBitmapFilter(BitmapBuilder bitmap) {
354 			this.bitmap = bitmap;
355 		}
356 
357 		@Override
358 		public final boolean include(RevWalk rw, RevCommit c) {
359 			if (!bitmap.contains(c)) {
360 				return true;
361 			}
362 			for (RevCommit p : c.getParents()) {
363 				p.add(SEEN);
364 			}
365 			return false;
366 		}
367 
368 		@Override
369 		public final NotInBitmapFilter clone() {
370 			throw new UnsupportedOperationException();
371 		}
372 
373 		@Override
374 		public final boolean requiresCommitBody() {
375 			return false;
376 		}
377 	}
378 
379 	/**
380 	 * Records which of the {@code wants} can be found in the previous GC pack's
381 	 * bitmap indices and which are new.
382 	 *
383 	 * @param rw
384 	 *            a {@link RevWalk} to find reachable objects in this repository
385 	 * @param expectedCommitCount
386 	 *            expected count of commits. The actual count may be less due to
387 	 *            unreachable garbage.
388 	 * @param excludeFromBitmapSelection
389 	 *            commits that should be excluded from bitmap selection
390 	 * @return a {@link CommitSelectionHelper} capturing which commits are
391 	 *         covered by a previous pack's bitmaps and which new commits need
392 	 *         bitmap coverage
393 	 * @throws IncorrectObjectTypeException
394 	 *             if any of the processed objects is not a commit
395 	 * @throws IOException
396 	 *             on errors reading pack or index files
397 	 * @throws MissingObjectException
398 	 *             if an expected object is missing
399 	 */
400 	private CommitSelectionHelper captureOldAndNewCommits(RevWalk rw,
401 			int expectedCommitCount,
402 			Set<? extends ObjectId> excludeFromBitmapSelection)
403 			throws IncorrectObjectTypeException, IOException,
404 			MissingObjectException {
405 		// Track bitmaps and commits from the previous GC pack bitmap indices.
406 		BitmapBuilder reuse = commitBitmapIndex.newBitmapBuilder();
407 		List<BitmapCommit> reuseCommits = new ArrayList<>();
408 		for (PackBitmapIndexRemapper.Entry entry : bitmapRemapper) {
409 			// More recent commits did not have the reuse flag set, so skip them
410 			if ((entry.getFlags() & FLAG_REUSE) != FLAG_REUSE) {
411 				continue;
412 			}
413 			RevObject ro = rw.peel(rw.parseAny(entry));
414 			if (!(ro instanceof RevCommit)) {
415 				continue;
416 			}
417 
418 			RevCommit rc = (RevCommit) ro;
419 			reuseCommits.add(new BitmapCommit(rc, false, entry.getFlags()));
420 			if (!reuse.contains(rc)) {
421 				EWAHCompressedBitmap bitmap = bitmapRemapper.ofObjectType(
422 						bitmapRemapper.getBitmap(rc), Constants.OBJ_COMMIT);
423 				reuse.or(new CompressedBitmap(bitmap, commitBitmapIndex));
424 			}
425 		}
426 
427 		// Add branch tips that are not represented in a previous pack's bitmap
428 		// indices. Set up a RevWalk to find new commits not in the old packs.
429 		List<RevCommit> newWantsByNewest = new ArrayList<>(want.size());
430 		Set<RevCommit> newWants = new HashSet<>(want.size());
431 		for (AnyObjectId objectId : want) {
432 			RevObject ro = rw.peel(rw.parseAny(objectId));
433 			if (!(ro instanceof RevCommit) || reuse.contains(ro)
434 					|| excludeFromBitmapSelection.contains(ro)) {
435 				continue;
436 			}
437 
438 			RevCommit rc = (RevCommit) ro;
439 			rw.markStart(rc);
440 			newWants.add(rc);
441 			newWantsByNewest.add(rc);
442 		}
443 
444 		// Create a list of commits in reverse order (older to newer) that are
445 		// not in the previous bitmap indices and are reachable.
446 		rw.setRevFilter(new NotInBitmapFilter(reuse));
447 		RevCommit[] commits = new RevCommit[expectedCommitCount];
448 		int pos = commits.length;
449 		RevCommit rc;
450 		while ((rc = rw.next()) != null && pos > 0) {
451 			commits[--pos] = rc;
452 			pm.update(1);
453 		}
454 
455 		// Sort the new wants by reverse commit time.
456 		Collections.sort(newWantsByNewest, ORDER_BY_REVERSE_TIMESTAMP);
457 		return new CommitSelectionHelper(newWants, commits, pos,
458 				newWantsByNewest, reuse, reuseCommits);
459 	}
460 
461 	/*-
462 	 * Returns the desired distance to the next bitmap based on the distance
463 	 * from the tip commit. Only differentiates recent from distant spans,
464 	 * selectCommits() handles the contiguous commits at the tip for active
465 	 * or inactive branches.
466 	 *
467 	 * A graph of this function looks like this, where
468 	 * the X axis is the distance from the tip commit and the Y axis is the
469 	 * bitmap selection distance.
470 	 *
471 	 * 5000                ____...
472 	 *                    /
473 	 *                  /
474 	 *                /
475 	 *              /
476 	 *  100  _____/
477 	 *       0  20100  25000
478 	 *
479 	 * Linear scaling between 20100 and 25000 prevents spans >100 for distances
480 	 * <20000 (otherwise, a span of 5000 would be returned for a distance of
481 	 * 21000, and the range 16000-20000 would have no selections).
482 	 */
483 	int nextSpan(int distanceFromTip) {
484 		if (distanceFromTip < 0) {
485 			throw new IllegalArgumentException();
486 		}
487 
488 		// Commits more toward the start will have more bitmaps.
489 		if (distanceFromTip <= recentCommitCount) {
490 			return recentCommitSpan;
491 		}
492 
493 		int next = Math.min(distanceFromTip - recentCommitCount,
494 				distantCommitSpan);
495 		return Math.max(next, recentCommitSpan);
496 	}
497 
498 	BitmapWalker newBitmapWalker() {
499 		return new BitmapWalker(
500 				new ObjectWalk(reader), bitmapIndex, null);
501 	}
502 
503 	/**
504 	 * A commit object for which a bitmap index should be built.
505 	 */
506 	static final class BitmapCommit extends ObjectId {
507 		private final boolean reuseWalker;
508 		private final int flags;
509 
510 		BitmapCommit(AnyObjectId objectId, boolean reuseWalker, int flags) {
511 			super(objectId);
512 			this.reuseWalker = reuseWalker;
513 			this.flags = flags;
514 		}
515 
516 		boolean isReuseWalker() {
517 			return reuseWalker;
518 		}
519 
520 		int getFlags() {
521 			return flags;
522 		}
523 	}
524 
525 	/**
526 	 * Container for state used in the first phase of selecting commits, which
527 	 * walks all of the reachable commits via the branch tips that are not
528 	 * covered by a previous pack's bitmaps ({@code newWants}) and stores them
529 	 * in {@code newCommitsByOldest}. {@code newCommitsByOldest} is initialized
530 	 * with an expected size of all commits, but may be smaller if some commits
531 	 * are unreachable and/or some commits are covered by a previous pack's
532 	 * bitmaps. {@code commitStartPos} will contain a positive offset to either
533 	 * the root commit or the oldest commit not covered by previous bitmaps.
534 	 */
535 	private static final class CommitSelectionHelper implements Iterable<RevCommit> {
536 		final Set<? extends ObjectId> newWants;
537 
538 		final List<RevCommit> newWantsByNewest;
539 		final BitmapBuilder reusedCommitsBitmap;
540 
541 		final List<BitmapCommit> reusedCommits;
542 
543 		final RevCommit[] newCommitsByOldest;
544 
545 		final int newCommitStartPos;
546 
547 		CommitSelectionHelper(Set<? extends ObjectId> newWants,
548 				RevCommit[] commitsByOldest, int commitStartPos,
549 				List<RevCommit> newWantsByNewest,
550 				BitmapBuilder reusedCommitsBitmap,
551 				List<BitmapCommit> reuse) {
552 			this.newWants = newWants;
553 			this.newCommitsByOldest = commitsByOldest;
554 			this.newCommitStartPos = commitStartPos;
555 			this.newWantsByNewest = newWantsByNewest;
556 			this.reusedCommitsBitmap = reusedCommitsBitmap;
557 			this.reusedCommits = reuse;
558 		}
559 
560 		@Override
561 		public Iterator<RevCommit> iterator() {
562 			// Member variables referenced by this iterator will have synthetic
563 			// accessors generated for them if they are made private.
564 			return new Iterator<RevCommit>() {
565 				int pos = newCommitStartPos;
566 
567 				@Override
568 				public boolean hasNext() {
569 					return pos < newCommitsByOldest.length;
570 				}
571 
572 				@Override
573 				public RevCommit next() {
574 					return newCommitsByOldest[pos++];
575 				}
576 
577 				@Override
578 				public void remove() {
579 					throw new UnsupportedOperationException();
580 				}
581 			};
582 		}
583 
584 		int getCommitCount() {
585 			return newCommitsByOldest.length - newCommitStartPos;
586 		}
587 	}
588 }