@Override public Image getImage(Object element) { RepositoryTreeNode node = (RepositoryTreeNode) element; if (node.getType() == RepositoryTreeNodeType.TAG) { // determine if we have a lightweight tag and // use the corresponding icon RevObject any; try { ObjectId id = node.getRepository().resolve(((Ref) node.getObject()).getName()); if (id == null) return null; any = new RevWalk(node.getRepository()).parseAny(id); } catch (MissingObjectException e) { Activator.logError(e.getMessage(), e); return null; } catch (IOException e) { Activator.logError(e.getMessage(), e); return null; } if (any instanceof RevCommit) // lightweight tag return decorateImage(lightweightTagImage, element); else // annotated or signed tag return decorateImage(node.getType().getIcon(), element); } else return decorateImage(node.getType().getIcon(), element); }
private IFileRevision[] buildRevisions(final IProgressMonitor monitor, final int flags) { if (walk == null) return NO_REVISIONS; final Repository db = walk.getRepository(); final RevCommit root; try { 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; }
private void logAndUnmapGoneMappedResource(final RepositoryMapping m) { Activator.logError( MessageFormat.format(CoreText.GitProjectData_mappedResourceGone, m.toString()), new FileNotFoundException(m.getContainerPath().toString())); m.clear(); UnmapJob unmapJob = new UnmapJob(getProject()); unmapJob.schedule(); }
private UserPasswordCredentials getCredentialsFromSecureStore(final URIish uri) { UserPasswordCredentials credentials = null; try { credentials = Activator.getDefault().getSecureStore().getCredentials(uri); } catch (StorageException e) { Activator.logError(UIText.EGitCredentialsProvider_errorReadingCredentials, e); } return credentials; }
private void map(final RepositoryMapping m) { final IResource r; final File git; final IResource dotGit; IContainer c = null; m.clear(); r = getProject().findMember(m.getContainerPath()); if (r instanceof IContainer) { c = (IContainer) r; } else if (r != null) { c = Utils.getAdapter(r, IContainer.class); } if (c == null) { logAndUnmapGoneMappedResource(m); return; } m.setContainer(c); IPath absolutePath = m.getGitDirAbsolutePath(); if (absolutePath == null) { logAndUnmapGoneMappedResource(m); return; } git = absolutePath.toFile(); if (!git.isDirectory() || !new File(git, "config").isFile()) { // $NON-NLS-1$ logAndUnmapGoneMappedResource(m); return; } try { m.setRepository(Activator.getDefault().getRepositoryCache().lookupRepository(git)); } catch (IOException ioe) { logAndUnmapGoneMappedResource(m); return; } m.fireRepositoryChanged(); trace( "map " //$NON-NLS-1$ + c + " -> " //$NON-NLS-1$ + m.getRepository()); try { c.setSessionProperty(MAPPING_KEY, m); } catch (CoreException err) { Activator.logError(CoreText.GitProjectData_failedToCacheRepoMapping, err); } dotGit = c.findMember(Constants.DOT_GIT); if (dotGit != null && dotGit.getLocation().toFile().equals(git)) { protect(dotGit); } }
@Override public void reset(URIish uri) { try { Activator.getDefault().getSecureStore().clearCredentials(uri); user = null; password = null; } catch (IOException e) { Activator.logError( MessageFormat.format(UIText.EGitCredentialsProvider_FailedToClearCredentials, uri), e); } }
private void notifyListeners() { IndexDiffChangedListener[] tmpListeners; synchronized (listeners) { tmpListeners = listeners.toArray(new IndexDiffChangedListener[listeners.size()]); } for (int i = 0; i < tmpListeners.length; i++) try { tmpListeners[i].indexDiffChanged(repository, indexDiffData); } catch (RuntimeException e) { Activator.logError("Exception occured in an IndexDiffChangedListener", e); // $NON-NLS-1$ } }
@Override protected ResourceTraversal[] getTraversals(ISynchronizationContext context, Object object) { if (object instanceof IAdaptable) { ResourceMapping rm = getResourceMapping(object); GitSubscriberMergeContext ctx = (GitSubscriberMergeContext) getContext(); ResourceMappingContext rmCtx = new GitSubscriberResourceMappingContext(ctx.getSyncData()); try { return rm.getTraversals(rmCtx, new NullProgressMonitor()); } catch (CoreException e) { Activator.logError(e.getMessage(), e); } } return null; }
/** * @param p * @return {@link GitProjectData} for the specified project, or null if the Git provider is not * associated with the project or an exception occurred */ @Nullable public static synchronized GitProjectData get(final @NonNull IProject p) { try { GitProjectData d = lookup(p); if (d == null && ResourceUtil.isSharedWithGit(p)) { d = new GitProjectData(p).load(); cache(p, d); } return d; } catch (IOException err) { Activator.logError(CoreText.GitProjectData_missing, err); return null; } }
private IBranchNameProvider getBranchNameProvider() { IExtensionRegistry registry = Platform.getExtensionRegistry(); IConfigurationElement[] config = registry.getConfigurationElementsFor(BRANCH_NAME_PROVIDER_ID); if (config.length > 0) { Object provider; try { provider = config[0].createExecutableExtension("class"); // $NON-NLS-1$ if (provider instanceof IBranchNameProvider) return (IBranchNameProvider) provider; } catch (Throwable e) { Activator.logError(UIText.CreateBranchPage_CreateBranchNameProviderFailed, e); } } return null; }
private void protect(IResource resource) { IResource c = resource; while (c != null && !c.equals(getProject())) { trace("protect " + c); // $NON-NLS-1$ protectedResources.add(c); try { c.setTeamPrivateMember(true); } catch (CoreException e) { Activator.logError( MessageFormat.format(CoreText.GitProjectData_FailedToMarkTeamPrivate, c.getFullPath()), e); } c = c.getParent(); } }
private ICommitMessageProvider getCommitMessageProvider() throws CoreException { IExtensionRegistry registry = Platform.getExtensionRegistry(); IConfigurationElement[] config = registry.getConfigurationElementsFor(COMMIT_MESSAGE_PROVIDER_ID); if (config.length > 0) { Object provider; provider = config[0].createExecutableExtension("class"); // $NON-NLS-1$ if (provider instanceof ICommitMessageProvider) { return (ICommitMessageProvider) provider; } else { Activator.logError(UIText.CommitDialog_WrongTypeOfCommitMessageProvider, null); } } return null; }
/** * @param resource any workbench resource contained within this project. * @return the mapping for the specified project */ @Nullable public /* TODO static */ RepositoryMapping getRepositoryMapping(@Nullable IResource resource) { IResource r = resource; try { for (; r != null; r = r.getParent()) { final RepositoryMapping m; if (!r.isAccessible()) continue; m = (RepositoryMapping) r.getSessionProperty(MAPPING_KEY); if (m != null) return m; } } catch (CoreException err) { Activator.logError(CoreText.GitProjectData_failedFindingRepoMapping, err); } return null; }
private KidWalk buildWalk() { final RepositoryMapping rm = RepositoryMapping.getMapping(resource); if (rm == null) { Activator.logError( NLS.bind(CoreText.GitFileHistory_gitNotAttached, resource.getProject().getName()), null); return null; } final KidWalk w = new KidWalk(rm.getRepository()); gitPath = rm.getRepoRelativePath(resource); w.setTreeFilter( AndTreeFilter.create( PathFilterGroup.createFromStrings(Collections.singleton(gitPath)), TreeFilter.ANY_DIFF)); return w; }
@Override @SuppressWarnings("synthetic-access") public void resourceChanged(final IResourceChangeEvent event) { switch (event.getType()) { case IResourceChangeEvent.PRE_CLOSE: uncache((IProject) event.getResource()); break; case IResourceChangeEvent.PRE_DELETE: try { delete((IProject) event.getResource()); } catch (IOException e) { Activator.logError(e.getMessage(), e); } break; default: break; } }
public StyledString getStyledText(Object element) { if (!(element instanceof RepositoryTreeNode)) return null; RepositoryTreeNode node = (RepositoryTreeNode) element; try { switch (node.getType()) { case REPO: Repository repository = (Repository) node.getObject(); File directory = repository.getDirectory(); StyledString string = new StyledString(directory.getParentFile().getName()); string.append( " - " + directory.getAbsolutePath(), StyledString.QUALIFIER_STYLER); // $NON-NLS-1$ String branch = repository.getBranch(); if (repository.getRepositoryState() != RepositoryState.SAFE) branch += " - " + repository.getRepositoryState().getDescription(); // $NON-NLS-1$ string.append( " [" + branch + "]", StyledString.DECORATIONS_STYLER); // $NON-NLS-1$//$NON-NLS-2$ return string; case ADDITIONALREF: Ref ref = (Ref) node.getObject(); // shorten the name StyledString refName = new StyledString(Repository.shortenRefName(ref.getName())); if (ref.isSymbolic()) { refName.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$ refName.append(ref.getLeaf().getName(), StyledString.QUALIFIER_STYLER); refName.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$ refName.append( ObjectId.toString(ref.getLeaf().getObjectId()), StyledString.QUALIFIER_STYLER); } else { refName.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$ refName.append(ObjectId.toString(ref.getObjectId()), StyledString.QUALIFIER_STYLER); } return refName; case WORKINGDIR: StyledString dirString = new StyledString(UIText.RepositoriesView_WorkingDir_treenode); dirString.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$ if (node.getRepository().isBare()) { dirString.append( UIText.RepositoriesViewLabelProvider_BareRepositoryMessage, StyledString.QUALIFIER_STYLER); } else { dirString.append( node.getRepository().getWorkTree().getAbsolutePath(), StyledString.QUALIFIER_STYLER); } return dirString; case PUSH: // fall through case FETCH: // fall through case FILE: // fall through case FOLDER: // fall through case BRANCHES: // fall through case LOCAL: // fall through case REMOTETRACKING: // fall through case BRANCHHIERARCHY: // fall through case TAGS: // fall through; case ADDITIONALREFS: // fall through case REMOTES: // fall through case REMOTE: // fall through case ERROR: // fall through case REF: // fall through case TAG: { String label = getSimpleText(node); if (label != null) return new StyledString(label); } } } catch (IOException e) { Activator.logError(e.getMessage(), e); } return null; }