use of org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput in project egit by eclipse.
the class CompareUtils method compareBetween.
/**
* Compares two explicit files specified by leftGitPath and rightGitPath
* between the two revisions leftRev and rightRev.
*
* @param repository
* The repository to load file revisions from.
* @param leftGitPath
* The repository relative path to be used for the left revision.
* @param rightGitPath
* The repository relative path to be used for the right
* revision.
* @param leftRev
* Left revision of the comparison (usually the local or "new"
* revision). Won't be used if <code>includeLocal</code> is
* <code>true</code>.
* @param rightRev
* Right revision of the comparison (usually the "old" revision).
* @param page
* If not {@null} try to re-use a compare editor on this
* page if any is available. Otherwise open a new one.
*/
public static void compareBetween(final Repository repository, final String leftGitPath, final String rightGitPath, final String leftRev, final String rightRev, final IWorkbenchPage page) {
Job job = new Job(UIText.CompareUtils_jobName) {
@Override
public IStatus run(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
final ITypedElement left;
final ITypedElement right;
try {
left = getTypedElementFor(repository, leftGitPath, leftRev);
right = getTypedElementFor(repository, rightGitPath, rightRev);
} catch (IOException e) {
return Activator.createErrorStatus(UIText.CompareWithRefAction_errorOnSynchronize, e);
}
final ITypedElement commonAncestor;
if (left != null && right != null && !GitFileRevision.INDEX.equals(leftRev) && !GitFileRevision.INDEX.equals(rightRev)) {
commonAncestor = getTypedElementForCommonAncestor(repository, rightGitPath, leftRev, rightRev);
} else {
commonAncestor = null;
}
final GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(left, right, commonAncestor, null);
in.getCompareConfiguration().setLeftLabel(leftRev);
in.getCompareConfiguration().setRightLabel(rightRev);
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
openCompareEditorRunnable(page, in);
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
use of org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput in project egit by eclipse.
the class CompareUtils method openInCompare.
/**
* Compares two files between the given commits, taking possible renames
* into account.
*
* @param commit1
* the "left" commit for the comparison editor
* @param commit2
* the "right" commit for the comparison editor
* @param commit1Path
* path to the file within commit1's tree
* @param commit2Path
* path to the file within commit2's tree
* @param repository
* the repository this commit was loaded out of
* @param workBenchPage
* the page to open the compare editor in
*/
public static void openInCompare(RevCommit commit1, RevCommit commit2, String commit1Path, String commit2Path, Repository repository, IWorkbenchPage workBenchPage) {
final ITypedElement base = CompareUtils.getFileRevisionTypedElement(commit1Path, commit1, repository);
final ITypedElement next = CompareUtils.getFileRevisionTypedElement(commit2Path, commit2, repository);
CompareEditorInput in = new GitCompareFileRevisionEditorInput(base, next, null);
CompareUtils.openInCompare(workBenchPage, in);
}
use of org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput in project egit by eclipse.
the class CompareUtils method compareHeadWithWorkingTree.
/**
* Opens a compare editor. The working tree version of the given file is
* compared with the version in the HEAD commit. Use this method if the
* given file is outide the workspace.
*
* @param repository
* @param path
*/
public static void compareHeadWithWorkingTree(Repository repository, String path) {
ITypedElement base = getHeadTypedElement(repository, path);
if (base == null)
return;
IFileRevision nextFile;
nextFile = new WorkingTreeFileRevision(new File(repository.getWorkTree(), path));
String encoding = ResourcesPlugin.getEncoding();
ITypedElement next = new FileRevisionTypedElement(nextFile, encoding);
GitCompareFileRevisionEditorInput input = new GitCompareFileRevisionEditorInput(next, base, null);
CompareUI.openCompareDialog(input);
}
use of org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput in project egit by eclipse.
the class GitOpenInCompareAction method handleGitObjectComparison.
private void handleGitObjectComparison(GitModelBlob obj, boolean reuseEditor) {
ITypedElement left;
ITypedElement right;
if (obj instanceof GitModelWorkingFile) {
IPath location = obj.getLocation();
if (location == null) {
return;
}
IFile file = ResourceUtil.getFileForLocation(location, false);
if (file == null) {
Repository repository = null;
GitModelObject modelObject = obj;
while (modelObject != null) {
if (modelObject instanceof GitModelRepository) {
repository = ((GitModelRepository) modelObject).getRepository();
break;
}
modelObject = modelObject.getParent();
}
if (repository == null) {
return;
}
left = new LocalNonWorkspaceTypedElement(repository, location);
} else {
left = SaveableCompareEditorInput.createFileElement(file);
}
right = getCachedFileElement(obj);
} else if (obj instanceof GitModelCacheFile) {
left = getCachedFileElement(obj);
right = getHeadFileElement(obj);
if (right == null)
return;
} else {
oldAction.run();
return;
}
GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(left, right, null);
IWorkbenchPage page = getWorkbenchPage(conf.getSite());
OpenInCompareAction.openCompareEditor(in, page, reuseEditor);
}
use of org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput in project egit by eclipse.
the class DiffViewer method showTwoWayFileDiff.
/**
* Shows a two-way diff between the old and new versions of a
* {@link FileDiff} in a compare editor.
*
* @param repository
* the {@link FileDiff} belongs to
* @param d
* the {@link FileDiff} to show
*/
public static void showTwoWayFileDiff(Repository repository, FileDiff d) {
String np = d.getNewPath();
String op = d.getOldPath();
RevCommit c = d.getCommit();
ObjectId[] blobs = d.getBlobs();
// extract commits
final RevCommit oldCommit;
final ObjectId oldObjectId;
if (!d.getChange().equals(ChangeType.ADD)) {
oldCommit = c.getParent(0);
oldObjectId = blobs[0];
} else {
// Initial import
oldCommit = null;
oldObjectId = null;
}
final RevCommit newCommit;
final ObjectId newObjectId;
if (d.getChange().equals(ChangeType.DELETE)) {
newCommit = null;
newObjectId = null;
} else {
newCommit = c;
newObjectId = blobs[blobs.length - 1];
}
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
if (oldCommit != null && newCommit != null && repository != null) {
IFile file = np != null ? ResourceUtil.getFileForLocation(repository, np, false) : null;
try {
if (file != null) {
CompareUtils.compare(file, repository, np, op, newCommit.getName(), oldCommit.getName(), false, page);
} else {
IPath location = new Path(repository.getWorkTree().getAbsolutePath()).append(np);
CompareUtils.compare(location, repository, newCommit.getName(), oldCommit.getName(), false, page);
}
} catch (IOException e) {
Activator.handleError(UIText.GitHistoryPage_openFailed, e, true);
}
return;
}
// still happens on initial commits
final ITypedElement oldSide = createTypedElement(repository, op, oldCommit, oldObjectId);
final ITypedElement newSide = createTypedElement(repository, np, newCommit, newObjectId);
CompareUtils.openInCompare(page, new GitCompareFileRevisionEditorInput(newSide, oldSide, null));
}
Aggregations