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