org.eclipse.jgit.lib.Repository.open()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中org.eclipse.jgit.lib.Repository.open方法的一些代码示例,展示了Repository.open的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.open方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:open

Repository.open介绍

[英]Open an object from this repository.

This is a one-shot call interface which may be faster than allocating a #newObjectReader() to perform the lookup.
[中]从该存储库中打开一个对象。
这是一个一次性调用接口,可能比分配#newObjectReader()来执行查找更快。

代码示例

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      ObjectId revId = repository.resolve(Constants.HEAD);
      try (TreeWalk treeWalk = new TreeWalk(repository)) {
        try (RevWalk revWalk = new RevWalk(repository)) {
          treeWalk.addTree(revWalk.parseTree(revId));

          while (treeWalk.next())
          {
            System.out.println("---------------------------");
            System.out.append("name: ").println(treeWalk.getNameString());
            System.out.append("path: ").println(treeWalk.getPathString());

            ObjectLoader loader = repository.open(treeWalk.getObjectId(0));

            System.out.append("directory: ").println(loader.getType()
                == Constants.OBJ_TREE);
            System.out.append("size: ").println(loader.getSize());
          }
        }
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      ObjectId revId = repository.resolve(Constants.HEAD);
      try (TreeWalk treeWalk = new TreeWalk(repository)) {
        try (RevWalk revWalk = new RevWalk(repository)) {
          treeWalk.addTree(revWalk.parseTree(revId));

          while (treeWalk.next())
          {
            System.out.println("---------------------------");
            System.out.append("name: ").println(treeWalk.getNameString());
            System.out.append("path: ").println(treeWalk.getPathString());

            ObjectLoader loader = repository.open(treeWalk.getObjectId(0));

            System.out.append("directory: ").println(loader.getType()
                == Constants.OBJ_TREE);
            System.out.append("size: ").println(loader.getSize());
          }
        }
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        List<Note> call = git.notesList().call();
        System.out.println("Listing " + call.size() + " notes");
        for (Note note : call) {
          System.out.println("Note: " + note + " " + note.getName() + " " + note.getData().getName() + "\nContent: ");

          // displaying the contents of the note is done via a simple blob-read
          ObjectLoader loader = repository.open(note.getData());
          loader.copyTo(System.out);
        }
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        List<Note> call = git.notesList().call();
        System.out.println("Listing " + call.size() + " notes");
        for (Note note : call) {
          System.out.println("Note: " + note + " " + note.getName() + " " + note.getData().getName() + "\nContent: ");

          // displaying the contents of the note is done via a simple blob-read
          ObjectLoader loader = repository.open(note.getData());
          loader.copyTo(System.out);
        }
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static int countLinesOfFileInCommit(Repository repository, ObjectId commitID, String name) throws IOException {
    try (RevWalk revWalk = new RevWalk(repository)) {
      RevCommit commit = revWalk.parseCommit(commitID);
      RevTree tree = commit.getTree();
      System.out.println("Having tree: " + tree);

      // now try to find a specific file
      try (TreeWalk treeWalk = new TreeWalk(repository)) {
        treeWalk.addTree(tree);
        treeWalk.setRecursive(true);
        treeWalk.setFilter(PathFilter.create(name));
        if (!treeWalk.next()) {
          throw new IllegalStateException("Did not find expected file 'README.md'");
        }

        ObjectId objectId = treeWalk.getObjectId(0);
        ObjectLoader loader = repository.open(objectId);

        // load the content of the file into a stream
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        loader.copyTo(stream);

        revWalk.dispose();

        return IOUtils.readLines(new ByteArrayInputStream(stream.toByteArray()), "UTF-8").size();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static int countLinesOfFileInCommit(Repository repository, ObjectId commitID, String name) throws IOException {
    try (RevWalk revWalk = new RevWalk(repository)) {
      RevCommit commit = revWalk.parseCommit(commitID);
      RevTree tree = commit.getTree();
      System.out.println("Having tree: " + tree);

      // now try to find a specific file
      try (TreeWalk treeWalk = new TreeWalk(repository)) {
        treeWalk.addTree(tree);
        treeWalk.setRecursive(true);
        treeWalk.setFilter(PathFilter.create(name));
        if (!treeWalk.next()) {
          throw new IllegalStateException("Did not find expected file 'README.md'");
        }

        ObjectId objectId = treeWalk.getObjectId(0);
        ObjectLoader loader = repository.open(objectId);

        // load the content of the file into a stream
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        loader.copyTo(stream);

        revWalk.dispose();

        return IOUtils.readLines(new ByteArrayInputStream(stream.toByteArray()), "UTF-8").size();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      // the Ref holds an ObjectId for any type of object (tree, commit, blob, tree)
      Ref head = repository.exactRef("refs/heads/master");
      System.out.println("Ref of refs/heads/master: " + head);

      System.out.println("\nPrint contents of head of master branch, i.e. the latest commit information");
      ObjectLoader loader = repository.open(head.getObjectId());
      loader.copyTo(System.out);

      System.out.println("\nPrint contents of tree of head of master branch, i.e. the latest binary tree information");

      // a commit points to a tree
      try (RevWalk walk = new RevWalk(repository)) {
        RevCommit commit = walk.parseCommit(head.getObjectId());
        RevTree tree = walk.parseTree(commit.getTree().getId());
        System.out.println("Found Tree: " + tree);
        loader = repository.open(tree.getId());
        loader.copyTo(System.out);

        walk.dispose();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      // the Ref holds an ObjectId for any type of object (tree, commit, blob, tree)
      Ref head = repository.exactRef("refs/heads/master");
      System.out.println("Ref of refs/heads/master: " + head);

      System.out.println("\nPrint contents of head of master branch, i.e. the latest commit information");
      ObjectLoader loader = repository.open(head.getObjectId());
      loader.copyTo(System.out);

      System.out.println("\nPrint contents of tree of head of master branch, i.e. the latest binary tree information");

      // a commit points to a tree
      try (RevWalk walk = new RevWalk(repository)) {
        RevCommit commit = walk.parseCommit(head.getObjectId());
        RevTree tree = walk.parseTree(commit.getTree().getId());
        System.out.println("Found Tree: " + tree);
        loader = repository.open(tree.getId());
        loader.copyTo(System.out);

        walk.dispose();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

ObjectLoader loader = repository.open(note.getData());
loader.copyTo(System.out);

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      // a RevWalk allows to retrieve information from the repository
      try (RevWalk walk = new RevWalk(repository)) {
        // a simple tag that is not annotated
        Ref simpleTag = repository.findRef("initialtag");
        RevObject any = walk.parseAny(simpleTag.getObjectId());
        System.out.println("Commit: " + any);

        // an annotated tag
        Ref annotatedTag = repository.findRef("secondtag");
        any = walk.parseAny(annotatedTag.getObjectId());
        System.out.println("Tag: " + any);

        // finally try to print out the tag-content
        System.out.println("\nTag-Content: \n");
        ObjectLoader loader = repository.open(annotatedTag.getObjectId());
        loader.copyTo(System.out);

        walk.dispose();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

ObjectLoader loader = repository.open(note.getData());
loader.copyTo(System.out);

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      // a RevWalk allows to retrieve information from the repository
      try (RevWalk walk = new RevWalk(repository)) {
        // a simple tag that is not annotated
        Ref simpleTag = repository.findRef("initialtag");
        RevObject any = walk.parseAny(simpleTag.getObjectId());
        System.out.println("Commit: " + any);

        // an annotated tag
        Ref annotatedTag = repository.findRef("secondtag");
        any = walk.parseAny(annotatedTag.getObjectId());
        System.out.println("Tag: " + any);

        // finally try to print out the tag-content
        System.out.println("\nTag-Content: \n");
        ObjectLoader loader = repository.open(annotatedTag.getObjectId());
        loader.copyTo(System.out);

        walk.dispose();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static void printFile(Repository repository, RevTree tree) throws IOException {
  // now try to find a specific file
  try (TreeWalk treeWalk = new TreeWalk(repository)) {
    treeWalk.addTree(tree);
    treeWalk.setRecursive(false);
    treeWalk.setFilter(PathFilter.create("README.md"));
    if (!treeWalk.next()) {
      throw new IllegalStateException("Did not find expected file 'README.md'");
    }
    // FileMode specifies the type of file, FileMode.REGULAR_FILE for normal file, FileMode.EXECUTABLE_FILE for executable bit
// set
    FileMode fileMode = treeWalk.getFileMode(0);
    ObjectLoader loader = repository.open(treeWalk.getObjectId(0));
    System.out.println("README.md: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode +
        " size: " + loader.getSize());
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static void printFile(Repository repository, RevTree tree) throws IOException {
  // now try to find a specific file
  try (TreeWalk treeWalk = new TreeWalk(repository)) {
    treeWalk.addTree(tree);
    treeWalk.setRecursive(false);
    treeWalk.setFilter(PathFilter.create("README.md"));
    if (!treeWalk.next()) {
      throw new IllegalStateException("Did not find expected file 'README.md'");
    }
    // FileMode specifies the type of file, FileMode.REGULAR_FILE for normal file, FileMode.EXECUTABLE_FILE for executable bit
// set
    FileMode fileMode = treeWalk.getFileMode(0);
    ObjectLoader loader = repository.open(treeWalk.getObjectId(0));
    System.out.println("README.md: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode +
        " size: " + loader.getSize());
  }
}

代码示例来源:origin: centic9/jgit-cookbook

ObjectLoader loader = repository.open(objectId);

代码示例来源:origin: centic9/jgit-cookbook

ObjectLoader loader = repository.open(objectId);

代码示例来源:origin: io.macgyver/macgyver-plugin-git

@Override
public InputStream openInputStream() throws IOException {
  GitResourceProvider p = getGitResourceProvider();
  ObjectLoader loader = p.repo.open(id, Constants.OBJ_BLOB);
  return loader.openStream();
}

代码示例来源:origin: indeedeng/proctor

private <C> C getFileContents(final Class<C> c,
    final ObjectId blobId) throws IOException {
  final ObjectLoader loader = git.getRepository().open(blobId);
  final ObjectMapper mapper = Serializers.lenient();
  return mapper.readValue(loader.getBytes(), c);
}

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

/**
 * Pulls the text form a Note object and writes it to the passes Outputstream.
 *
 * @param note   - The Note contained in the repository to read.
 * @param output - The stream to ouput the note text.
 * @throws IOException - failed.
 */
public void writeNote(final Note note, final OutputStream output) throws IOException {
  if (!isUndefined()) {
    git.getRepository().open(note.getData()).copyTo(output);
  }
}

代码示例来源:origin: ModeShape/modeshape

@Override
public ExternalBinaryValue getBinaryValue( String id ) {
  try {
    ObjectId fileObjectId = ObjectId.fromString(id);
    ObjectLoader fileLoader = repository.open(fileObjectId);
    return new GitBinaryValue(fileObjectId, fileLoader, getSourceName(), null, getMimeTypeDetector());
  } catch (IOException e) {
    throw new DocumentStoreException(id, e);
  }
}

相关文章

Repository类方法