summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJens Baumgart2010-04-15 04:37:17 (EDT)
committer Stefan Lay2010-04-15 04:37:17 (EDT)
commit9a3c2433a75c8da0350b889ef7499c2a86a10e98 (patch)
tree7f80b67b6d9204cb32d2496fd829b85ace9365ca
parentbdfbb0e9dcfe40f6a86e04070d2e3c0eb7a0d462 (diff)
downloadegit-9a3c2433a75c8da0350b889ef7499c2a86a10e98.zip
egit-9a3c2433a75c8da0350b889ef7499c2a86a10e98.tar.gz
egit-9a3c2433a75c8da0350b889ef7499c2a86a10e98.tar.bz2
Implement view revision action in history viewrefs/changes/53/553/2
A view revision action (label: open) was added to the history view. The action can be triggered on one or more commits. Read only editors are opend showing the selected revision(s) of the current resource in the selected commits. Change-Id: I7ce36794460f6c9cc89ae2e8a66e9216b076d624 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com> Signed-off-by: Stefan Lay <stefan.lay@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java15
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java93
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties5
3 files changed, 113 insertions, 0 deletions
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 5ecb2dd..b31c08e 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
@@ -202,9 +202,24 @@ public class UIText extends NLS {
public static String GitHistoryPage_FileNotInCommit;
/** */
+ public static String GitHistoryPage_fileNotFound;
+
+ /** */
public static String GitHistoryPage_find;
/** */
+ public static String GitHistoryPage_notContainedInCommits;
+
+ /** */
+ public static String GitHistoryPage_open;
+
+ /** */
+ public static String GitHistoryPage_openFailed;
+
+ /** */
+ public static String GitHistoryPage_seeLog;
+
+ /** */
public static String GitProjectPropertyPage_LabelBranch;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index 2d0307f..33e6ec5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -19,6 +19,8 @@ import org.eclipse.compare.CompareUI;
import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
@@ -44,6 +46,7 @@ import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.util.OpenStrategy;
@@ -56,6 +59,7 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.IndexChangedEvent;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RefsChangedEvent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryListener;
@@ -85,6 +89,7 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.team.core.history.IFileRevision;
import org.eclipse.team.internal.ui.IPreferenceIds;
import org.eclipse.team.internal.ui.TeamUIPlugin;
+import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.history.HistoryPage;
import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;
import org.eclipse.ui.IActionBars;
@@ -124,6 +129,8 @@ public class GitHistoryPage extends HistoryPage implements RepositoryListener {
private IAction compareVersionsAction = new CompareVersionsAction();
+ private IAction viewVersionsAction = new ViewVersionsAction();
+
/**
* Determine if the input can be shown in this viewer.
*
@@ -525,6 +532,7 @@ public class GitHistoryPage extends HistoryPage implements RepositoryListener {
public void menuAboutToShow(IMenuManager manager) {
popupMgr.remove(new ActionContributionItem(compareAction));
popupMgr.remove(new ActionContributionItem(compareVersionsAction));
+ popupMgr.remove(new ActionContributionItem(viewVersionsAction));
int size = ((IStructuredSelection) revObjectSelectionProvider
.getSelection()).size();
if (IFile.class.isAssignableFrom(getInput()
@@ -535,6 +543,8 @@ public class GitHistoryPage extends HistoryPage implements RepositoryListener {
else if (size == 2) {
popupMgr.add(compareVersionsAction);
}
+ if (size >=1 )
+ popupMgr.add(viewVersionsAction);
}
}
@@ -1224,4 +1234,87 @@ public class GitHistoryPage extends HistoryPage implements RepositoryListener {
}
+ private class ViewVersionsAction extends Action {
+ public ViewVersionsAction() {
+ super(UIText.GitHistoryPage_open);
+ }
+
+ @Override
+ public void run() {
+ IStructuredSelection selection = ((IStructuredSelection) revObjectSelectionProvider
+ .getSelection());
+ if (selection.size() < 1)
+ return;
+ if (!(getInput() instanceof IFile))
+ return;
+ IFile resource = (IFile) getInput();
+ final RepositoryMapping map = RepositoryMapping
+ .getMapping(resource);
+ final String gitPath = map.getRepoRelativePath(resource);
+ Iterator<?> it = selection.iterator();
+ boolean errorOccured = false;
+ List<ObjectId> ids = new ArrayList<ObjectId>();
+ while (it.hasNext()) {
+ SWTCommit commit = (SWTCommit) it.next();
+ IFileRevision rev = null;
+ try {
+ rev = getFileRevision(resource, gitPath, commit);
+ } catch (IOException e) {
+ Activator.logError(NLS.bind(
+ UIText.GitHistoryPage_errorLookingUpPath, gitPath,
+ commit.getId()), e);
+ errorOccured = true;
+ }
+ if (rev != null) {
+ try {
+ Utils.openEditor(getSite().getPage(), rev,
+ new NullProgressMonitor());
+ } catch (CoreException e) {
+ Activator.logError(UIText.GitHistoryPage_openFailed, e);
+ errorOccured = true;
+ }
+ } else {
+ ids.add(commit.getId());
+ }
+ }
+ if (errorOccured)
+ MessageDialog.openError(getSite().getShell(),
+ UIText.GitHistoryPage_openFailed,
+ UIText.GitHistoryPage_seeLog);
+ if (ids.size() > 0) {
+ String idList = ""; //$NON-NLS-1$
+ for (ObjectId objectId : ids) {
+ idList += objectId.getName() + " "; //$NON-NLS-1$
+ }
+ MessageDialog.openError(getSite().getShell(),
+ UIText.GitHistoryPage_fileNotFound, NLS.bind(
+ UIText.GitHistoryPage_notContainedInCommits,
+ gitPath, idList));
+ }
+
+ }
+
+ @Override
+ public boolean isEnabled() {
+ int size = ((IStructuredSelection) revObjectSelectionProvider
+ .getSelection()).size();
+ return IFile.class.isAssignableFrom(getInput().getClass())
+ && size >= 1;
+ }
+
+ }
+
+ private IFileRevision getFileRevision(final IFile resource,
+ final String gitPath, SWTCommit commit) throws IOException {
+
+ TreeWalk w = TreeWalk.forPath(db, gitPath, commit.getTree());
+ // check if file is contained in commit
+ if (w != null) {
+ final IFileRevision fileRevision = GitFileRevision.inCommit(db,
+ commit, gitPath, null);
+ return fileRevision;
+ }
+ return null;
+ }
+
}
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 a465b06..3ac6fd0 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
@@ -72,7 +72,12 @@ GitHistoryPage_errorLookingUpPath=IO error looking up path {0} in {1}.
GitHistoryPage_errorParsingHead=Cannot parse HEAD in: {0}
GitHistoryPage_errorReadingHeadCommit=Cannot read HEAD commit {0} in: {1}
GitHistoryPage_FileNotInCommit={0} not in {1}
+GitHistoryPage_fileNotFound=File not found
GitHistoryPage_find=Find
+GitHistoryPage_notContainedInCommits=File {0} is not contained in the commits: {1}
+GitHistoryPage_open=Open
+GitHistoryPage_openFailed=Opening Editor failed
+GitHistoryPage_seeLog=See rrror log for details
GitProjectPropertyPage_LabelBranch=Branch:
GitProjectPropertyPage_LabelGitDir=Git directory:
GitProjectPropertyPage_LabelId=Id: