/** * 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); }
/** * Throw an {@link IllegalArgumentException} with a default message if the * {@link Object} array has a length of zero. * * @param objects * @return objects * @throws IllegalArgumentException */ public static <V> V[] notEmpty(final V[] objects) throws IllegalArgumentException { return notEmpty(null, objects); }
/** * Throw an {@link IllegalArgumentException} with a default message if the * object is null. * * @param object * @return object * @throws IllegalArgumentException */ public static <V> V notNull(final V object) throws IllegalArgumentException { return notNull(null, object); }
/** * 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(); }
/** * 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(""); }
/** * 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; }
/** * Throw an {@link IllegalArgumentException} with a default message if the * string has a length of zero. * * @param string * @return string * @throws IllegalArgumentException */ public static String notEmpty(final String string) throws IllegalArgumentException { return notEmpty(null, string); }
/** * 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); }
/** * 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; }
/** * 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)); }
/** * 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); }
/** * 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)); }
/** * 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); }
/** * 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); }
/** * 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 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 id of the tree at the path in the given commit * * @param repository * @param commitId * @param path * @return tree id or null if no tree id at path */ 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.formatNotNull("Path")); final RevCommit commit = CommitUtils.parse(repository, commitId); return lookupId(repository, commit, path); }
/** * 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); } }
/** * 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)); }