/** * Get the common base commit between the given revisions. * * @param repository * @param revisions * @return base commit or null if none */ public static RevCommit getBase(final Repository repository, final String... revisions) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (revisions == null) throw new IllegalArgumentException( Assert.formatNotNull("Revisions")); if (revisions.length == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Revisions")); final int length = revisions.length; final ObjectId[] commits = new ObjectId[length]; for (int i = 0; i < length; i++) { commits[i] = strictResolve(repository, revisions[i]); } return walkToBase(repository, commits); }
/** * Get raw contents of the blob at the given path in the commit that the * revision references. * * @param repository * @param revision * @param path * @return raw content or null if no blob with path at given revision */ public static byte[] getRawContent(final Repository repository, final String revision, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (revision == null) throw new IllegalArgumentException(Assert.formatNotNull("Revision")); if (revision.length() == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Revision")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Path")); final RevCommit commit = CommitUtils.parse(repository, CommitUtils.strictResolve(repository, revision)); return getBytes(repository, commit, path); }
/** * Get the id of the tree at the path in the given revision * * @param repository * @param revision * @param path * @return tree id or null if no tree id at path */ public static ObjectId getId(final Repository repository, final String revision, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (revision == null) throw new IllegalArgumentException(Assert.formatNotNull("Revision")); if (revision.length() == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Revision")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotNull("Path")); final RevCommit commit = CommitUtils.parse(repository, CommitUtils.strictResolve(repository, revision)); return lookupId(repository, commit, path); }
/** * Get the id of the blob at the path in the commit that the given revision * references. * * @param repository * @param revision * @param path * @return blob id */ public static ObjectId getId(final Repository repository, final String revision, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (revision == null) throw new IllegalArgumentException(Assert.formatNotNull("Revision")); if (revision.length() == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Revision")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Path")); final RevCommit commit = CommitUtils.parse(repository, CommitUtils.strictResolve(repository, revision)); return lookupId(repository, commit, path); }
CommitUtils.strictResolve(repository, revision)); final ObjectId blobId = lookupId(repository, commit, path); if (blobId == null)
/** * Create a tree walk with all the trees from the given revision's commit * parents. * * @param repository * @param revision * @return tree walk */ public static TreeWalk withParents(final Repository repository, final String revision) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (revision == null) throw new IllegalArgumentException(Assert.formatNotNull("Revision")); if (revision.length() == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Revision")); final ObjectId commit = CommitUtils.strictResolve(repository, revision); final ObjectReader reader = repository.newObjectReader(); final RevWalk walk = new RevWalk(reader); try { return withParents(reader, walk, walk.parseCommit(commit)); } catch (IOException e) { walk.close(); throw new GitException(e, repository); } }
try { walk.markStart(walk .parseCommit(strictResolve(repository, revision))); walk.setTreeFilter(PathFilterUtils.and(path)); return walk.next();