List of usage examples for org.eclipse.jgit.api LogCommand addPath
public LogCommand addPath(String path)
From source file:at.nonblocking.maven.nonsnapshot.impl.ScmHandlerGitImpl.java
License:Apache License
@Override public boolean checkChangesSinceDate(final File moduleDirectory, final Date date) { if (this.git == null) { return false; }//from w ww . j a v a 2 s.co m try { String modulePath = PathUtil.relativePath(this.baseDir, moduleDirectory); LogCommand logCommand = this.git.log().setMaxCount(100); if (!modulePath.isEmpty()) { logCommand.addPath(modulePath); } for (RevCommit commit : logCommand.call()) { Date commitTime = new Date(commit.getCommitTime() * 1000L); if (commitTime.after(date)) { if (!commit.getFullMessage().startsWith(NONSNAPSHOT_COMMIT_MESSAGE_PREFIX)) { LOG.debug("Module folder {}: Change since last commit: rev{} @ {} ({})", new Object[] { moduleDirectory.getAbsolutePath(), commit.getId(), commitTime, commit.getFullMessage() }); return true; } } else { break; } } } catch (Exception e) { LOG.warn("Failed to check changes for path: {}" + moduleDirectory.getAbsolutePath(), e); return true; } return false; }
From source file:com.tasktop.c2c.server.scm.service.GitBrowseUtil.java
License:Open Source License
private static void addHistory(Git git, Trees.Tree tree, ObjectId revision, String path) throws MissingObjectException, IncorrectObjectTypeException, GitAPIException { LogCommand logCommand = git.log(); logCommand.add(revision);/* w w w . j a va 2 s.c om*/ logCommand.addPath(path); for (RevCommit revCommit : logCommand.call()) { Commit commit = GitDomain.createCommit(revCommit); tree.setLatestCommit(commit); break; } }
From source file:eu.hohenegger.gitmine.ui.views.TimeLapseView.java
License:Open Source License
@Inject public void setSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection) { if (scale == null || scale.isDisposed()) { return;/*w ww . j a va2s . c o m*/ } if (selection == null) { return; } if (!(selection.getFirstElement() instanceof PlatformObject)) { return; } PlatformObject firstElement = (PlatformObject) selection.getFirstElement(); resource = (IResource) firstElement.getAdapter(IResource.class); if (resource == null) { return; } IProject project = resource.getProject(); RepositoryMapping mapping = RepositoryMapping.getMapping(project.getLocation()); repository = mapping.getRepository(); String relativePath = createRelativePath(resource.getLocation().toString(), repository); Git git = Git.wrap(repository); commitList = new ArrayList<>(); Iterable<RevCommit> commits; LogCommand logCmd = git.log(); if (!relativePath.isEmpty()) { logCmd.addPath(relativePath); } try { commits = logCmd.call(); for (RevCommit revCommit : commits) { commitList.add(0, revCommit); } scale.setMaximum(commitList.size() - 1); } catch (NoHeadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (GitAPIException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:net.riezebos.thoth.content.impl.GitContentManager.java
License:Apache License
@Override public PagedList<Commit> getCommits(String path, int pageNumber, int pageSize) throws ContentManagerException { path = ThothUtil.stripPrefix(path, "/"); try (Git repos = getRepository()) { Repository repository = repos.getRepository(); List<Commit> commits = new ArrayList<>(); LogCommand log = repos.log(); if (path != null) log = log.addPath(path); Iterable<RevCommit> revisions = log.call(); Iterator<RevCommit> iterator = revisions.iterator(); // First skip over the pages we are not interested in int skipCount = (pageNumber - 1) * pageSize; while (skipCount-- > 0 && iterator.hasNext()) iterator.next();/*from ww w.ja v a 2s . c om*/ // Now add the revisions while (iterator.hasNext() && commits.size() < pageSize) { RevCommit revCommit = iterator.next(); commits.add(getCommit(repository, revCommit, path)); } PagedList<Commit> pagedList = new PagedList<>(commits, iterator.hasNext()); return pagedList; } catch (IOException | GitAPIException e) { throw new ContentManagerException(e); } }
From source file:org.eclipse.orion.server.git.servlets.GitCommitHandlerV1.java
License:Open Source License
private boolean handleGetCommitLog(HttpServletRequest request, HttpServletResponse response, Repository db, String refIdsRange, String path) throws AmbiguousObjectException, IOException, ServletException, JSONException, URISyntaxException, CoreException { int page = request.getParameter("page") != null ? new Integer(request.getParameter("page")).intValue() : 0; //$NON-NLS-1$ //$NON-NLS-2$ int pageSize = request.getParameter("pageSize") != null //$NON-NLS-1$ ? new Integer(request.getParameter("pageSize")).intValue() //$NON-NLS-1$ : PAGE_SIZE;//from ww w .ja va 2 s .c om ObjectId toObjectId = null; ObjectId fromObjectId = null; Ref toRefId = null; Ref fromRefId = null; Git git = new Git(db); LogCommand log = git.log(); if (refIdsRange != null) { // git log <since>..<until> if (refIdsRange.contains("..")) { //$NON-NLS-1$ String[] commits = refIdsRange.split("\\.\\."); //$NON-NLS-1$ if (commits.length != 2) { String msg = NLS.bind("Failed to generate commit log for ref {0}", refIdsRange); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null)); } fromObjectId = db.resolve(commits[0]); fromRefId = db.getRef(commits[0]); if (fromObjectId == null) { String msg = NLS.bind("Failed to generate commit log for ref {0}", commits[0]); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null)); } toObjectId = db.resolve(commits[1]); toRefId = db.getRef(commits[1]); if (toObjectId == null) { String msg = NLS.bind("No ref or commit found: {0}", commits[1]); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null)); } } else { toObjectId = db.resolve(refIdsRange); toRefId = db.getRef(refIdsRange); if (toObjectId == null) { String msg = NLS.bind("No ref or commit found: {0}", refIdsRange); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null)); } } // set the commit range log.add(toObjectId); if (fromObjectId != null) log.not(fromObjectId); } else { // git log --all // workaround for git log --all - see bug 353310 List<Ref> branches = git.branchList().setListMode(ListMode.ALL).call(); for (Ref branch : branches) { log.add(branch.getObjectId()); } } // set the path filter TreeFilter filter = null; boolean isRoot = true; if (path != null && !"".equals(path)) { //$NON-NLS-1$ filter = AndTreeFilter.create(PathFilterGroup.createFromStrings(Collections.singleton(path)), TreeFilter.ANY_DIFF); log.addPath(path); isRoot = false; } try { Iterable<RevCommit> commits = log.call(); Map<ObjectId, JSONArray> commitToBranchMap = getCommitToBranchMap(db); JSONObject result = toJSON(db, OrionServlet.getURI(request), commits, commitToBranchMap, page, pageSize, filter, isRoot); result.put(GitConstants.KEY_REPOSITORY_PATH, isRoot ? "" : path); //$NON-NLS-1$ if (refIdsRange == null) result.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.COMMIT)); else result.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.COMMIT_REFRANGE)); if (toRefId != null) { result.put(GitConstants.KEY_REMOTE, BaseToRemoteConverter.getRemoteBranchLocation(getURI(request), Repository.shortenRefName(toRefId.getName()), db, BaseToRemoteConverter.REMOVE_FIRST_3)); String refTargetName = toRefId.getTarget().getName(); if (refTargetName.startsWith(Constants.R_HEADS)) { // this is a branch result.put(GitConstants.KEY_LOG_TO_REF, BranchToJSONConverter.toJSON(toRefId.getTarget(), db, getURI(request), 3)); } } if (fromRefId != null) { String refTargetName = fromRefId.getTarget().getName(); if (refTargetName.startsWith(Constants.R_HEADS)) { // this is a branch result.put(GitConstants.KEY_LOG_FROM_REF, BranchToJSONConverter.toJSON(fromRefId.getTarget(), db, getURI(request), 3)); } } OrionServlet.writeJSONResponse(request, response, result); return true; } catch (NoHeadException e) { String msg = NLS.bind("No HEAD reference found when generating log for ref {0}", refIdsRange); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e)); } catch (JGitInternalException e) { String msg = NLS.bind("An internal error occured when generating log for ref {0}", refIdsRange); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e)); } }
From source file:org.eclipse.osee.ote.version.git.GitVersion.java
License:Open Source License
public RevCommit getLastCommit() throws IOException, NoHeadException, GitAPIException { if (!file.exists()) { return null; }/*from w w w. j av a 2 s. c om*/ File gitFolder = findGitDirUp(file); if (gitFolder == null) { return null; } Repository repository = buildRepository(gitFolder); Git git = new Git(repository); LogCommand log = git.log(); String pathFilter = getPathFilterFromFullPathAndGitFolder(file, gitFolder); log.addPath(pathFilter); Iterable<RevCommit> iterable = log.call(); Iterator<RevCommit> it = iterable.iterator(); if (it.hasNext()) { return it.next(); } else { return null; } }
From source file:org.eclipse.osee.ote.version.git.GitVersions.java
License:Open Source License
public Map<File, RevCommit> getLastCommits() { Map<File, RevCommit> commits = new HashMap<File, RevCommit>(); Map<File, List<File>> gitToFiles = new HashMap<File, List<File>>(); for (File file : files) { if (!file.exists()) { continue; }//from www . jav a 2 s . co m File gitFolder = findGitDirUp(file); if (gitFolder == null) { continue; } List<File> gitfiles = gitToFiles.get(gitFolder); if (gitfiles == null) { gitfiles = new ArrayList<File>(); gitToFiles.put(gitFolder, gitfiles); } gitfiles.add(file); } for (Entry<File, List<File>> entry : gitToFiles.entrySet()) { try { Repository repository = buildRepository(entry.getKey()); Git git = new Git(repository); for (File gitfile : entry.getValue()) { LogCommand log = git.log(); log.setMaxCount(1); String pathFilter = getPathFilterFromFullPathAndGitFolder(gitfile, entry.getKey()); log.addPath(pathFilter); Iterable<RevCommit> iterable = log.call(); Iterator<RevCommit> it = iterable.iterator(); if (it.hasNext()) { RevCommit commit = it.next(); commits.put(gitfile, commit); } } } catch (IOException e) { e.printStackTrace(); } catch (NoHeadException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } } return commits; }
From source file:org.kie.commons.java.nio.fs.jgit.util.JGitUtil.java
License:Apache License
public static VersionAttributes buildVersionAttributes(final JGitFileSystem fs, final String branchName, final String path) { final JGitPathInfo pathInfo = resolvePath(fs.gitRepo(), branchName, path); if (pathInfo == null) { throw new NoSuchFileException(path); }//from w ww . java2 s .c om final String gPath = fixPath(path); final ObjectId id = resolveObjectId(fs.gitRepo(), branchName); final List<VersionRecord> records = new ArrayList<VersionRecord>(); if (id != null) { try { final LogCommand logCommand = fs.gitRepo().log().add(id); if (!gPath.isEmpty()) { logCommand.addPath(gPath); } for (final RevCommit commit : logCommand.call()) { records.add(new VersionRecord() { @Override public String id() { return commit.name(); } @Override public String author() { return commit.getCommitterIdent().getName(); } @Override public String email() { return commit.getCommitterIdent().getEmailAddress(); } @Override public String comment() { return commit.getFullMessage(); } @Override public Date date() { return commit.getCommitterIdent().getWhen(); } @Override public String uri() { return fs.getPath(commit.name(), path).toUri().toString(); } }); } } catch (Exception e) { throw new RuntimeException(e); } } Collections.sort(records, new Comparator<VersionRecord>() { @Override public int compare(final VersionRecord o1, final VersionRecord o2) { return o1.date().compareTo(o2.date()); } }); return new VersionAttributes() { @Override public VersionHistory history() { return new VersionHistory() { @Override public List<VersionRecord> records() { return records; } }; } @Override public FileTime lastModifiedTime() { if (records.size() > 0) { return new FileTimeImpl(records.get(records.size() - 1).date().getTime()); } return null; } @Override public FileTime lastAccessTime() { return null; } @Override public FileTime creationTime() { if (records.size() > 0) { return new FileTimeImpl(records.get(0).date().getTime()); } return null; } @Override public boolean isRegularFile() { return pathInfo.getPathType().equals(PathType.FILE); } @Override public boolean isDirectory() { return pathInfo.getPathType().equals(PathType.DIRECTORY); } @Override public boolean isSymbolicLink() { return false; } @Override public boolean isOther() { return false; } @Override public long size() { return pathInfo.getSize(); } @Override public Object fileKey() { return pathInfo.getObjectId() == null ? null : pathInfo.getObjectId().toString(); } }; }
From source file:org.uberfire.java.nio.fs.jgit.util.commands.ListCommits.java
License:Apache License
private RevWalk buildWalk() throws GitAPIException, IncorrectObjectTypeException, MissingObjectException { if (ref != null) { final LogCommand logCommand = git._log().add(ref.getObjectId()); if (path != null && !path.isEmpty()) { logCommand.addPath(path); }// w ww . ja va 2 s . c o m return (RevWalk) logCommand.call(); } return new RevWalk(git.getRepository()); }
From source file:org.uberfire.java.nio.fs.jgit.util.JGitUtil.java
License:Apache License
public static VersionAttributes buildVersionAttributes(final JGitFileSystem fs, final String branchName, final String path) { final JGitPathInfo pathInfo = resolvePath(fs.gitRepo(), branchName, path); if (pathInfo == null) { throw new NoSuchFileException(path); }/*from ww w .j av a 2s. co m*/ final String gPath = fixPath(path); final ObjectId id = resolveObjectId(fs.gitRepo(), branchName); final List<VersionRecord> records = new ArrayList<VersionRecord>(); if (id != null) { try { final LogCommand logCommand = fs.gitRepo().log().add(id); if (!gPath.isEmpty()) { logCommand.addPath(gPath); } for (final RevCommit commit : logCommand.call()) { records.add(new VersionRecord() { @Override public String id() { return commit.name(); } @Override public String author() { return commit.getAuthorIdent().getName(); } @Override public String email() { return commit.getAuthorIdent().getEmailAddress(); } @Override public String comment() { return commit.getFullMessage(); } @Override public Date date() { return commit.getAuthorIdent().getWhen(); } @Override public String uri() { return fs.getPath(commit.name(), path).toUri().toString(); } }); } } catch (Exception e) { throw new RuntimeException(e); } } Collections.sort(records, new Comparator<VersionRecord>() { @Override public int compare(final VersionRecord o1, final VersionRecord o2) { return o1.date().compareTo(o2.date()); } }); return new VersionAttributes() { @Override public VersionHistory history() { return new VersionHistory() { @Override public List<VersionRecord> records() { return records; } }; } @Override public FileTime lastModifiedTime() { if (records.size() > 0) { return new FileTimeImpl(records.get(records.size() - 1).date().getTime()); } return null; } @Override public FileTime lastAccessTime() { return null; } @Override public FileTime creationTime() { if (records.size() > 0) { return new FileTimeImpl(records.get(0).date().getTime()); } return null; } @Override public boolean isRegularFile() { return pathInfo.getPathType().equals(PathType.FILE); } @Override public boolean isDirectory() { return pathInfo.getPathType().equals(PathType.DIRECTORY); } @Override public boolean isSymbolicLink() { return false; } @Override public boolean isOther() { return false; } @Override public long size() { return pathInfo.getSize(); } @Override public Object fileKey() { return pathInfo.getObjectId() == null ? null : pathInfo.getObjectId().toString(); } }; }