use of org.eclipse.egit.core.internal.storage.WorkspaceFileRevision in project egit by eclipse.
the class CompareUtils method compareHeadWithWorkspace.
/**
* Opens a compare editor. The workspace version of the given file is
* compared with the version in the HEAD commit.
*
* @param repository
* @param file
*/
public static void compareHeadWithWorkspace(Repository repository, @NonNull IFile file) {
RepositoryMapping mapping = RepositoryMapping.getMapping(file);
if (mapping == null) {
Activator.error(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, file.getLocation(), repository), null);
return;
}
String path = mapping.getRepoRelativePath(file);
ITypedElement base = getHeadTypedElement(repository, path);
if (base == null)
return;
IFileRevision nextFile = new WorkspaceFileRevision(file);
String encoding = null;
try {
encoding = file.getCharset();
} catch (CoreException e) {
Activator.handleError(UIText.CompareUtils_errorGettingEncoding, e, true);
}
ITypedElement next = new FileRevisionTypedElement(nextFile, encoding);
GitCompareFileRevisionEditorInput input = new GitCompareFileRevisionEditorInput(next, base, null);
CompareUI.openCompareDialog(input);
}
use of org.eclipse.egit.core.internal.storage.WorkspaceFileRevision in project egit by eclipse.
the class GitModelSynchronizeParticipant method asCompareInput.
@Override
public ICompareInput asCompareInput(Object object) {
final ICompareInput input = super.asCompareInput(object);
final ISynchronizationContext ctx = getContext();
if (input instanceof ResourceDiffCompareInput && ctx instanceof SubscriberMergeContext) {
// Team only considers local resources as "left"
// We'll use the cached data instead as left could be remote
final IResource resource = ((ResourceNode) input.getLeft()).getResource();
final Subscriber subscriber = ((SubscriberMergeContext) ctx).getSubscriber();
if (resource instanceof IFile && subscriber instanceof GitResourceVariantTreeSubscriber) {
try {
final IFileRevision revision = ((GitResourceVariantTreeSubscriber) subscriber).getSourceFileRevision((IFile) resource);
if (revision == null) {
final ITypedElement newSource = new GitCompareFileRevisionEditorInput.EmptyTypedElement(resource.getName());
((ResourceDiffCompareInput) input).setLeft(newSource);
} else if (!(revision instanceof WorkspaceFileRevision)) {
final ITypedElement newSource = new FileRevisionTypedElement(revision, getLocalEncoding(resource));
((ResourceDiffCompareInput) input).setLeft(newSource);
}
} catch (TeamException e) {
// Keep the input from super as-is
String error = NLS.bind(UIText.GitModelSynchronizeParticipant_noCachedSourceVariant, resource.getName());
Activator.logError(error, e);
}
}
}
return input;
}
Aggregations