| | |
| | | import org.eclipse.jgit.revwalk.RevSort;
|
| | | import org.eclipse.jgit.revwalk.RevTree;
|
| | | import org.eclipse.jgit.revwalk.RevWalk;
|
| | | import org.eclipse.jgit.revwalk.filter.CommitTimeRevFilter;
|
| | | import org.eclipse.jgit.revwalk.filter.RevFilter;
|
| | | import org.eclipse.jgit.storage.file.FileRepository;
|
| | | import org.eclipse.jgit.transport.CredentialsProvider;
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Retrieves a Java Date from a Git commit.
|
| | | * |
| | | * @param commit
|
| | | * @return date of the commit or Date(0) if the commit is null
|
| | | */
|
| | | public static Date getAuthorDate(RevCommit commit) {
|
| | | if (commit == null) {
|
| | | return new Date(0);
|
| | | }
|
| | | return commit.getAuthorIdent().getWhen();
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the specified commit from the repository. If the repository does
|
| | | * not exist or is empty, null is returned.
|
| | | *
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Returns a list of commits since the minimum date starting from the
|
| | | * specified object id.
|
| | | * |
| | | * @param repository
|
| | | * @param objectId
|
| | | * if unspecified, HEAD is assumed.
|
| | | * @param minimumDate
|
| | | * @return list of commits
|
| | | */
|
| | | public static List<RevCommit> getRevLog(Repository repository, String objectId, Date minimumDate) {
|
| | | List<RevCommit> list = new ArrayList<RevCommit>();
|
| | | if (!hasCommits(repository)) {
|
| | | return list;
|
| | | }
|
| | | try {
|
| | | // resolve branch
|
| | | ObjectId branchObject;
|
| | | if (StringUtils.isEmpty(objectId)) {
|
| | | branchObject = getDefaultBranch(repository);
|
| | | } else {
|
| | | branchObject = repository.resolve(objectId);
|
| | | }
|
| | |
|
| | | RevWalk rw = new RevWalk(repository);
|
| | | rw.markStart(rw.parseCommit(branchObject));
|
| | | rw.setRevFilter(CommitTimeRevFilter.after(minimumDate));
|
| | | Iterable<RevCommit> revlog = rw;
|
| | | for (RevCommit rev : revlog) {
|
| | | list.add(rev);
|
| | | }
|
| | | rw.dispose();
|
| | | } catch (Throwable t) {
|
| | | error(t, repository, "{0} failed to get {1} revlog for minimum date {2}", objectId,
|
| | | minimumDate);
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns a list of commits starting from HEAD and working backwards.
|
| | | *
|
| | | * @param repository
|
| | |
| | | rw.dispose();
|
| | | } catch (Throwable t) {
|
| | | error(t, repository, "{0} failed to get {1} revlog for path {2}", objectId, path);
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns a list of commits for the repository within the range specified
|
| | | * by startRangeId and endRangeId. If the repository does not exist or is
|
| | | * empty, an empty list is returned.
|
| | | * |
| | | * @param repository
|
| | | * @param startRangeId
|
| | | * the first commit (not included in results)
|
| | | * @param endRangeId
|
| | | * the end commit (included in results)
|
| | | * @return a list of commits
|
| | | */
|
| | | public static List<RevCommit> getRevLog(Repository repository, String startRangeId,
|
| | | String endRangeId) {
|
| | | List<RevCommit> list = new ArrayList<RevCommit>();
|
| | | if (!hasCommits(repository)) {
|
| | | return list;
|
| | | }
|
| | | try {
|
| | | ObjectId endRange = repository.resolve(endRangeId);
|
| | | ObjectId startRange = repository.resolve(startRangeId);
|
| | |
|
| | | RevWalk rw = new RevWalk(repository);
|
| | | rw.markStart(rw.parseCommit(endRange));
|
| | | if (startRange.equals(ObjectId.zeroId())) {
|
| | | // maybe this is a tag or an orphan branch
|
| | | list.add(rw.parseCommit(endRange));
|
| | | rw.dispose();
|
| | | return list;
|
| | | } else {
|
| | | rw.markUninteresting(rw.parseCommit(startRange));
|
| | | }
|
| | |
|
| | | Iterable<RevCommit> revlog = rw;
|
| | | for (RevCommit rev : revlog) {
|
| | | list.add(rev);
|
| | | }
|
| | | rw.dispose();
|
| | | } catch (Throwable t) {
|
| | | error(t, repository, "{0} failed to get revlog for {1}..{2}", startRangeId, endRangeId);
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Returns a RefModel for the gh-pages branch in the repository. If the
|
| | | * branch can not be found, null is returned.
|
| | | * |
| | | * @param repository
|
| | | * @return a refmodel for the gh-pages branch or null
|
| | | */
|
| | | public static RefModel getPagesBranch(Repository repository) {
|
| | | RefModel ghPages = null;
|
| | | try {
|
| | | // search for gh-pages branch in local heads
|
| | | for (RefModel ref : JGitUtils.getLocalBranches(repository, false, -1)) {
|
| | | if (ref.displayName.endsWith("gh-pages")) {
|
| | | ghPages = ref;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | // search for gh-pages branch in remote heads
|
| | | if (ghPages == null) {
|
| | | for (RefModel ref : JGitUtils.getRemoteBranches(repository, false, -1)) {
|
| | | if (ref.displayName.endsWith("gh-pages")) {
|
| | | ghPages = ref;
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | } catch (Throwable t) {
|
| | | LOGGER.error("Failed to find gh-pages branch!", t);
|
| | | }
|
| | | return ghPages;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of notes entered about the commit from the refs/notes
|
| | | * namespace. If the repository does not exist or is empty, an empty list is
|
| | | * returned.
|