use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitHistoryPage method buildFilterPaths.
private ArrayList<FilterPath> buildFilterPaths(final IResource[] inResources, final File[] inFiles, final Repository db) throws IllegalStateException {
final ArrayList<FilterPath> paths;
if (inResources != null) {
paths = new ArrayList<>(inResources.length);
for (final IResource r : inResources) {
final RepositoryMapping map = RepositoryMapping.getMapping(r);
if (map == null)
continue;
if (db != map.getRepository())
throw new IllegalStateException(UIText.RepositoryAction_multiRepoSelection);
if (showAllFilter == ShowFilter.SHOWALLFOLDER) {
final String path;
// check here and use the project instead
if (r.getParent() instanceof IWorkspaceRoot)
path = map.getRepoRelativePath(r.getProject());
else
path = map.getRepoRelativePath(r.getParent());
if (path != null && path.length() > 0)
paths.add(new FilterPath(path, false));
} else if (showAllFilter == ShowFilter.SHOWALLPROJECT) {
final String path = map.getRepoRelativePath(r.getProject());
if (path != null && path.length() > 0)
paths.add(new FilterPath(path, false));
} else if (showAllFilter == ShowFilter.SHOWALLREPO) {
// nothing
} else /* if (showAllFilter == ShowFilter.SHOWALLRESOURCE) */
{
final String path = map.getRepoRelativePath(r);
if (path != null && path.length() > 0)
paths.add(new FilterPath(path, r.getType() == IResource.FILE));
}
}
} else if (inFiles != null) {
IPath workdirPath = new Path(db.getWorkTree().getPath());
IPath gitDirPath = new Path(db.getDirectory().getPath());
int segmentCount = workdirPath.segmentCount();
paths = new ArrayList<>(inFiles.length);
for (File file : inFiles) {
IPath filePath;
boolean isRegularFile;
if (showAllFilter == ShowFilter.SHOWALLFOLDER) {
filePath = new Path(file.getParentFile().getPath());
isRegularFile = false;
} else if (showAllFilter == ShowFilter.SHOWALLPROJECT || showAllFilter == ShowFilter.SHOWALLREPO)
// we don't know of projects here -> treat as SHOWALLREPO
continue;
else /* if (showAllFilter == ShowFilter.SHOWALLRESOURCE) */
{
filePath = new Path(file.getPath());
isRegularFile = file.isFile();
}
if (gitDirPath.isPrefixOf(filePath))
throw new IllegalStateException(NLS.bind(UIText.GitHistoryPage_FileOrFolderPartOfGitDirMessage, filePath.toOSString()));
IPath pathToAdd = filePath.removeFirstSegments(segmentCount).setDevice(null);
if (!pathToAdd.isEmpty())
paths.add(new FilterPath(pathToAdd.toString(), isRegularFile));
}
} else
paths = new ArrayList<>(0);
return paths;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class OpenInTextEditorHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = getSelection(event);
if (selection.size() < 1)
return null;
Object input = getPage(event).getInputInternal().getSingleFile();
if (input == null)
return null;
boolean errorOccurred = false;
List<ObjectId> ids = new ArrayList<>();
String gitPath = null;
if (input instanceof IFile) {
IFile resource = (IFile) input;
final RepositoryMapping map = RepositoryMapping.getMapping(resource);
if (map != null) {
gitPath = map.getRepoRelativePath(resource);
Iterator<?> it = selection.iterator();
while (it.hasNext()) {
RevCommit commit = (RevCommit) it.next();
String commitPath = getRenamedPath(gitPath, commit);
IFileRevision rev = null;
try {
rev = CompareUtils.getFileRevision(commitPath, commit, map.getRepository(), null);
} catch (IOException e) {
Activator.logError(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, commitPath, commit.getId()), e);
errorOccurred = true;
}
if (rev != null) {
try {
EgitUiEditorUtils.openTextEditor(getPart(event).getSite().getPage(), rev, null);
} catch (CoreException e) {
Activator.logError(e.getMessage(), e);
errorOccurred = true;
}
} else {
ids.add(commit.getId());
}
}
}
}
if (input instanceof File) {
Repository repo = getRepository(event);
File fileInput = (File) input;
gitPath = getRepoRelativePath(repo, fileInput);
Iterator<?> it = selection.iterator();
while (it.hasNext()) {
RevCommit commit = (RevCommit) it.next();
String commitPath = getRenamedPath(gitPath, commit);
IFileRevision rev = null;
try {
rev = CompareUtils.getFileRevision(commitPath, commit, repo, null);
} catch (IOException e) {
Activator.logError(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, commitPath, commit.getId()), e);
errorOccurred = true;
}
if (rev != null)
try {
EgitUiEditorUtils.openTextEditor(getPart(event).getSite().getPage(), rev, null);
} catch (CoreException e) {
Activator.logError(e.getMessage(), e);
errorOccurred = true;
}
else
ids.add(commit.getId());
}
}
if (errorOccurred)
Activator.showError(UIText.GitHistoryPage_openFailed, null);
if (ids.size() > 0) {
// $NON-NLS-1$
StringBuilder idList = new StringBuilder("");
for (ObjectId objectId : ids) idList.append(objectId.getName()).append(' ');
MessageDialog.openError(getPart(event).getSite().getShell(), UIText.GitHistoryPage_fileNotFound, NLS.bind(UIText.GitHistoryPage_notContainedInCommits, gitPath, idList.toString()));
}
return null;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class CreatePatchOperation method computeWorkspacePath.
/**
* Returns a workspace path
*
* @param path
* @param project
* @return path
*/
public static IPath computeWorkspacePath(final IPath path, final IProject project) {
RepositoryMapping rm = RepositoryMapping.getMapping(project);
if (rm == null) {
return path;
}
String repoRelativePath = rm.getRepoRelativePath(project);
// the relative path cannot be determined, return unchanged
if (repoRelativePath == null)
return path;
// repository and project at the same level
if (// $NON-NLS-1$
repoRelativePath.equals(""))
return path;
return path.removeFirstSegments(path.matchingFirstSegments(new Path(repoRelativePath)));
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitResourceVariantTreeSubscriber method refresh.
@Override
public void refresh(IResource[] resources, int depth, IProgressMonitor monitor) throws TeamException {
for (IResource resource : resources) {
// check to see if there is a full refresh
if (resource.getType() == IResource.ROOT) {
// refresh entire cache
cache = GitSyncCache.getAllData(gsds, monitor);
super.refresh(resources, depth, monitor);
return;
}
}
// not refreshing the workspace, locate and collect target resources
Map<GitSynchronizeData, Collection<String>> updateRequests = new HashMap<GitSynchronizeData, Collection<String>>();
for (IResource resource : resources) {
IProject project = resource.getProject();
GitSynchronizeData data = gsds.getData(project.getName());
if (data != null) {
RepositoryMapping mapping = RepositoryMapping.getMapping(project);
// mapping may be null if the project has been closed
if (mapping != null) {
Collection<String> paths = updateRequests.get(data);
if (paths == null) {
paths = new ArrayList<String>();
updateRequests.put(data, paths);
}
String path = mapping.getRepoRelativePath(resource);
// null path may be returned, check for this
if (path == null)
// unknown, force a refresh of the whole repository
// $NON-NLS-1$
path = "";
paths.add(path);
}
}
}
// scan only the repositories that were affected
if (!updateRequests.isEmpty()) {
// refresh cache
GitSyncCache.mergeAllDataIntoCache(updateRequests, monitor, cache);
}
super.refresh(resources, depth, monitor);
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitSubscriberMergeContext method handleResourceChange.
private void handleResourceChange(IResourceDelta delta) {
IResourceDelta[] children = delta.getAffectedChildren();
for (IResourceDelta resourceDelta : children) {
IResource resource = resourceDelta.getResource();
RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
if (mapping == null)
continue;
scanDeltaAndRefresh(mapping, resourceDelta);
}
}
Aggregations