/** * Create a pattern find commit filter * * @param pattern * @param flags */ public PatternFindCommitFilter(final String pattern, final int flags) { if (pattern == null) throw new IllegalArgumentException(Assert.formatNotNull("Pattern")); if (pattern.length() == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Pattern")); this.pattern = pattern; this.flags = flags; matcher = Pattern.compile(pattern, flags).matcher(""); }
/** * Create a repository service for the specified repositories. * * @param repositories */ public RepositoryService(final Repository... repositories) { if (repositories == null) throw new IllegalArgumentException( Assert.formatNotNull("Repositories")); if (repositories.length == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Repositories")); this.repositories = new Repository[repositories.length]; System.arraycopy(repositories, 0, this.repositories, 0, repositories.length); }
/** * Create a diff filter that affects all the given paths * * @param paths * @return tree filter for diffs affecting given paths */ public static TreeFilter and(final String... paths) { if (paths == null) throw new IllegalArgumentException(Assert.formatNotNull("Paths")); if (paths.length == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Paths")); return andDiff(paths(paths)); }
/** * Create a repository service for the repositories at the specified * directories. * * @param gitDirs */ public RepositoryService(final File... gitDirs) { if (gitDirs == null) throw new IllegalArgumentException( Assert.formatNotNull("Directories")); if (gitDirs.length == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Directories")); final int length = gitDirs.length; repositories = new Repository[length]; try { for (int i = 0; i < length; i++) repositories[i] = new FileRepository(gitDirs[i]); } catch (IOException e) { throw new IllegalArgumentException(e); } }
/** * Create a repository service for the repositories at the specified * directory paths. * * @param gitDirs */ public RepositoryService(final String... gitDirs) { if (gitDirs == null) throw new IllegalArgumentException( Assert.formatNotNull("Directories")); if (gitDirs.length == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Directories")); final int length = gitDirs.length; repositories = new Repository[length]; try { for (int i = 0; i < length; i++) repositories[i] = new FileRepository(gitDirs[i]); } catch (IOException e) { throw new IllegalArgumentException(e); } }
/** * Create a diff filter that affects any of the given paths * * @param paths * @return tree filter for diffs affecting given paths */ public static TreeFilter or(final String... paths) { if (paths == null) throw new IllegalArgumentException(Assert.formatNotNull("Paths")); if (paths.length == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Paths")); return AndTreeFilter.create(group(paths), ANY_DIFF); }
/** * Create a diff filter affecting all of the given path suffixes * * @param suffixes * @return tree filter for diffs affecting given suffixes */ public static TreeFilter andSuffix(final String... suffixes) { if (suffixes == null) throw new IllegalArgumentException(Assert.formatNotNull("Suffixes")); if (suffixes.length == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Suffixes")); return andDiff(suffix(suffixes)); }
/** * Create a diff filter affecting any of the given path suffixes * * @param suffixes * @return tree filter for diffs affecting given suffixes */ public static TreeFilter orSuffix(final String... suffixes) { if (suffixes == null) throw new IllegalArgumentException(Assert.formatNotNull("Suffixes")); if (suffixes.length == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Suffixes")); return orDiff(suffix(suffixes)); } }
/** * Get the common base commit of the given commits. * * @param repository * @param commits * @return base commit or null if none */ public static RevCommit getBase(final Repository repository, final ObjectId... commits) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commits == null) throw new IllegalArgumentException(Assert.formatNotNull("Commits")); if (commits.length == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Commits")); return walkToBase(repository, commits); }
/** * Get the commit that the given name references. * * @param repository * @param refName * @return commit, may be null */ public static RevCommit getRef(final Repository repository, final String refName) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (refName == null) throw new IllegalArgumentException(Assert.formatNotNull("Ref name")); if (refName.length() == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Ref name")); Ref ref; ref = repository.getAllRefs().get(refName); return ref != null ? lookupRef(repository, ref) : null; }
/** * 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 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); }
/** * Get the commit that the revision references. * * @param repository * @param revision * @return commit */ public static RevCommit getCommit(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")); ObjectId commitId = resolve(repository, revision); if (commitId == null) { return null; } return parse(repository, commitId); }
/** * Get the raw contents of the blob in the commit located at the given path. * * @param repository * @param commitId * @param path * @return raw content or null if no blob with path at given commit */ public static byte[] getRawContent(final Repository repository, final ObjectId commitId, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commitId == null) throw new IllegalArgumentException( Assert.formatNotNull("Commit id")); 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, commitId); return getBytes(repository, commit, path); }
/** * Get the id of the blob at the path in the commit that the given revision * references. * * @param repository * @param commitId * @param path * @return blob id */ public static ObjectId getId(final Repository repository, final ObjectId commitId, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commitId == null) throw new IllegalArgumentException( Assert.formatNotNull("Commit id")); 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, commitId); return lookupId(repository, commit, path); }
/** * 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 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); }
/** * Create a tree walk configured with the given commits * * @param repository * @param commits * @return tree walk */ public static TreeWalk withCommits(final Repository repository, final ObjectId... commits) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commits == null) throw new IllegalArgumentException(Assert.formatNotNull("Commits")); if (commits.length == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Commits")); final TreeWalk walk = new TreeWalk(repository); try { for (ObjectId commit : commits) walk.addTree(CommitUtils.getCommit(repository, commit) .getTree()); } catch (IOException e) { throw new GitException(e, repository); } return walk; }
/** * Create a tree walk configured with the given commit revisions * * @param repository * @param revisions * @return tree walk */ public static TreeWalk withCommits(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 TreeWalk walk = new TreeWalk(repository); try { for (String revision : revisions) walk.addTree(CommitUtils.getCommit(repository, revision) .getTree()); } catch (IOException e) { throw new GitException(e, repository); } return walk; }
/** * 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); } }