/** * Create cursor filter that retains last commit when not included by the * given filter. * * @param filter */ public CommitCursorFilter(final RevFilter filter) { if (filter == null) throw new IllegalArgumentException(Assert.formatNotNull("Filter")); this.filter = filter; }
/** * Create a date filter for a given date * * @param date * must be non-null */ public DateFilter(final Date date) { if (date == null) throw new IllegalArgumentException(Assert.formatNotNull("Date")); time = date.getTime(); }
/** * Check if any of the given objects are null * * @param objects * @return true if any object is null, false otherwise */ public static boolean anyNull(final Object... objects) { if (objects == null) throw new IllegalArgumentException(Assert.formatNotNull("Objects")); final int length = objects.length; for (int i = 0; i < length; i++) if (objects[i] == null) return true; return false; }
/** * Check if the all given objects are null. * * @param objects * @return true if both are null, false otherwise */ public static boolean allNull(final Object... objects) { if (objects == null) throw new IllegalArgumentException(Assert.formatNotNull("Objects")); final int length = objects.length; for (int i = 0; i < length; i++) if (objects[i] != null) return false; return true; }
/** * Get the commit for the given reference. * * @param repository * @param ref * @return commit, may be null */ public static RevCommit getRef(final Repository repository, final Ref ref) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (ref == null) throw new IllegalArgumentException(Assert.formatNotNull("Ref")); return lookupRef(repository, ref); }
/** * Get the commit with the given id * * @param repository * @param commitId * @return commit */ public static RevCommit getCommit(final Repository repository, final ObjectId commitId) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commitId == null) throw new IllegalArgumentException( Assert.formatNotNull("Commit id")); return parse(repository, commitId); }
/** * Get all the tag references in the given repository. * * @param repository * @return non-null but possibly array of branch reference names */ public static Collection<String> getTags(final Repository repository) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); return repository.getTags().keySet(); }
/** * 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); }
/** * 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 contents of the the blob with the given id as a UTF-8 * {@link String}. * * @param repository * @param id * @return content of blob as UTF-8 string */ public static String getContent(final Repository repository, final ObjectId id) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (id == null) throw new IllegalArgumentException( Assert.formatNotNull("Object id")); return toString(repository, getBytes(repository, id)); }
/** * Get all the note references in the given repository. * * @param repository * @return non-null but possibly empty array of note references */ public static Collection<String> getNoteRefs(final Repository repository) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); final Collection<Ref> refs = getRefs(repository, R_NOTES); final List<String> notes = new ArrayList<String>(refs.size()); for (Ref ref : refs) notes.add(ref.getName()); return notes; }
/** * 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; }
/** * Create a tree walk with all the trees from the given commit's parents. * * @param walk * @param commit * @return tree walk */ public static TreeWalk withParents(final RevWalk walk, final RevCommit commit) { if (walk == null) throw new IllegalArgumentException(Assert.formatNotNull("Walk")); if (commit == null) throw new IllegalArgumentException(Assert.formatNotNull("Commit")); try { return withParents(walk.getObjectReader(), walk, commit); } catch (IOException e) { throw new GitException(e, null); } }
/** * 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 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 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 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 all the local and remote tracking branch references in the given * repository. * * @param repository * @return non-null but possibly array of branch reference names */ public static Collection<String> getBranches(final Repository repository) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); final List<String> branches = new ArrayList<String>(); for (Ref ref : getRefs(repository, R_HEADS)) branches.add(ref.getName()); for (Ref ref : getRefs(repository, R_REMOTES)) branches.add(ref.getName()); return branches; }