Beispiel #1
0
  /**
   * Mark an object to not produce in the output.
   *
   * <p>Uninteresting objects denote not just themselves but also their entire reachable chain, back
   * until the merge base of an uninteresting commit and an otherwise interesting commit.
   *
   * <p>Callers are encouraged to use {@link RevWalk#parseAny(AnyObjectId)} instead of {@link
   * RevWalk#lookupAny(AnyObjectId, int)}, as this method requires the object to be parsed before it
   * can be added as a root for the traversal.
   *
   * <p>The method will automatically parse an unparsed object, but error handling may be more
   * difficult for the application to explain why a RevObject is not actually valid. The object pool
   * of this walker would also be 'poisoned' by the invalid RevObject.
   *
   * <p>This method will automatically call {@link RevWalk#markStart(RevCommit)} if passed RevCommit
   * instance, or a RevTag that directly (or indirectly) references a RevCommit.
   *
   * @param o the object to start traversing from. The object passed must be
   * @throws MissingObjectException the object supplied is not available from the object database.
   *     This usually indicates the supplied object is invalid, but the reference was constructed
   *     during an earlier invocation to {@link RevWalk#lookupAny(AnyObjectId, int)}.
   * @throws IncorrectObjectTypeException the object was not parsed yet and it was discovered during
   *     parsing that it is not actually the type of the instance passed in. This usually indicates
   *     the caller used the wrong type in a {@link RevWalk#lookupAny(AnyObjectId, int)} call.
   * @throws IOException a pack file or loose object could not be read.
   */
  public void markUninteresting(RevObject o)
      throws MissingObjectException, IncorrectObjectTypeException, IOException {
    while (o instanceof RevTag) {
      o.flags |= UNINTERESTING;
      if (hasRevSort(RevSort.BOUNDARY)) addObject(o);
      o = ((RevTag) o).getObject();
      parseHeaders(o);
    }

    if (o instanceof RevCommit) super.markUninteresting((RevCommit) o);
    else if (o instanceof RevTree) markTreeUninteresting((RevTree) o);
    else o.flags |= UNINTERESTING;

    if (o.getType() != Constants.OBJ_COMMIT && hasRevSort(RevSort.BOUNDARY)) {
      addObject(o);
    }
  }
Beispiel #2
0
  /**
   * Pop the next most recent object.
   *
   * @return next most recent object; null if traversal is over.
   * @throws MissingObjectException one or or more of the next objects are not available from the
   *     object database, but were thought to be candidates for traversal. This usually indicates a
   *     broken link.
   * @throws IncorrectObjectTypeException one or or more of the objects in a tree do not match the
   *     type indicated.
   * @throws IOException a pack file or loose object could not be read.
   */
  public RevObject nextObject()
      throws MissingObjectException, IncorrectObjectTypeException, IOException {
    if (last != null) treeWalk = last instanceof RevTree ? enter(last) : treeWalk.next();

    while (!treeWalk.eof()) {
      final FileMode mode = treeWalk.getEntryFileMode();
      switch (mode.getObjectType()) {
        case Constants.OBJ_BLOB:
          {
            treeWalk.getEntryObjectId(idBuffer);
            final RevBlob o = lookupBlob(idBuffer);
            if ((o.flags & SEEN) != 0) break;
            o.flags |= SEEN;
            if (shouldSkipObject(o)) break;
            last = o;
            return o;
          }
        case Constants.OBJ_TREE:
          {
            treeWalk.getEntryObjectId(idBuffer);
            final RevTree o = lookupTree(idBuffer);
            if ((o.flags & SEEN) != 0) break;
            o.flags |= SEEN;
            if (shouldSkipObject(o)) break;
            last = o;
            return o;
          }
        default:
          if (FileMode.GITLINK.equals(mode)) break;
          treeWalk.getEntryObjectId(idBuffer);
          throw new CorruptObjectException(
              MessageFormat.format(
                  JGitText.get().corruptObjectInvalidMode3,
                  mode,
                  idBuffer.name(),
                  treeWalk.getEntryPathString(),
                  currentTree.name()));
      }

      treeWalk = treeWalk.next();
    }

    last = null;
    for (; ; ) {
      final RevObject o = pendingObjects.next();
      if (o == null) return null;
      if ((o.flags & SEEN) != 0) continue;
      o.flags |= SEEN;
      if (shouldSkipObject(o)) continue;
      if (o instanceof RevTree) {
        currentTree = (RevTree) o;
        treeWalk = treeWalk.resetRoot(db, currentTree, curs);
      }
      return o;
    }
  }
Beispiel #3
0
 private void addObject(final RevObject o) {
   if ((o.flags & IN_PENDING) == 0) {
     o.flags |= IN_PENDING;
     pendingObjects.add(o);
   }
 }