/** * Returns the logs for a file in the repository. * * @param path - The file path. * @return - Stream of RevCommits the file is in. * @throws GitAPIException - failed. */ public Stream<RevCommit> logs(final String path) throws GitAPIException { return StreamSupport.stream(git.log().addPath(path).call().spliterator(), false); }
private FileData createFileData(org.eclipse.jgit.lib.Repository repository, TreeWalk dirWalk, String baseFolder, ObjectId start) throws GitAPIException, IOException { String fullPath = baseFolder + dirWalk.getPathString(); Iterator<RevCommit> iterator = git.log() .add(start) .addPath(fullPath) .call() .iterator(); if (!iterator.hasNext()) { throw new IllegalStateException("Can't find revision for a file " + dirWalk.getPathString()); } return createFileData(repository, dirWalk, baseFolder, iterator.next()); }
private <T> T iterateHistory(String name, HistoryVisitor<T> historyVisitor) throws IOException { Lock readLock = repositoryLock.readLock(); try { readLock.lock(); Iterator<RevCommit> iterator = git.log() .add(resolveBranchId()) .addPath(name) .call() .iterator(); List<Ref> tags = git.tagList().call(); while (iterator.hasNext()) { RevCommit commit = iterator.next(); boolean stop = historyVisitor.visit(name, commit, getVersionName(tags, commit)); if (stop) { break; } } return historyVisitor.getResult(); } catch (Exception e) { throw new IOException(e); } finally { readLock.unlock(); } }
public boolean getCommitsList() { try { LogCommand cmd = mRepo.getGit().log(); if (mFile != null) cmd.addPath(mFile); Iterable<RevCommit> commits = cmd.call(); mResult = new ArrayList<RevCommit>(); for (RevCommit commit : commits) { mResult.add(commit); } } catch (GitAPIException e) { setException(e); return false; } catch (StopTaskException e) { return false; } catch (Throwable e) { setException(e); return false; } return true; }
public boolean getCommitsList() { try { LogCommand cmd = mRepo.getGit().log(); if (mFile != null) cmd.addPath(mFile); Iterable<RevCommit> commits = cmd.call(); mResult = new ArrayList<RevCommit>(); for (RevCommit commit : commits) { mResult.add(commit); } } catch (GitAPIException e) { setException(e); return false; } catch (StopTaskException e) { return false; } catch (Throwable e) { setException(e); return false; } return true; }
/** * 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(); }
git.log().add(revisionId).addPath(path).call())
public static Iterable<RevCommit> getCommits( Iterable<File> dirs, String rangeStart, String rangeEnd, Repository repository) throws Exception { try (Git git = Git.wrap(repository)) { LogCommand logCommand = git.log(); for (File dir : dirs) { logCommand.addPath(_relativize(dir, repository)); } logCommand.addRange( repository.resolve(rangeStart), repository.resolve(rangeEnd)); return logCommand.call(); } }
final LogCommand logCommand = fs.gitRepo().log().add( id ); if ( !gPath.isEmpty() ) { logCommand.addPath( gPath );
/** * Does not fetch. */ public CommitInfo getCommitInfo(String path) throws Exception { Iterator<RevCommit> revCommits = git.log().addPath(path).setMaxCount(1).call().iterator(); if (revCommits.hasNext()) { RevCommit revCommit = revCommits.next(); CommitInfo commitInfo = new CommitInfo(revCommit.getId().name()); PersonIdent committerIdent = revCommit.getCommitterIdent(); commitInfo.setCommitter(committerIdent.getName()); commitInfo.setEmail(committerIdent.getEmailAddress()); if ((commitInfo.getCommitter() == null || commitInfo.getCommitter().isEmpty()) && commitInfo.getEmail() != null) commitInfo.setCommitter(commitInfo.getEmail()); commitInfo.setDate(committerIdent.getWhen()); commitInfo.setMessage(revCommit.getShortMessage()); return commitInfo; } return null; }
public static BasicFileAttributes buildBasicFileAttributes(final Git git, final String branchName, final String path) { long createDate = Long.MAX_VALUE; long lastModified = Long.MIN_VALUE; final JGitPathInfo pathInfo = resolvePath(git, branchName, path); if (pathInfo == null) { throw new NoSuchFileException(path); } final String gPath = fixPath(path); try { final LogCommand logCommand = git.log().add(getBranch(git, branchName).getObjectId()); if (!gPath.isEmpty()) { logCommand.addPath(gPath); } for (final RevCommit commit : logCommand.call()) { if (commit.getAuthorIdent().getWhen().getTime() < createDate) { createDate = commit.getAuthorIdent().getWhen().getTime(); } if (commit.getAuthorIdent().getWhen().getTime() > lastModified) { lastModified = commit.getAuthorIdent().getWhen().getTime(); } } } catch (Exception e) { throw new RuntimeException(e); } return new JGitFileAttributes(pathInfo.getObjectId() == null ? null : pathInfo.getObjectId().toString(), new FileTimeImpl(lastModified), new FileTimeImpl(createDate), pathInfo.getSize(), pathInfo.getPathType().equals(PathType.FILE), pathInfo.getPathType().equals(PathType.DIRECTORY)); }
/** * Get a JSON representation of the log of changes to a file * * @param jobId The jobId to fetch the log for * @return A log of the form [{commit:commitid, time:time, msg:commitmessage}, ...] * @throws GitAPIException If there is a problem fetching the log * @throws JSONException If there is a problem generating the JSON */ public JSONArray getGitLog(String jobId) throws Exception { JSONArray rv = new JSONArray(); for (RevCommit commit : git.log().addPath(getPathForJobId(jobId)).call()) { JSONObject commitJson = new JSONObject().put("commit", commit.getName()).put("time", 1000L * (commit.getCommitTime())).put("msg", commit.getFullMessage()); rv.put(commitJson); } return rv; }
@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); } }
RevCommit lastCommit = git.log().addPath(parentPath).call().iterator().next(); print("commitMessage", lastCommit.getShortMessage()); PersonIdent authorIdent = lastCommit.getAuthorIdent();