public Long commitCountOnMaster() throws GitAPIException, IncorrectObjectTypeException, MissingObjectException { // not inside a doLocked/synchronized block because we don't want to block the server status service. // we do a `git branch` because we switch branches as part of normal git operations, // and we don't care about number of commits on those branches. List<Ref> branches = git.branchList().call(); for (Ref branch : branches) { if (branch.getName().equals("refs/heads/master")) { Iterable<RevCommit> commits = git.log().add(branch.getObjectId()).call(); long count = 0; for (RevCommit commit : commits) { count++; } return count; } } return Long.valueOf(-1); } }
log.add(fId);
@Signature public Memory resolveCommit(String revstr) throws IOException, GitAPIException { ObjectId objectId = getWrappedObject().getRepository().resolve(revstr); if (objectId == null) { return Memory.NULL; } LogCommand command = getWrappedObject() .log() .add(objectId) .setMaxCount(1); Iterable<RevCommit> call = command.call(); for (RevCommit revCommit : call) { return GitUtils.valueOf(revCommit); } return Memory.NULL; }
private static RevCommitsPair resolveRevCommitsPair(Repository repo) { RevCommitsPair revCommitIteratorPair; try (RevWalk revWalk = new RevWalk(repo); Git git = new Git(repo)) { final Iterator<RevCommit> first; final Iterator<RevCommit> second; final ObjectId headId = repo.resolve(Constants.HEAD); final RevCommit headCommit = revWalk.parseCommit(headId); if (isMergeCommit(headCommit)) { final RevCommit firstParent = headCommit.getParent(0); final RevCommit secondParent = headCommit.getParent(1); first = git.log().add(firstParent).call().iterator(); second = git.log().add(secondParent).call().iterator(); } else { first = git.log().call().iterator(); second = Collections.emptyIterator(); } revCommitIteratorPair = new RevCommitsPair(new OmitMergeCommitsIterator(first), new OmitMergeCommitsIterator(second)); } catch (GitAPIException | IOException ignored) { revCommitIteratorPair = new RevCommitsPair(); } return revCommitIteratorPair; }
return add(true, start);
/** * Same as {@code --not start}, or {@code ^start} * * @param start * a {@link org.eclipse.jgit.lib.AnyObjectId} * @return {@code this} * @throws org.eclipse.jgit.errors.MissingObjectException * the commit supplied is not available from the object * database. This usually indicates the supplied commit is * invalid, but the reference was constructed during an earlier * invocation to * {@link org.eclipse.jgit.revwalk.RevWalk#lookupCommit(AnyObjectId)}. * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException * the object was not parsed yet and it was discovered during * parsing that it is not actually a commit. This usually * indicates the caller supplied a non-commit SHA-1 to * {@link org.eclipse.jgit.revwalk.RevWalk#lookupCommit(AnyObjectId)}. * @throws JGitInternalException * a low-level exception of JGit has occurred. The original * exception can be retrieved by calling * {@link java.lang.Exception#getCause()}. Expect only * {@code IOException's} to be wrapped. Subclasses of * {@link java.io.IOException} (e.g. * {@link org.eclipse.jgit.errors.MissingObjectException}) are * typically not wrapped here but thrown as original exception */ public LogCommand not(AnyObjectId start) throws MissingObjectException, IncorrectObjectTypeException { return add(false, start); }
return not(since).add(until);
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Ref> call = git.tagList().call(); for (Ref ref : call) { System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); // fetch all commits for this tag LogCommand log = git.log(); Ref peeledRef = repository.getRefDatabase().peel(ref); if(peeledRef.getPeeledObjectId() != null) { log.add(peeledRef.getPeeledObjectId()); } else { log.add(ref.getObjectId()); } Iterable<RevCommit> logs = log.call(); for (RevCommit rev : logs) { System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */); } } } } } }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Ref> call = git.tagList().call(); for (Ref ref : call) { System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); // fetch all commits for this tag LogCommand log = git.log(); Ref peeledRef = repository.getRefDatabase().peel(ref); if(peeledRef.getPeeledObjectId() != null) { log.add(peeledRef.getPeeledObjectId()); } else { log.add(ref.getObjectId()); } Iterable<RevCommit> logs = log.call(); for (RevCommit rev : logs) { System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */); } } } } } }
LogCommand log = new Git(repository).log(); Ref peeledRef = repository.peel(ref); if(peeledRef.getPeeledObjectId() != null) { log.add(peeledRef.getPeeledObjectId()); } else { log.add(ref.getObjectId()); } Iterable<RevCommit> logs = log.call(); for (RevCommit rev : logs) { System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */); }
throw new NoHeadException( JGitText.get().noHEADExistsAndNoExplicitStartingRevisionWasSpecified); add(headId); } catch (IOException e) {
/** * Returns the logs for a specified commit. * * @param com - The commit to retrieive logs for. * @return - Stream of RevCommits contained in the passed commit. * @throws GitAPIException - failed * @throws IOException - failed */ public Stream<RevCommit> commitLogs(final RevCommit com) throws GitAPIException, IOException { return StreamSupport.stream(git.log().add(com).call().spliterator(), false); }
public void logLastCommitsInBranch(Git git, int nbCommitsToLog, String branchName) throws IOException, GitAPIException { Iterable<RevCommit> lastCommitsOnBranch = git.log() .add(git.getRepository().resolve(branchName)) .setMaxCount(nbCommitsToLog) .call(); logDiffCommits(StreamSupport.stream(lastCommitsOnBranch.spliterator(), false).collect(toList()), "last " + nbCommitsToLog + "commits on branch " + branchName); }
@Override public boolean containsCommit(Git git, String branch, String commitMessage) throws IOException, GitAPIException { ObjectId head = git.getRepository().resolve(branch); Iterable<RevCommit> log = git.log().add(head).call(); for (RevCommit rc : log) { if (rc.getFullMessage().equals(commitMessage)) { return true; } } return false; }
@Override public boolean containsCommit(Git git, String branch, String commitMessage) throws IOException, GitAPIException { ObjectId head = git.getRepository().resolve(branch); Iterable<RevCommit> log = git.log().add(head).call(); for (RevCommit rc : log) { if (rc.getFullMessage().equals(commitMessage)) { return true; } } return false; }
private List<RevCommit> getCommitsFromBranch(final GitImpl origin, String branch) throws GitAPIException, MissingObjectException, IncorrectObjectTypeException { List<RevCommit> commits = new ArrayList<>(); final ObjectId id = new GetRef(origin.getRepository(), branch).execute().getObjectId(); for (RevCommit commit : origin._log().add(id).call()) { commits.add(commit); } return commits; } }
private List<RevCommit> getCommitsFromBranch(final GitImpl origin, String branch) throws GitAPIException, MissingObjectException, IncorrectObjectTypeException { List<RevCommit> commits = new ArrayList<>(); final ObjectId id = new GetRef(origin.getRepository(), branch).execute().getObjectId(); for (RevCommit commit : origin._log().add(id).call()) { logger.info(">>> " + branch + " Commits: " + commit.getFullMessage() + " - " + commit.toString()); commits.add(commit); } return commits; }