public GoConfigRevisions getCommits(final int pageSize, final int offset) { return doLocked(() -> { GoConfigRevisions goConfigRevisions = new GoConfigRevisions(); try { LogCommand command = git.log().setMaxCount(pageSize).setSkip(offset); Iterable<RevCommit> revisions = command.call(); for (RevCommit revision : revisions) { GoConfigRevision goConfigRevision = new GoConfigRevision((byte[]) null, revision.getFullMessage()); goConfigRevision.setCommitSHA(revision.name()); goConfigRevisions.add(goConfigRevision); } } catch (Exception e) { // ignore } return goConfigRevisions; }); }
log.setSkip(skip.toInteger());
/** * Returns the hash of the last commit before a job was deleted. * * This method uses the following git command equivalent: * <pre> * git log --all --skip=1 -n 1 -- jobs/[jobId] * </pre> * which only works as intended with deleted jobs. * * @param jobId The id of a deleted job. * @throws GitAPIException * @throws IOException */ public String getCommitHashBeforeJobDeletion(String jobId) throws GitAPIException, IOException { // skip=1 skips the deletion, and -n 1 returns only the commit immediately before that Iterable<RevCommit> iter = git.log().all().addPath(getPathForJobId(jobId)).setSkip(1).setMaxCount(1).call(); RevCommit commit = Iterables.getFirst(iter, null); return commit == null ? null : commit.getName(); }
/** * Return a simplified git commit history list. * * @param repositoryDirectory The directory in which the git repo exists. * @param from Start to query from the given history. * @param count The number of history entries to retrieve. * @return A list of simplified history entries. */ public static List<SimpleGitHistoryEntry> getHistory(Path repositoryDirectory, int from, int count) { Git repository = null; try { repository = Git.open(repositoryDirectory.toFile()); Iterable<RevCommit> commits = repository.log().setSkip(from).setMaxCount(count).call(); List<SimpleGitHistoryEntry> historyEntries = Lists.newArrayList(); for (RevCommit commit : commits) { historyEntries.add(new SimpleGitHistoryEntry(commit.getId().getName(), commit.getAuthorIdent().getName(), commit.getAuthorIdent().getEmailAddress(), commit.getFullMessage(), new Date(commit.getCommitTime() * 1000L))); } return historyEntries; } catch (NoHeadException e) { log.debug("Your repository has no head, you need to save your topology before using the git history."); return Lists.newArrayList(); } catch (GitAPIException | IOException e) { throw new GitException("Unable to get history from the git repository", e); } finally { close(repository); } }
command.setSkip(0); command.setMaxCount(pageSize);
@Override public List<Revision> getHistory(final String test, final String revision, final int start, final int limit) throws StoreException { try { final ObjectId commitId = ObjectId.fromString(revision); final LogCommand logCommand = git.log() // TODO: create path to definition.json file, sanitize test name for invalid / relative characters .addPath(getTestDefinitionsDirectory() + File.separator + test + File.separator + FileBasedProctorStore.TEST_DEFINITION_FILENAME) .add(commitId) .setSkip(start) .setMaxCount(limit); return getHistoryFromLogCommand(logCommand); } catch (IOException e) { throw new StoreException("Could not get history for " + test + " starting at " + getGitCore().getRefName(), e); } }
@Override public List<Revision> getHistory(final String test, final String revision, final int start, final int limit) throws StoreException { try { final ObjectId commitId = ObjectId.fromString(revision); final LogCommand logCommand = git.log() // TODO: create path to definition.json file, sanitize test name for invalid / relative characters .addPath(getTestDefinitionsDirectory() + File.separator + test + File.separator + FileBasedProctorStore.TEST_DEFINITION_FILENAME) .add(commitId) .setSkip(start) .setMaxCount(limit); return getHistoryFromLogCommand(logCommand); } catch (IOException e) { throw new StoreException("Could not get history for " + test + " starting at " + getGitCore().getRefName(), e); } }
@Override public List<Revision> getMatrixHistory(final int start, final int limit) throws StoreException { final LogCommand logCommand; try { final ObjectId branchHead = git.getRepository().resolve(getGitCore().getRefName()); logCommand = git.log() .add(branchHead) .setSkip(start) .setMaxCount(limit); return getHistoryFromLogCommand(logCommand); } catch (MissingObjectException e) { throw new StoreException("Could not get history for starting at " + getGitCore().getRefName(), e); } catch (IncorrectObjectTypeException e) { throw new StoreException("Could not get history for starting at " + getGitCore().getRefName(), e); } catch (AmbiguousObjectException e) { throw new StoreException("Could not get history for starting at " + getGitCore().getRefName(), e); } catch (IOException e) { throw new StoreException("Could not get history for starting at " + getGitCore().getRefName(), e); } }
@Override public List<Revision> getMatrixHistory(final int start, final int limit) throws StoreException { final LogCommand logCommand; try { final ObjectId branchHead = git.getRepository().resolve(getGitCore().getRefName()); logCommand = git.log() .add(branchHead) .setSkip(start) .setMaxCount(limit); return getHistoryFromLogCommand(logCommand); } catch (MissingObjectException e) { throw new StoreException("Could not get history for starting at " + getGitCore().getRefName(), e); } catch (IncorrectObjectTypeException e) { throw new StoreException("Could not get history for starting at " + getGitCore().getRefName(), e); } catch (AmbiguousObjectException e) { throw new StoreException("Could not get history for starting at " + getGitCore().getRefName(), e); } catch (IOException e) { throw new StoreException("Could not get history for starting at " + getGitCore().getRefName(), e); } }