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

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

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

Repository.newObjectReader介绍

[英]Create a new reader to read objects from #getObjectDatabase().
[中]

代码示例

代码示例来源:origin: gocd/gocd

private byte[] contentFromTree(RevTree tree) {
  try {
    final ObjectReader reader = gitRepo.newObjectReader();
    CanonicalTreeParser parser = new CanonicalTreeParser();
    parser.reset(reader, tree);
    String lastPath = null;
    while (true) {
      final String path = parser.getEntryPathString();
      parser = parser.next();
      if (path.equals(lastPath)) {
        break;
      }
      lastPath = path;
      if (path.equals(CRUISE_CONFIG_XML)) {
        final ObjectId id = parser.getEntryObjectId();
        final ObjectLoader loader = reader.open(id);
        return loader.getBytes();
      }
    }
    return null;
  } catch (IOException e) {
    LOGGER.error("Could not fetch content from the config repository found at path '{}'", workingDir.getAbsolutePath(), e);
    throw new RuntimeException("Error while fetching content from the config repository.", e);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create a new revision and object walker for a given repository.
 *
 * @param repo
 *            the repository the walker will obtain data from.
 */
public ObjectWalk(Repository repo) {
  this(repo.newObjectReader());
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create a new revision walker for a given repository.
 *
 * @param repo
 *            the repository the walker will obtain data from. An
 *            ObjectReader will be created by the walker, and will be closed
 *            when the walker is closed.
 */
public RevWalk(Repository repo) {
  this(repo.newObjectReader(), true);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create writer for specified repository.
 * <p>
 * Objects for packing are specified in {@link #preparePack(Iterator)} or
 * {@link #preparePack(ProgressMonitor, Set, Set)}.
 *
 * @param repo
 *            repository where objects are stored.
 */
public PackWriter(Repository repo) {
  this(repo, repo.newObjectReader());
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create a new tree walker for a given repository.
 *
 * @param repo
 *            the repository the walker will obtain data from. An
 *            ObjectReader will be created by the walker, and will be closed
 *            when the walker is closed.
 */
public TreeWalk(Repository repo) {
  this(repo, repo.newObjectReader(), true);
}

代码示例来源:origin: git-commit-id/maven-git-commit-id-plugin

@Override
public void init() throws GitCommitIdExecutionException {
 git = getGitRepository();
 objectReader = git.newObjectReader();
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private static byte[] read(Repository db, AnyObjectId blobId)
    throws MissingObjectException, IncorrectObjectTypeException,
    IOException {
  try (ObjectReader or = db.newObjectReader()) {
    return read(or, blobId);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create a new rename detector for the given repository
 *
 * @param repo
 *            the repository to use for rename detection
 */
public RenameDetector(Repository repo) {
  this(repo.newObjectReader(), repo.getConfig().get(DiffConfig.KEY));
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Set the repository the formatter can load object contents from.
 *
 * Once a repository has been set, the formatter must be released to ensure
 * the internal ObjectReader is able to release its resources.
 *
 * @param repository
 *            source repository holding referenced objects.
 */
public void setRepository(Repository repository) {
  this.repository = repository;
  setReader(repository.newObjectReader(), repository.getConfig(), true);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

@Nullable
private ObjectId resolveAbbreviation(String revstr) throws IOException,
    AmbiguousObjectException {
  AbbreviatedObjectId id = AbbreviatedObjectId.fromString(revstr);
  try (ObjectReader reader = newObjectReader()) {
    Collection<ObjectId> matches = reader.resolve(id);
    if (matches.size() == 0)
      return null;
    else if (matches.size() == 1)
      return matches.iterator().next();
    else
      throw new AmbiguousObjectException(id, matches);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private PackWriter newPackWriter() {
  PackConfig pc = packConfig;
  if (pc == null) {
    pc = db != null ? new PackConfig(db) : new PackConfig();
  }
  return new PackWriter(pc, reader != null ? reader : db.newObjectReader());
}

代码示例来源:origin: apache/incubator-gobblin

ObjectReader reader = this.git.getRepository().newObjectReader();
CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
oldTreeIter.reset(reader, oldHeadTree);

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private static byte[] read(Repository db, AnyObjectId treeish, String path)
    throws MissingObjectException, IncorrectObjectTypeException,
    IOException {
  try (ObjectReader or = db.newObjectReader()) {
    TreeWalk tree = TreeWalk.forPath(or, path, asTree(or, treeish));
    if (tree == null)
      throw new FileNotFoundException(MessageFormat.format(JGitText
          .get().entryNotFoundByPath, path));
    return read(or, tree.getObjectId(0));
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

void load() throws IOException {
  close();
  reader = db.newObjectReader();
  Ref ref = db.getRefDatabase().exactRef(REF_NAME);
  if (ref == null) {
    // No ref, same as empty.
    return;
  }
  try (RevWalk rw = new RevWalk(reader)) {
    commit = rw.parseCommit(ref.getObjectId());
  }
}

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

private static AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException {
  // from the commit we can build the tree which allows us to construct the TreeParser
  //noinspection Duplicates
  try (RevWalk walk = new RevWalk(repository)) {
    RevCommit commit = walk.parseCommit(repository.resolve(objectId));
    RevTree tree = walk.parseTree(commit.getTree().getId());
    CanonicalTreeParser treeParser = new CanonicalTreeParser();
    try (ObjectReader reader = repository.newObjectReader()) {
      treeParser.reset(reader, tree.getId());
    }
    walk.dispose();
    return treeParser;
  }
}

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

private static AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException {
  // from the commit we can build the tree which allows us to construct the TreeParser
  //noinspection Duplicates
  try (RevWalk walk = new RevWalk(repository)) {
    RevCommit commit = walk.parseCommit(repository.resolve(objectId));
    RevTree tree = walk.parseTree(commit.getTree().getId());
    CanonicalTreeParser treeParser = new CanonicalTreeParser();
    try (ObjectReader reader = repository.newObjectReader()) {
      treeParser.reset(reader, tree.getId());
    }
    walk.dispose();
    return treeParser;
  }
}

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

private static AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException {
    // from the commit we can build the tree which allows us to construct the TreeParser
    //noinspection Duplicates
    try (RevWalk walk = new RevWalk(repository)) {
      RevCommit commit = walk.parseCommit(repository.resolve(objectId));
      RevTree tree = walk.parseTree(commit.getTree().getId());

      CanonicalTreeParser treeParser = new CanonicalTreeParser();
      try (ObjectReader reader = repository.newObjectReader()) {
        treeParser.reset(reader, tree.getId());
      }

      walk.dispose();

      return treeParser;
    }
  }
}

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

private static AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException {
    // from the commit we can build the tree which allows us to construct the TreeParser
    //noinspection Duplicates
    try (RevWalk walk = new RevWalk(repository)) {
      RevCommit commit = walk.parseCommit(ObjectId.fromString(objectId));
      RevTree tree = walk.parseTree(commit.getTree().getId());

      CanonicalTreeParser treeParser = new CanonicalTreeParser();
      try (ObjectReader reader = repository.newObjectReader()) {
        treeParser.reset(reader, tree.getId());
      }

      walk.dispose();

      return treeParser;
    }
  }
}

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

private static AbstractTreeIterator prepareTreeParser(Repository repository, String ref) throws IOException {
    // from the commit we can build the tree which allows us to construct the TreeParser
    Ref head = repository.exactRef(ref);
    try (RevWalk walk = new RevWalk(repository)) {
      RevCommit commit = walk.parseCommit(head.getObjectId());
      RevTree tree = walk.parseTree(commit.getTree().getId());

      CanonicalTreeParser treeParser = new CanonicalTreeParser();
      try (ObjectReader reader = repository.newObjectReader()) {
        treeParser.reset(reader, tree.getId());
      }

      walk.dispose();

      return treeParser;
    }
  }
}

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

@Test
  public void testRevWalkDisposeClosesReader() throws IOException {
    try (Repository repo = CookbookHelper.openJGitCookbookRepository()) {
      try (ObjectReader reader = repo.newObjectReader()) {
        try (RevWalk walk = new RevWalk(reader)) {
          walk.dispose();

          Ref head = repo.exactRef("refs/heads/master");
          System.out.println("Found head: " + head);

          ObjectLoader loader = reader.open(head.getObjectId());
          assertNotNull(loader);
        }
      }
    }
  }
}

相关文章

Repository类方法