private Optional<NodeRef> parseID(ObjectId commitId, String path, GeoGIG geogig) {
    Optional<RevObject> object = geogig.command(RevObjectParse.class).setObjectId(commitId).call();
    RevCommit commit = null;
    if (object.isPresent() && object.get() instanceof RevCommit) {
      commit = (RevCommit) object.get();
    } else {
      throw new CommandSpecException(
          "Couldn't resolve id: " + commitId.toString() + " to a commit");
    }

    object = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call();

    if (object.isPresent()) {
      RevTree tree = (RevTree) object.get();
      return geogig.command(FindTreeChild.class).setParent(tree).setChildPath(path).call();
    } else {
      throw new CommandSpecException("Couldn't resolve commit's treeId");
    }
  }
Пример #2
0
    public void print(RevCommit commit) throws IOException {

      StringBuilder sb = new StringBuilder();
      sb.append("commit ").append(commit.getId().toString()).append('\n');
      sb.append("tree ").append(commit.getTreeId().toString()).append('\n');
      sb.append("parent");
      for (ObjectId parentId : commit.getParentIds()) {
        sb.append(' ').append(parentId.toString());
      }
      sb.append('\n');
      sb.append("author ").append(format(commit.getAuthor())).append('\n');
      sb.append("committer ").append(format(commit.getCommitter())).append('\n');

      if (commit.getMessage() != null) {
        sb.append("message\n");
        sb.append("\t" + commit.getMessage().replace("\n", "\n\t"));
        sb.append('\n');
      }
      if (showChanges) {
        Iterator<DiffEntry> diff =
            geogig
                .command(DiffOp.class)
                .setOldVersion(commit.parentN(0).or(ObjectId.NULL))
                .setNewVersion(commit.getId())
                .call();
        DiffEntry diffEntry;
        sb.append("changes\n");
        while (diff.hasNext()) {
          diffEntry = diff.next();
          String path = diffEntry.newPath() != null ? diffEntry.newPath() : diffEntry.oldPath();
          sb.append('\t')
              .append(path)
              .append(' ')
              .append(diffEntry.oldObjectId().toString())
              .append(' ')
              .append(diffEntry.newObjectId().toString())
              .append('\n');
        }
      }
      console.println(sb.toString());
    }