use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitAdapterFactory method getRepository.
@Nullable
private static Repository getRepository(IURIEditorInput uriInput) {
File file = getFile(uriInput);
if (file == null) {
return null;
}
Path path = new Path(file.getAbsolutePath());
RepositoryMapping mapping = RepositoryMapping.getMapping(path);
if (mapping != null) {
return mapping.getRepository();
}
Repository repository = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().getRepository(path);
return repository;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class CommitSelectionDialog method createTreeFilter.
private TreeFilter createTreeFilter() {
if (filterResources == null)
return TreeFilter.ALL;
List<TreeFilter> filters = new ArrayList<>();
for (IResource resource : filterResources) {
RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
if (mapping != null) {
DiffConfig diffConfig = mapping.getRepository().getConfig().get(DiffConfig.KEY);
String path = mapping.getRepoRelativePath(resource);
if (path != null && !"".equals(path)) {
// $NON-NLS-1$
if (resource.getType() == IResource.FILE)
filters.add(FollowFilter.create(path, diffConfig));
else
filters.add(AndTreeFilter.create(PathFilter.create(path), TreeFilter.ANY_DIFF));
}
}
}
if (filters.isEmpty())
return TreeFilter.ALL;
else if (filters.size() == 1)
return filters.get(0);
else
return OrTreeFilter.create(filters);
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitCompareEditorInput method prepareInput.
@Override
protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// make sure all resources belong to the same repository
try (RevWalk rw = new RevWalk(repository)) {
monitor.beginTask(UIText.GitCompareEditorInput_CompareResourcesTaskName, IProgressMonitor.UNKNOWN);
for (IResource resource : resources) {
RepositoryMapping map = RepositoryMapping.getMapping(resource);
if (map == null) {
throw new InvocationTargetException(new IllegalStateException(UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge));
}
if (repository != null && repository != map.getRepository())
throw new InvocationTargetException(new IllegalStateException(UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge));
String repoRelativePath = map.getRepoRelativePath(resource);
filterPathStrings.add(repoRelativePath);
DiffNode node = new DiffNode(Differencer.NO_CHANGE) {
@Override
public Image getImage() {
return FOLDER_IMAGE;
}
};
diffRoots.put(new Path(map.getRepoRelativePath(resource)), node);
repository = map.getRepository();
}
if (repository == null)
throw new InvocationTargetException(new IllegalStateException(UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge));
if (monitor.isCanceled())
throw new InterruptedException();
final RevCommit baseCommit;
try {
try {
baseCommit = rw.parseCommit(repository.resolve(baseVersion));
} catch (IOException e) {
throw new InvocationTargetException(e);
}
final RevCommit compareCommit;
if (compareVersion == null) {
compareCommit = null;
} else {
try {
compareCommit = rw.parseCommit(repository.resolve(compareVersion));
} catch (IOException e) {
throw new InvocationTargetException(e);
}
}
if (monitor.isCanceled())
throw new InterruptedException();
// set the labels
CompareConfiguration config = getCompareConfiguration();
config.setLeftLabel(compareVersion);
config.setRightLabel(baseVersion);
// set title and icon
if (resources.length == 0) {
Object[] titleParameters = new Object[] { Activator.getDefault().getRepositoryUtil().getRepositoryName(repository), CompareUtils.truncatedRevision(compareVersion), CompareUtils.truncatedRevision(baseVersion) };
setTitle(NLS.bind(UIText.GitCompareEditorInput_EditorTitle, titleParameters));
} else if (resources.length == 1) {
Object[] titleParameters = new Object[] { resources[0].getFullPath().makeRelative().toString(), CompareUtils.truncatedRevision(compareVersion), CompareUtils.truncatedRevision(baseVersion) };
setTitle(NLS.bind(UIText.GitCompareEditorInput_EditorTitleSingleResource, titleParameters));
} else {
setTitle(NLS.bind(UIText.GitCompareEditorInput_EditorTitleMultipleResources, CompareUtils.truncatedRevision(compareVersion), CompareUtils.truncatedRevision(baseVersion)));
}
// build the nodes
try {
return buildDiffContainer(baseCommit, compareCommit, monitor);
} catch (IOException e) {
throw new InvocationTargetException(e);
}
} finally {
monitor.done();
}
}
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class CompareVersionsHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = getSelection(event);
if (selection.size() == 2) {
Iterator<?> it = selection.iterator();
RevCommit commit1 = (RevCommit) it.next();
RevCommit commit2 = (RevCommit) it.next();
Object input = getPage(event).getInputInternal().getSingleItem();
Repository repo = getRepository(event);
IWorkbenchPage workBenchPage = HandlerUtil.getActiveWorkbenchWindowChecked(event).getActivePage();
if (input instanceof IFile) {
IFile resource = (IFile) input;
final RepositoryMapping map = RepositoryMapping.getMapping(resource);
if (map != null) {
final String gitPath = map.getRepoRelativePath(resource);
final String commit1Path = getRenamedPath(gitPath, commit1);
final String commit2Path = getRenamedPath(gitPath, commit2);
CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, map.getRepository(), workBenchPage);
}
} else if (input instanceof File) {
File fileInput = (File) input;
final String gitPath = getRepoRelativePath(repo, fileInput);
final String commit1Path = getRenamedPath(gitPath, commit1);
final String commit2Path = getRenamedPath(gitPath, commit2);
CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, repo, workBenchPage);
} else if (input instanceof IResource) {
GitCompareEditorInput compareInput = new GitCompareEditorInput(commit1.name(), commit2.name(), repo, (IResource) input);
CompareUtils.openInCompare(workBenchPage, compareInput);
} else if (input == null) {
GitCompareEditorInput compareInput = new GitCompareEditorInput(commit1.name(), commit2.name(), repo);
CompareUtils.openInCompare(workBenchPage, compareInput);
}
}
return null;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class CompareVersionsInTreeHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = getSelection(event);
if (selection.size() == 2) {
Iterator<?> it = selection.iterator();
RevCommit commit1 = (RevCommit) it.next();
RevCommit commit2 = (RevCommit) it.next();
HistoryPageInput pageInput = getPage(event).getInputInternal();
Object input = pageInput.getSingleItem();
Repository repository = pageInput.getRepository();
IWorkbenchPage workBenchPage = HandlerUtil.getActiveWorkbenchWindowChecked(event).getActivePage();
// available in this case in the UI
if (input instanceof IFile) {
IFile resource = (IFile) input;
final RepositoryMapping map = RepositoryMapping.getMapping(resource);
if (map != null) {
final String gitPath = map.getRepoRelativePath(resource);
final String commit1Path = getRenamedPath(gitPath, commit1);
final String commit2Path = getRenamedPath(gitPath, commit2);
CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, map.getRepository(), workBenchPage);
}
} else if (input instanceof File) {
File fileInput = (File) input;
Repository repo = getRepository(event);
final String gitPath = getRepoRelativePath(repo, fileInput);
final String commit1Path = getRenamedPath(gitPath, commit1);
final String commit2Path = getRenamedPath(gitPath, commit2);
CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, repo, workBenchPage);
} else if (input instanceof IResource) {
CompareTreeView view;
try {
view = (CompareTreeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(CompareTreeView.ID);
view.setInput(new IResource[] { (IResource) input }, commit1.getId().name(), commit2.getId().name());
} catch (PartInitException e) {
Activator.handleError(e.getMessage(), e, true);
}
} else if (input == null) {
CompareTreeView view;
try {
view = (CompareTreeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(CompareTreeView.ID);
view.setInput(repository, commit1.getId().name(), commit2.getId().name());
} catch (PartInitException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
}
return null;
}
Aggregations