List of usage examples for org.eclipse.jgit.lib Constants HEAD
String HEAD
To view the source code for org.eclipse.jgit.lib Constants HEAD.
Click Source Link
From source file:org.eclipse.che.git.impl.jgit.JGitDiffPage.java
License:Open Source License
/** * Show changes between specified revision and index. If * <code>commitId == null</code> then view changes between HEAD and index. * * @param commitId// w w w . jav a2 s. co m * id of commit, pass <code>null</code> is the same as pass HEAD * @param formatter * diff formatter * @return list of diff entries * @throws IOException * if any i/o errors occurs */ private List<DiffEntry> commitToIndex(String commitId, DiffFormatter formatter) throws IOException { if (commitId == null) { commitId = Constants.HEAD; } ObjectId commitA = repository.resolve(commitId); if (commitA == null) { throw new IllegalArgumentException("Invalid commit id " + commitId); } RevTree treeA; try (RevWalk revWalkA = new RevWalk(repository)) { treeA = revWalkA.parseTree(commitA); } DirCache dirCache = null; List<DiffEntry> diff; try (ObjectReader reader = repository.newObjectReader()) { dirCache = repository.lockDirCache(); CanonicalTreeParser iterA = new CanonicalTreeParser(); iterA.reset(reader, treeA); DirCacheIterator iterB = new DirCacheIterator(dirCache); if (!request.isNoRenames()) { // Use embedded RenameDetector it works well with index and // revision history. formatter.setDetectRenames(true); int renameLimit = request.getRenameLimit(); if (renameLimit > 0) { formatter.getRenameDetector().setRenameLimit(renameLimit); } } diff = formatter.scan(iterA, iterB); } finally { if (dirCache != null) { dirCache.unlock(); } } return diff; }
From source file:org.eclipse.che.git.impl.jgit.JGitDiffPage.java
License:Open Source License
/** * Show changes between specified two revisions and index. If * <code>commitAId == null</code> then view changes between HEAD and revision commitBId. * * @param commitAId/*from w ww.j ava 2 s .c o m*/ * id of commit A, pass <code>null</code> is the same as pass HEAD * @param commitBId * id of commit B * @param formatter * diff formatter * @return list of diff entries * @throws IOException * if any i/o errors occurs */ private List<DiffEntry> commitToCommit(String commitAId, String commitBId, DiffFormatter formatter) throws IOException { if (commitAId == null) { commitAId = Constants.HEAD; } ObjectId commitA = repository.resolve(commitAId); if (commitA == null) { throw new IllegalArgumentException("Invalid commit id " + commitAId); } ObjectId commitB = repository.resolve(commitBId); if (commitB == null) { throw new IllegalArgumentException("Invalid commit id " + commitBId); } RevTree treeA; try (RevWalk revWalkA = new RevWalk(repository)) { treeA = revWalkA.parseTree(commitA); } RevTree treeB; try (RevWalk revWalkB = new RevWalk(repository)) { treeB = revWalkB.parseTree(commitB); } if (!request.isNoRenames()) { // Use embedded RenameDetector it works well with index and revision // history. formatter.setDetectRenames(true); int renameLimit = request.getRenameLimit(); if (renameLimit > 0) { formatter.getRenameDetector().setRenameLimit(renameLimit); } } return formatter.scan(treeA, treeB); }
From source file:org.eclipse.egit.bc.BeyondCompareRepositoryActionHandler.java
License:Open Source License
protected List<PreviousCommit> findPreviousCommits() throws IOException { List<PreviousCommit> result = new ArrayList<PreviousCommit>(); Repository repository = getRepository(); IResource resource = getSelectedResources()[0]; String path = RepositoryMapping.getMapping(resource.getProject()).getRepoRelativePath(resource); RevWalk rw = new RevWalk(repository); try {/*from w w w .j a va 2s .c o m*/ if (path.length() > 0) { FollowFilter filter = FollowFilter.create(path); rw.setTreeFilter(filter); } RevCommit headCommit = rw.parseCommit(repository.getRef(Constants.HEAD).getObjectId()); rw.markStart(headCommit); headCommit = rw.next(); if (headCommit == null) return result; List<RevCommit> directParents = Arrays.asList(headCommit.getParents()); RevCommit previousCommit = rw.next(); while (previousCommit != null && result.size() < directParents.size()) { if (directParents.contains(previousCommit)) { String previousPath = getPreviousPath(repository, rw.getObjectReader(), headCommit, previousCommit, path); result.add(new PreviousCommit(previousCommit, previousPath)); } previousCommit = rw.next(); } } finally { rw.dispose(); } return result; }
From source file:org.eclipse.egit.bc.BeyondCompareWithHeadActionHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { final Repository repository = getRepository(true, event); // assert all resources map to the same repository if (repository == null) return null; final IResource[] resources = getSelectedResources(event); if (resources.length == 1 && resources[0] instanceof IFile) { final IFile baseFile = (IFile) resources[0]; try {/* w w w .j a v a 2s . c o m*/ RepositoryMapping mapping = RepositoryMapping.getMapping(baseFile.getProject()); String repoRelativeBasePath = mapping.getRepoRelativePath(baseFile); Repository localRepo = mapping.getRepository(); RevCommit commit = getHeadRevision(repository, repoRelativeBasePath); String rightFilePath = BeyondCompareUtil.getCompareFilePath(repoRelativeBasePath, commit, localRepo); String leftFilePath = baseFile.getLocation().toFile().getAbsolutePath(); BeyondCompareUtil.execBeyondCompare(leftFilePath, rightFilePath); } catch (Exception e) { Activator.handleError(UIText.CompareWithHeadActionHandler_onError, e, true); } return null; } else { CompareTreeView view; try { view = (CompareTreeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .showView(CompareTreeView.ID); try { Ref head = repository.getRef(Constants.HEAD); if (head == null || head.getObjectId() == null) { // Initial commit case Shell shell = HandlerUtil.getActiveShell(event); MessageDialog.openInformation(shell, UIText.CompareWithHeadActionHandler_NoHeadTitle, UIText.CompareWithHeadActionHandler_NoHeadMessage); } else view.setInput(resources, Repository.shortenRefName(head.getTarget().getName())); } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); return null; } } catch (PartInitException e) { Activator.handleError(e.getMessage(), e, true); return null; } return null; } }
From source file:org.eclipse.egit.bc.BeyondCompareWithHeadActionHandler.java
License:Open Source License
private static RevCommit getHeadRevision(Repository repository, String repoRelativePath) throws MissingObjectException, IncorrectObjectTypeException, IOException { Ref head = repository.getRef(Constants.HEAD); if (head == null || head.getObjectId() == null) // Initial import, not yet a HEAD commit return null; RevCommit latestFileCommit;//w w w . j av a2 s . c o m RevWalk rw = new RevWalk(repository); try { RevCommit headCommit = rw.parseCommit(head.getObjectId()); rw.markStart(headCommit); rw.setTreeFilter(AndTreeFilter.create(PathFilter.create(repoRelativePath), TreeFilter.ANY_DIFF)); latestFileCommit = rw.next(); // Fall back to HEAD if (latestFileCommit == null) latestFileCommit = headCommit; } finally { rw.release(); } return latestFileCommit; }
From source file:org.eclipse.egit.core.CommitUtil.java
License:Open Source License
/** * Returns whether the commits are on the current branch, ie. if they are * reachable from the current HEAD.//from w w w . j a v a 2 s. co m * * @param commits * the commits to check * @param repository * the repository * @return true if the commits are reachable from HEAD * @throws IOException * if there is an I/O error */ public static boolean areCommitsInCurrentBranch(Collection<RevCommit> commits, Repository repository) throws IOException { try (RevWalk walk = new RevWalk(repository)) { ObjectId headCommitId = repository.resolve(Constants.HEAD); RevCommit headCommit = walk.parseCommit(headCommitId); for (final RevCommit commit : commits) { walk.reset(); walk.markStart(headCommit); RevFilter revFilter = new RevFilter() { @Override public boolean include(RevWalk walker, RevCommit cmit) throws StopWalkException, MissingObjectException, IncorrectObjectTypeException, IOException { return cmit.equals(commit); } @Override public RevFilter clone() { return null; } }; walk.setRevFilter(revFilter); if (walk.next() == null) return false; } return true; } }
From source file:org.eclipse.egit.core.internal.GitRepositoryProviderType.java
License:Open Source License
/** * Creates {@link GitRepositoryProviderType} *//*from w ww . j a v a2 s. com*/ public GitRepositoryProviderType() { GitSynchronizeDataSet set = new GitSynchronizeDataSet(); try { Repository[] repositories = Activator.getDefault().getRepositoryCache().getAllRepositories(); for (int i = 0; i < repositories.length; i++) { GitSynchronizeData data = new GitSynchronizeData(repositories[i], Constants.HEAD, Constants.HEAD, true); set.add(data); } } catch (IOException e) { // do nothing } GitResourceVariantTreeSubscriber gitSubscriber = new GitResourceVariantTreeSubscriber(set); gitSubscriber.init(new NullProgressMonitor()); subscriber = gitSubscriber; }
From source file:org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.java
License:Open Source License
private IndexDiffData calcIndexDiffDataIncremental(IProgressMonitor monitor, String jobName, Collection<String> filesToUpdate, Collection<IResource> resourcesToUpdate) throws IOException { if (indexDiffData == null) // Incremental update not possible without prior indexDiffData // -> do full refresh instead return calcIndexDiffDataFull(monitor, jobName); EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(monitor); List<String> treeFilterPaths = calcTreeFilterPaths(filesToUpdate); WorkingTreeIterator iterator = IteratorService.createInitialIterator(repository); if (iterator == null) return null; // workspace is closed IndexDiff diffForChangedResources = new IndexDiff(repository, Constants.HEAD, iterator); diffForChangedResources.setFilter(PathFilterGroup.createFromStrings(treeFilterPaths)); diffForChangedResources.diff(jgitMonitor, 0, 0, jobName); return new IndexDiffData(indexDiffData, filesToUpdate, resourcesToUpdate, diffForChangedResources); }
From source file:org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.java
License:Open Source License
private IndexDiffData calcIndexDiffDataFull(IProgressMonitor monitor, String jobName) throws IOException { EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(monitor); IndexDiff newIndexDiff;//ww w. j a v a 2 s . c o m WorkingTreeIterator iterator = IteratorService.createInitialIterator(repository); if (iterator == null) return null; // workspace is closed newIndexDiff = new IndexDiff(repository, Constants.HEAD, iterator); newIndexDiff.diff(jgitMonitor, 0, 0, jobName); return new IndexDiffData(newIndexDiff); }
From source file:org.eclipse.egit.core.internal.storage.GitFileHistory.java
License:Open Source License
private IFileRevision[] buildRevisions(final IProgressMonitor monitor, final int flags) { if (walk == null) return NO_REVISIONS; final RevCommit root; try {//from w w w . j a va 2s . com final AnyObjectId headId = db.resolve(Constants.HEAD); if (headId == null) { Activator.logError( NLS.bind(CoreText.GitFileHistory_noHeadRevisionAvailable, resource.getProject().getName()), null); return NO_REVISIONS; } root = walk.parseCommit(headId); if ((flags & SINGLE_REVISION) == SINGLE_REVISION) { // If all Eclipse wants is one revision it probably is // for the editor "quick diff" feature. We can pass off // just the repository HEAD, even though it may not be // the revision that most recently modified the path. // final CommitFileRevision single; single = new CommitFileRevision(db, root, gitPath); return new IFileRevision[] { single }; } walk.markStart(root); } catch (IOException e) { Activator.logError( NLS.bind(CoreText.GitFileHistory_invalidHeadRevision, resource.getProject().getName()), e); return NO_REVISIONS; } final KidCommitList list = new KidCommitList(); list.source(walk); try { for (;;) { final int oldsz = list.size(); list.fillTo(oldsz + BATCH_SIZE - 1); if (oldsz == list.size()) break; if (monitor != null && monitor.isCanceled()) break; } } catch (IOException e) { Activator.logError(NLS.bind(CoreText.GitFileHistory_errorParsingHistory, resource.getFullPath()), e); return NO_REVISIONS; } final IFileRevision[] r = new IFileRevision[list.size()]; for (int i = 0; i < r.length; i++) r[i] = new CommitFileRevision(db, list.get(i), gitPath); return r; }