Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Kinzler2011-02-03 08:46:25 -0500
committerChris Aniszczyk2011-02-03 11:21:11 -0500
commitd5ad12d2ea644c4800c64c284a626183f3497e68 (patch)
tree294272251df0df64bb303442d89dfa7a27c1ac79
parentd422d75ee407a7e2476c0e3358766d367e5d6878 (diff)
downloadegit-d5ad12d2ea644c4800c64c284a626183f3497e68.tar.gz
egit-d5ad12d2ea644c4800c64c284a626183f3497e68.tar.xz
egit-d5ad12d2ea644c4800c64c284a626183f3497e68.zip
Add "quick" compare and use it in history view by default
When clicking "Compare with each other" after selecting exactly two commits while showing a project, folder, or repository in the history view, we open a "quick" compare (using the Eclipse compare infrastructure) to show the structural differences instead of the Git Tree Compare view. A new menu action is added to allow to open the Tree Compare. Change-Id: I411e290131647c969b96df71eb9c7c0f899b7c6b Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/plugin.xml5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java18
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CompareUtils.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java32
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsInTreeHandler.java110
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitCompareEditorInput.java459
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties6
9 files changed, 615 insertions, 26 deletions
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 3b769330f..7b8a3f663 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -2545,6 +2545,11 @@
name="%CompareCommand.name">
</command>
<command
+ defaultHandler="org.eclipse.egit.ui.internal.history.command.CompareVersionsInTreeHandler"
+ id="org.eclipse.egit.ui.history.CompareVersionsInTree"
+ name="Compare in Tree">
+ </command>
+ <command
defaultHandler="org.eclipse.egit.ui.internal.history.command.CompareWithWorkingTreeHandler"
id="org.eclipse.egit.ui.history.CompareWithWorkingTree"
name="%CompareWithWorkTreeCommand.name">
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index 23226acc3..acd4e0454 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -2326,6 +2326,21 @@ public class UIText extends NLS {
public static String Disconnect_disconnect;
/** */
+ public static String GitCompareEditorInput_CompareResourcesTaskName;
+
+ /** */
+ public static String GitCompareEditorInput_EditorTitle;
+
+ /** */
+ public static String GitCompareEditorInput_EditorTitleMultipleResources;
+
+ /** */
+ public static String GitCompareEditorInput_EditorTitleSingleResource;
+
+ /** */
+ public static String GitCompareEditorInput_ResourcesInDifferentReposMessagge;
+
+ /** */
public static String GitCompareFileRevisionEditorInput_CompareInputTitle;
/** */
@@ -2690,6 +2705,9 @@ public class UIText extends NLS {
public static String CommitGraphTable_Committer;
/** */
+ public static String CommitGraphTable_CompareWithEachOtherInTreeMenuLabel;
+
+ /** */
public static String GitSynchronizeWizard_synchronize;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CompareUtils.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CompareUtils.java
index 52a2fac19..2a188b3f3 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CompareUtils.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CompareUtils.java
@@ -35,6 +35,7 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.egit.core.internal.storage.GitFileRevision;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.merge.GitCompareEditorInput;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.util.OpenStrategy;
import org.eclipse.jgit.dircache.DirCache;
@@ -283,7 +284,7 @@ public class CompareUtils {
for (int i = 0; i < editorRefs.length; i++) {
IEditorPart part = editorRefs[i].getEditor(false);
if (part != null
- && (part.getEditorInput() instanceof GitCompareFileRevisionEditorInput)
+ && (part.getEditorInput() instanceof GitCompareFileRevisionEditorInput || part.getEditorInput() instanceof GitCompareEditorInput)
&& part instanceof IReusableEditor
&& part.getEditorInput().equals(input)) {
return part;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
index b8f6f2bd5..0f21ab52f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
@@ -503,6 +503,11 @@ class CommitGraphTable {
popupMgr.add(getCommandContributionItem(
HistoryViewCommands.COMPARE_VERSIONS,
UIText.GitHistoryPage_CompareWithEachOtherMenuLabel));
+ if (!input.isSingleFile())
+ popupMgr
+ .add(getCommandContributionItem(
+ HistoryViewCommands.COMPARE_VERSIONS_IN_TREE,
+ UIText.CommitGraphTable_CompareWithEachOtherInTreeMenuLabel));
}
popupMgr.add(new Separator());
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java
index d5540a10d..916002fdd 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java
@@ -18,16 +18,13 @@ import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.egit.core.project.RepositoryMapping;
-import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.CompareUtils;
import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
-import org.eclipse.egit.ui.internal.dialogs.CompareTreeView;
import org.eclipse.egit.ui.internal.history.GitHistoryPage;
+import org.eclipse.egit.ui.internal.merge.GitCompareEditorInput;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
/**
* Compare the file contents of two commits.
@@ -71,29 +68,14 @@ public class CompareVersionsHandler extends AbstractHistoryCommanndHandler {
base, next, null);
openInCompare(event, in);
} 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);
- }
+ GitCompareEditorInput compareInput = new GitCompareEditorInput(
+ commit1.name(), commit2.name(), (IResource) input);
+ openInCompare(event, compareInput);
} 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);
- }
+ GitCompareEditorInput compareInput = new GitCompareEditorInput(
+ commit1.name(), commit2.name(), repository);
+ openInCompare(event, compareInput);
}
-
}
return null;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsInTreeHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsInTreeHandler.java
new file mode 100644
index 000000000..07afb786b
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsInTreeHandler.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (C) 2011, Mathias Kinzler <mathias.kinzler@sap.com>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.history.command;
+
+import java.io.File;
+import java.util.Iterator;
+
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.internal.CompareUtils;
+import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
+import org.eclipse.egit.ui.internal.dialogs.CompareTreeView;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Compare the file contents of two commits in the {@link CompareTreeView}.
+ */
+public class CompareVersionsInTreeHandler extends
+ AbstractHistoryCommanndHandler {
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IStructuredSelection selection = getSelection(getPage());
+ if (selection.size() == 2) {
+ Iterator<?> it = selection.iterator();
+ RevCommit commit1 = (RevCommit) it.next();
+ RevCommit commit2 = (RevCommit) it.next();
+
+ Object input = getPage().getInputInternal().getSingleItem();
+ Repository repository = getPage().getInputInternal()
+ .getRepository();
+ // IFile and File just for compatibility; the action should not be
+ // available in this case in the UI
+ if (input instanceof IFile) {
+ IFile resource = (IFile) input;
+ final RepositoryMapping map = RepositoryMapping
+ .getMapping(resource);
+ final String gitPath = map.getRepoRelativePath(resource);
+
+ final ITypedElement base = CompareUtils
+ .getFileRevisionTypedElement(gitPath, commit1, map
+ .getRepository());
+ final ITypedElement next = CompareUtils
+ .getFileRevisionTypedElement(gitPath, commit2, map
+ .getRepository());
+ CompareEditorInput in = new GitCompareFileRevisionEditorInput(
+ base, next, null);
+ openInCompare(event, in);
+ } else if (input instanceof File) {
+ File fileInput = (File) input;
+ Repository repo = getRepository(event);
+ final String gitPath = getRepoRelativePath(repo, fileInput);
+
+ final ITypedElement base = CompareUtils
+ .getFileRevisionTypedElement(gitPath, commit1, repo);
+ final ITypedElement next = CompareUtils
+ .getFileRevisionTypedElement(gitPath, commit2, repo);
+ CompareEditorInput in = new GitCompareFileRevisionEditorInput(
+ base, next, null);
+ openInCompare(event, in);
+ } 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;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ GitHistoryPage page = getPage();
+ if (page == null)
+ return false;
+ return getSelection(page).size() == 2;
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java
index d5824987a..c20d71c46 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java
@@ -29,6 +29,9 @@ public class HistoryViewCommands {
/** "Compare with each other" */
public static final String COMPARE_VERSIONS = "org.eclipse.egit.ui.history.CompareVersions"; //$NON-NLS-1$
+ /** "Compare in Tree Compare" */
+ public static final String COMPARE_VERSIONS_IN_TREE = "org.eclipse.egit.ui.history.CompareVersionsInTree"; //$NON-NLS-1$
+
/** "Compare with working tree" */
public static final String COMPARE_WITH_TREE = "org.eclipse.egit.ui.history.CompareWithWorkingTree"; //$NON-NLS-1$
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitCompareEditorInput.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitCompareEditorInput.java
new file mode 100644
index 000000000..d7708a88c
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitCompareEditorInput.java
@@ -0,0 +1,459 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.merge;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.compare.structuremergeviewer.DiffNode;
+import org.eclipse.compare.structuremergeviewer.Differencer;
+import org.eclipse.compare.structuremergeviewer.IDiffContainer;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.core.AdaptableFileTreeIterator;
+import org.eclipse.egit.core.internal.storage.GitFileRevision;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.FileRevisionTypedElement;
+import org.eclipse.egit.ui.internal.dialogs.CompareTreeView;
+import org.eclipse.jgit.dircache.DirCacheIterator;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.treewalk.AbstractTreeIterator;
+import org.eclipse.jgit.treewalk.CanonicalTreeParser;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.WorkingTreeIterator;
+import org.eclipse.jgit.treewalk.filter.OrTreeFilter;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * A Git-specific {@link CompareEditorInput}
+ */
+public class GitCompareEditorInput extends CompareEditorInput {
+ private static final Image FOLDER_IMAGE = PlatformUI.getWorkbench()
+ .getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
+
+ private final String baseVersion;
+
+ private final String compareVersion;
+
+ private final IResource[] resources;
+
+ private final List<String> filterPathStrings = new ArrayList<String>();
+
+ private final Map<IPath, IDiffContainer> diffRoots = new HashMap<IPath, IDiffContainer>();
+
+ private Repository repository;
+
+ /**
+ * @param compareVersion
+ * (shown on the left side in compare); currently only commit IDs
+ * are supported
+ * @param baseVersion
+ * (shown on the right side in compare); currently only commit
+ * IDs are supported
+ * @param resources
+ * as selected by the user
+ */
+ public GitCompareEditorInput(String compareVersion, String baseVersion,
+ IResource... resources) {
+ super(new CompareConfiguration());
+ this.resources = convertResourceInput(resources);
+ this.baseVersion = baseVersion;
+ this.compareVersion = compareVersion;
+ }
+
+ /**
+ * @param compareVersion
+ * (shown on the left side in compare); currently only commit IDs
+ * are supported
+ * @param baseVersion
+ * (shown on the right side in compare); currently only commit
+ * IDs are supported
+ * @param repository
+ * as selected by the user
+ */
+ public GitCompareEditorInput(String compareVersion, String baseVersion,
+ Repository repository) {
+ super(new CompareConfiguration());
+ this.resources = new IResource[0];
+ this.baseVersion = baseVersion;
+ this.compareVersion = compareVersion;
+ this.repository = repository;
+ }
+
+ @Override
+ protected Object prepareInput(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ // make sure all resources belong to the same repository
+ RevWalk rw = null;
+ try {
+ monitor.beginTask(
+ UIText.GitCompareEditorInput_CompareResourcesTaskName,
+ IProgressMonitor.UNKNOWN);
+
+ for (IResource resource : resources) {
+ RepositoryMapping map = RepositoryMapping.getMapping(resource
+ .getProject());
+ 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();
+
+ rw = new RevWalk(repository);
+
+ final RevCommit baseCommit;
+ 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), compareVersion,
+ baseVersion };
+ setTitle(NLS.bind(UIText.GitCompareEditorInput_EditorTitle,
+ titleParameters));
+ } else if (resources.length == 1) {
+ Object[] titleParameters = new Object[] {
+ resources[0].getFullPath().makeRelative().toString(),
+ compareVersion, baseVersion };
+ setTitle(NLS.bind(
+ UIText.GitCompareEditorInput_EditorTitleSingleResource,
+ titleParameters));
+ } else
+ setTitle(NLS
+ .bind(
+ UIText.GitCompareEditorInput_EditorTitleMultipleResources,
+ compareVersion, baseVersion));
+
+ // build the nodes
+ try {
+ return buildDiffContainer(baseCommit, compareCommit, monitor);
+ } catch (IOException e) {
+ throw new InvocationTargetException(e);
+ }
+ } finally {
+ if (rw != null)
+ rw.dispose();
+ monitor.done();
+ }
+ }
+
+ @Override
+ protected void contentsCreated() {
+ super.contentsCreated();
+ // select the first conflict
+ getNavigator().selectChange(true);
+ }
+
+ @Override
+ protected void handleDispose() {
+ super.handleDispose();
+ // we do NOT dispose the images, as these are shared
+ }
+
+ private IDiffContainer buildDiffContainer(RevCommit baseCommit,
+ RevCommit compareCommit, IProgressMonitor monitor)
+ throws IOException, InterruptedException {
+ boolean useIndex = compareVersion.equals(CompareTreeView.INDEX_VERSION);
+ boolean checkIgnored = false;
+
+ IDiffContainer result = new DiffNode(Differencer.CONFLICTING);
+
+ TreeWalk tw = new TreeWalk(repository);
+
+ // filter by selected resources
+ if (filterPathStrings.size() > 1) {
+ List<TreeFilter> suffixFilters = new ArrayList<TreeFilter>();
+ for (String filterPath : filterPathStrings)
+ suffixFilters.add(PathFilter.create(filterPath));
+ TreeFilter otf = OrTreeFilter.create(suffixFilters);
+ tw.setFilter(otf);
+ } else if (filterPathStrings.size() > 0)
+ tw.setFilter(PathFilter.create(filterPathStrings.get(0)));
+
+ tw.setRecursive(true);
+
+ int baseTreeIndex;
+ if (baseCommit == null) {
+ // compare workspace with something
+ checkIgnored = true;
+ baseTreeIndex = tw.addTree(new AdaptableFileTreeIterator(
+ repository, ResourcesPlugin.getWorkspace().getRoot()));
+ } else
+ baseTreeIndex = tw.addTree(new CanonicalTreeParser(null, repository
+ .newObjectReader(), baseCommit.getTree()));
+ int compareTreeIndex;
+ if (!useIndex)
+ compareTreeIndex = tw.addTree(new CanonicalTreeParser(null,
+ repository.newObjectReader(), compareCommit.getTree()));
+ else
+ // compare something with the index
+ compareTreeIndex = tw.addTree(new DirCacheIterator(repository
+ .readDirCache()));
+
+ try {
+ while (tw.next()) {
+ if (monitor.isCanceled())
+ throw new InterruptedException();
+ AbstractTreeIterator compareVersionIterator = tw.getTree(
+ compareTreeIndex, AbstractTreeIterator.class);
+ AbstractTreeIterator baseVersionIterator = tw.getTree(
+ baseTreeIndex, AbstractTreeIterator.class);
+ if (checkIgnored
+ && baseVersionIterator != null
+ && ((WorkingTreeIterator) baseVersionIterator)
+ .isEntryIgnored())
+ continue;
+
+ if (compareVersionIterator != null
+ && baseVersionIterator != null) {
+ // content exists on both sides
+ boolean equalContent = compareVersionIterator
+ .getEntryObjectId().equals(
+ baseVersionIterator.getEntryObjectId());
+ if (equalContent)
+ continue;
+ monitor.setTaskName(baseVersionIterator
+ .getEntryPathString());
+ GitFileRevision baseRev = GitFileRevision.inCommit(
+ repository, baseCommit, baseVersionIterator
+ .getEntryPathString(), tw
+ .getObjectId(baseTreeIndex));
+ GitFileRevision compareRev;
+ if (!useIndex)
+ compareRev = GitFileRevision.inCommit(repository,
+ compareCommit, compareVersionIterator
+ .getEntryPathString(), tw
+ .getObjectId(compareTreeIndex));
+ else
+ compareRev = GitFileRevision.inIndex(repository,
+ compareVersionIterator.getEntryPathString());
+
+ add(result, baseVersionIterator.getEntryPathString(),
+ new DiffNode(new FileRevisionTypedElement(baseRev),
+ new FileRevisionTypedElement(compareRev)));
+
+ } else if (baseVersionIterator != null
+ && compareVersionIterator == null) {
+ monitor.setTaskName(baseVersionIterator
+ .getEntryPathString());
+ // only on base side
+ GitFileRevision baseRev = GitFileRevision.inCommit(
+ repository, baseCommit, baseVersionIterator
+ .getEntryPathString(), tw
+ .getObjectId(baseTreeIndex));
+ add(result, baseVersionIterator.getEntryPathString(),
+ new DiffNode(Differencer.DELETION, null, null,
+ new FileRevisionTypedElement(baseRev)));
+ } else if (compareVersionIterator != null
+ && baseVersionIterator == null) {
+ monitor.setTaskName(compareVersionIterator
+ .getEntryPathString());
+ // only on compare side
+ GitFileRevision compareRev = GitFileRevision.inCommit(
+ repository, compareCommit, compareVersionIterator
+ .getEntryPathString(), tw
+ .getObjectId(compareTreeIndex));
+ add(result, compareVersionIterator.getEntryPathString(),
+ new DiffNode(Differencer.ADDITION, null, null,
+ new FileRevisionTypedElement(compareRev)));
+ }
+
+ if (monitor.isCanceled())
+ throw new InterruptedException();
+ }
+ return result;
+ } finally {
+ tw.release();
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((baseVersion == null) ? 0 : baseVersion.hashCode());
+ result = prime * result
+ + ((compareVersion == null) ? 0 : compareVersion.hashCode());
+ result = prime
+ * result
+ + ((repository == null) ? 0 : repository.getDirectory()
+ .hashCode());
+ result = prime * result + Arrays.hashCode(resources);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ GitCompareEditorInput other = (GitCompareEditorInput) obj;
+ if (baseVersion == null) {
+ if (other.baseVersion != null)
+ return false;
+ } else if (!baseVersion.equals(other.baseVersion))
+ return false;
+ if (compareVersion == null) {
+ if (other.compareVersion != null)
+ return false;
+ } else if (!compareVersion.equals(other.compareVersion))
+ return false;
+ if (repository == null) {
+ if (other.repository != null)
+ return false;
+ } else if (!repository.getDirectory().equals(
+ other.repository.getDirectory()))
+ return false;
+ if (!Arrays.equals(resources, other.resources))
+ return false;
+ return true;
+ }
+
+ private void add(IDiffContainer result, String filePath, DiffNode diffNode) {
+ IDiffContainer container = getFileParent(result, filePath);
+ container.add(diffNode);
+ diffNode.setParent(container);
+
+ }
+
+ private IDiffContainer getFileParent(IDiffContainer root, String filePath) {
+ IPath path = new Path(filePath);
+ IDiffContainer child = root;
+ if (diffRoots.isEmpty()) {
+ for (int i = 0; i < path.segmentCount() - 1; i++)
+ child = getOrCreateChild(child, path.segment(i));
+ return child;
+ } else {
+ for (Entry<IPath, IDiffContainer> entry : diffRoots.entrySet()) {
+ if (entry.getKey().isPrefixOf(path)) {
+ for (int i = entry.getKey().segmentCount(); i < path
+ .segmentCount() - 1; i++)
+ child = getOrCreateChild(child, path.segment(i));
+ return child;
+ }
+ }
+ return null;
+ }
+ }
+
+ private DiffNode getOrCreateChild(IDiffContainer parent, final String name) {
+ for (IDiffElement child : parent.getChildren()) {
+ if (child.getName().equals(name)) {
+ return ((DiffNode) child);
+ }
+ }
+ DiffNode child = new DiffNode(parent, Differencer.NO_CHANGE) {
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Image getImage() {
+ return FOLDER_IMAGE;
+ }
+ };
+ return child;
+ }
+
+ private IResource[] convertResourceInput(final IResource[] input) {
+ if (input.length > 0) {
+ // we must make sure to only show the topmost resources as roots
+ List<IResource> resourceList = new ArrayList<IResource>(
+ input.length);
+ List<IPath> allPaths = new ArrayList<IPath>(input.length);
+ for (IResource originalInput : input) {
+ allPaths.add(originalInput.getFullPath());
+ }
+ for (IResource originalInput : input) {
+ boolean skip = false;
+ for (IPath path : allPaths) {
+ if (path.isPrefixOf(originalInput.getFullPath())
+ && path.segmentCount() < originalInput
+ .getFullPath().segmentCount()) {
+ skip = true;
+ break;
+ }
+ }
+ if (!skip)
+ resourceList.add(originalInput);
+ }
+ return resourceList.toArray(new IResource[resourceList.size()]);
+ } else
+ return input;
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
index 5f9323dd2..9a5181c06 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
@@ -803,6 +803,11 @@ DiscardChangesAction_confirmActionMessage=This will discard all local changes fo
DiscardChangesAction_discardChanges=Discard Changes
Disconnect_disconnect=Disconnect
+GitCompareEditorInput_CompareResourcesTaskName=Comparing Resources
+GitCompareEditorInput_EditorTitle=Repository "{0}": comparing "{1}" with "{2}"
+GitCompareEditorInput_EditorTitleMultipleResources=Multiple Resources: comparting "{0}" with "{1}"
+GitCompareEditorInput_EditorTitleSingleResource="{0}": comparing "{1}" with "{2}"
+GitCompareEditorInput_ResourcesInDifferentReposMessagge=Resources belong to different Repositories
GitCompareFileRevisionEditorInput_CompareInputTitle={0}
GitCompareFileRevisionEditorInput_CompareTooltip=Compare {0} {1} and {2}
GitCompareFileRevisionEditorInput_CurrentRevision=Current Revision
@@ -942,6 +947,7 @@ CommitFileDiffViewer_OpenWorkingTreeVersionInEditorMenuLabel=Open Working Tree V
CommitFileDiffViewer_SelectOneCommitMessage=Please select exactly one commit
CommitGraphTable_CommitId=Id
CommitGraphTable_Committer=Committer
+CommitGraphTable_CompareWithEachOtherInTreeMenuLabel=Compare with each other in &Tree
CommitSelectionDialog_BuildingCommitListMessage=Building commit list
CommitSelectionDialog_DialogMessage=Please select a commit from the list
CommitSelectionDialog_DialogTitle={0} commits in Repository {1}

Back to the top