public Optional read()

in src/main/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReader.java [59:110]


  public Optional<RevisionData> read(Project.NameKey project, ObjectId objectId, String refName)
      throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException,
          RepositoryNotFoundException, IOException {
    try (Repository git = gitRepositoryManager.openRepository(project)) {
      Long totalRefSize = 0l;

      ObjectLoader commitLoader = git.open(objectId);
      totalRefSize += commitLoader.getSize();
      verifySize(totalRefSize, commitLoader);

      if (commitLoader.getType() != Constants.OBJ_COMMIT) {
        repLog.trace(
            "Ref {} for project {} points to an object type {}",
            refName,
            project,
            commitLoader.getType());
        return Optional.empty();
      }

      RevCommit commit = RevCommit.parse(commitLoader.getCachedBytes());
      RevisionObjectData commitRev =
          new RevisionObjectData(commit.getType(), commitLoader.getCachedBytes());

      RevTree tree = commit.getTree();
      ObjectLoader treeLoader = git.open(commit.getTree().toObjectId());
      totalRefSize += treeLoader.getSize();
      verifySize(totalRefSize, treeLoader);

      RevisionObjectData treeRev =
          new RevisionObjectData(tree.getType(), treeLoader.getCachedBytes());

      List<RevisionObjectData> blobs = Lists.newLinkedList();
      try (TreeWalk walk = new TreeWalk(git)) {
        if (commit.getParentCount() > 0) {
          List<DiffEntry> diffEntries = readDiffs(git, commit, tree, walk);
          blobs = readBlobs(git, totalRefSize, diffEntries);
        } else {
          walk.setRecursive(true);
          walk.addTree(tree);
          blobs = readBlobs(git, totalRefSize, walk);
        }
      }
      return Optional.of(new RevisionData(commitRev, treeRev, blobs));
    } catch (LargeObjectException e) {
      repLog.trace(
          "Ref {} size for project {} is greater than configured '{}'",
          refName,
          project,
          CONFIG_MAX_API_PAYLOAD_SIZE);
      return Optional.empty();
    }
  }