FixUninterestingGenerator.java

  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. package org.eclipse.jgit.revwalk;

  12. import java.io.IOException;

  13. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  14. import org.eclipse.jgit.errors.MissingObjectException;

  15. /**
  16.  * Filters out commits marked {@link RevWalk#UNINTERESTING}.
  17.  * <p>
  18.  * This generator is only in front of another generator that has fully buffered
  19.  * commits, such that we are called only after the {@link PendingGenerator} has
  20.  * exhausted its input queue and given up. It skips over any uninteresting
  21.  * commits that may have leaked out of the PendingGenerator due to clock skew
  22.  * being detected in the commit objects.
  23.  */
  24. final class FixUninterestingGenerator extends Generator {
  25.     private final Generator pending;

  26.     FixUninterestingGenerator(Generator g) {
  27.         super(g.firstParent);
  28.         pending = g;
  29.     }

  30.     @Override
  31.     int outputType() {
  32.         return pending.outputType();
  33.     }

  34.     @Override
  35.     RevCommit next() throws MissingObjectException,
  36.             IncorrectObjectTypeException, IOException {
  37.         for (;;) {
  38.             final RevCommit c = pending.next();
  39.             if (c == null)
  40.                 return null;
  41.             if ((c.flags & RevWalk.UNINTERESTING) == 0)
  42.                 return c;
  43.         }
  44.     }
  45. }