Example #1
0
    private void verifyPrerequisites() throws TransportException {
      if (prereqs.isEmpty()) return;

      final RevWalk rw = new RevWalk(local);
      final RevFlag PREREQ = rw.newFlag("PREREQ");
      final RevFlag SEEN = rw.newFlag("SEEN");

      final List<ObjectId> missing = new ArrayList<ObjectId>();
      final List<RevObject> commits = new ArrayList<RevObject>();
      for (final ObjectId p : prereqs) {
        try {
          final RevCommit c = rw.parseCommit(p);
          if (!c.has(PREREQ)) {
            c.add(PREREQ);
            commits.add(c);
          }
        } catch (MissingObjectException notFound) {
          missing.add(p);
        } catch (IOException err) {
          throw new TransportException(uri, "Cannot read commit " + p.name(), err);
        }
      }
      if (!missing.isEmpty()) throw new MissingBundlePrerequisiteException(uri, missing);

      for (final Ref r : local.getAllRefs().values()) {
        try {
          rw.markStart(rw.parseCommit(r.getObjectId()));
        } catch (IOException readError) {
          // If we cannot read the value of the ref skip it.
        }
      }

      int remaining = commits.size();
      try {
        RevCommit c;
        while ((c = rw.next()) != null) {
          if (c.has(PREREQ)) {
            c.add(SEEN);
            if (--remaining == 0) break;
          }
        }
      } catch (IOException err) {
        throw new TransportException(uri, "Cannot read object", err);
      }

      if (remaining > 0) {
        for (final RevObject o : commits) {
          if (!o.has(SEEN)) missing.add(o);
        }
        throw new MissingBundlePrerequisiteException(uri, missing);
      }
    }
  private void markReachable(final Set<ObjectId> have, final int maxTime) throws IOException {
    for (final Ref r : local.getAllRefs().values()) {
      try {
        final RevCommit o = walk.parseCommit(r.getObjectId());
        o.add(REACHABLE);
        reachableCommits.add(o);
      } catch (IOException readError) {
        // If we cannot read the value of the ref skip it.
      }
    }

    for (final ObjectId id : have) {
      try {
        final RevCommit o = walk.parseCommit(id);
        o.add(REACHABLE);
        reachableCommits.add(o);
      } catch (IOException readError) {
        // If we cannot read the value of the ref skip it.
      }
    }

    if (maxTime > 0) {
      // Mark reachable commits until we reach maxTime. These may
      // wind up later matching up against things we want and we
      // can avoid asking for something we already happen to have.
      //
      final Date maxWhen = new Date(maxTime * 1000L);
      walk.sort(RevSort.COMMIT_TIME_DESC);
      walk.markStart(reachableCommits);
      walk.setRevFilter(CommitTimeRevFilter.after(maxWhen));
      for (; ; ) {
        final RevCommit c = walk.next();
        if (c == null) break;
        if (c.has(ADVERTISED) && !c.has(COMMON)) {
          // This is actually going to be a common commit, but
          // our peer doesn't know that fact yet.
          //
          c.add(COMMON);
          c.carry(COMMON);
          reachableCommits.add(c);
        }
      }
    }
  }