List of usage examples for org.eclipse.jgit.api LogCommand setSkip
public LogCommand setSkip(int skip)
From source file:org.ajoberstar.gradle.git.tasks.GitLog.java
License:Apache License
/** * Gets the commit log and stores it in a project property as configured. *//* w ww . j a va 2 s.c om*/ @TaskAction public void reset() { final LogCommand cmd = getGit().log(); Repository repo = getGit().getRepository(); if (includes != null) { for (String include : includes) { try { ObjectId commit = repo.resolve(include); if (commit == null) { throw new GradleException("No commit found for revision string: " + include); } else { cmd.add(commit); } } catch (AmbiguousObjectException e) { throw new GradleException("Revision string is ambiguous: " + include, e); } catch (MissingObjectException e) { throw new GradleException("Commit could not be found in repository: " + include, e); } catch (IncorrectObjectTypeException e) { throw new GradleException("Revision string did not point to a commit: " + include, e); } catch (IOException e) { throw new GradleException("Problem resolving revision string: " + include, e); } } } if (excludes != null) { for (String exclude : excludes) { try { ObjectId commit = repo.resolve(exclude); if (commit == null) { throw new GradleException("No commit found for revision string: " + exclude); } else { cmd.add(commit); } } catch (AmbiguousObjectException e) { throw new GradleException("Revision string is ambiguous: " + exclude, e); } catch (MissingObjectException e) { throw new GradleException("Commit could not be found in repository: " + exclude, e); } catch (IncorrectObjectTypeException e) { throw new GradleException("Revision string did not point to a commit: " + exclude, e); } catch (IOException e) { throw new GradleException("Problem resolving revision string: " + exclude, e); } } } cmd.setSkip(skipCommits); cmd.setMaxCount(maxCommits); try { Iterable<RevCommit> commits = cmd.call(); List<Commit> tempLog = new ArrayList<Commit>(); for (RevCommit commit : commits) { tempLog.add(GitUtil.revCommitToCommit(commit)); } this.log = Collections.unmodifiableList(tempLog); } catch (GitAPIException e) { throw new GradleException("Problem with log.", e); } //TODO add progress monitor to log progress to Gradle status bar }
From source file:org.modeshape.connector.git.GitFunction.java
License:Apache License
/** * Add the first page of commits in the history names of the tags as children of the current node. * //from w w w . ja v a 2s .com * @param git the Git object; may not be null * @param spec the call specification; may not be null * @param writer the document writer for the current node; may not be null * @param pageSize the number of commits to include, and the number of commits that will be in the next page (if there are * more commits) * @throws GitAPIException if there is a problem accessing the Git repository */ protected void addCommitsAsChildren(Git git, CallSpecification spec, DocumentWriter writer, int pageSize) throws GitAPIException { // Add commits in the log ... LogCommand command = git.log(); command.setSkip(0); command.setMaxCount(pageSize); // Add the first set of commits ... int actual = 0; String commitId = null; for (RevCommit commit : command.call()) { commitId = commit.getName(); writer.addChild(spec.childId(commitId), commitId); ++actual; } if (actual == pageSize) { // We wrote the maximum number of commits, so there's (probably) another page ... writer.addPage(spec.getId(), commitId, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE); } }
From source file:org.modeshape.connector.git.GitHistory.java
License:Apache License
@Override public Document execute(Repository repository, Git git, CallSpecification spec, PageWriter writer, Values values, PageKey pageKey) throws GitAPIException, IOException { if (spec.parameterCount() == 0) { // List the next page of commits ... addCommitsAsPageOfChildren(git, repository, spec, writer, pageKey); } else {//from w w w.j a va 2 s . c o m // We know the branch, tag, or commit for the history ... String branchOrTagNameOrObjectId = spec.parameter(0); ObjectId objId = repository.resolve(branchOrTagNameOrObjectId); RevWalk walker = new RevWalk(repository); try { int offset = pageKey.getOffsetInt(); RevCommit commit = walker.parseCommit(objId); LogCommand command = git.log(); command.add(commit.getId()); command.setSkip(offset); command.setMaxCount(pageSize); for (RevCommit rev : command.call()) { String commitId = rev.getId().toString(); writer.addChild(spec.childId(commitId), commitId); } // Handle paging ... int nextOffset = offset + pageSize; writer.addPage(pageKey.getParentId(), nextOffset, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE); } finally { walker.dispose(); } } return writer.document(); }