git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] Drop the non-structured compare
@ 2007-04-19 19:10 Robin Rosenberg
  2007-04-19 19:10 ` [PATCH 2/3] Add compare with previous action Robin Rosenberg
  2007-04-19 19:10 ` [PATCH 3/3] Show patch name in history view Robin Rosenberg
  0 siblings, 2 replies; 4+ messages in thread
From: Robin Rosenberg @ 2007-04-19 19:10 UTC (permalink / raw)
  To: spearce; +Cc: git


---

 .../src/org/spearce/egit/ui/GitHistoryPage.java    |   11 +----------
 .../internal/actions/GitCompareRevisionAction.java |    2 +-
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
index 3057344..bd80324 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
@@ -57,7 +57,6 @@ import org.eclipse.team.core.history.IFileHistory;
 import org.eclipse.team.core.history.IFileHistoryProvider;
 import org.eclipse.team.core.history.IFileRevision;
 import org.eclipse.team.internal.ui.TeamUIMessages;
-import org.eclipse.team.internal.ui.actions.CompareRevisionAction;
 import org.eclipse.team.internal.ui.history.DialogHistoryPageSite;
 import org.eclipse.team.ui.history.HistoryPage;
 import org.eclipse.team.ui.history.IHistoryCompareAdapter;
@@ -103,10 +102,8 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 		if (parentSite != null && parentSite instanceof DialogHistoryPageSite)
 			parentSite.setSelectionProvider(viewer);
 
-		final CompareRevisionAction compareAction = new CompareRevisionAction(
+		final GitCompareRevisionAction compareAction = new GitCompareRevisionAction(
 				"Compare");
-		final GitCompareRevisionAction compareActionNG = new GitCompareRevisionAction(
-				"Compare NG");
 		tree.addSelectionListener(new SelectionAdapter() {
 			public void widgetSelected(SelectionEvent e) {
 				// update the current
@@ -119,20 +116,14 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 				compareAction.setCurrentFileRevision(fileRevisions[0]);
 				compareAction.selectionChanged(new StructuredSelection(
 						selection2));
-
-				compareActionNG.setCurrentFileRevision(fileRevisions[0]);
-				compareActionNG.selectionChanged(new StructuredSelection(
-						selection2));
 			}
 		});
 		compareAction.setPage(this);
-		compareActionNG.setPage(this);
 		MenuManager menuMgr = new MenuManager();
 		Menu menu = menuMgr.createContextMenu(tree);
 		menuMgr.addMenuListener(new IMenuListener() {
 			public void menuAboutToShow(IMenuManager menuMgr) {
 				menuMgr.add(compareAction);
-				menuMgr.add(compareActionNG);
 			}
 		});
 		menuMgr.setRemoveAllWhenShown(true);
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/GitCompareRevisionAction.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/GitCompareRevisionAction.java
index 9a0b378..9487197 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/GitCompareRevisionAction.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/GitCompareRevisionAction.java
@@ -188,7 +188,7 @@ public class GitCompareRevisionAction extends BaseSelectionListenerAction {
 			return shouldShow();
 		}
 		else if (selection.size() == 2){
-			this.setText(TeamUIMessages.CompareRevisionAction_CompareWithOther+" NG");
+			this.setText(TeamUIMessages.CompareRevisionAction_CompareWithOther);
 			return shouldShow();
 		}
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] Add compare with previous action.
  2007-04-19 19:10 [PATCH 1/3] Drop the non-structured compare Robin Rosenberg
@ 2007-04-19 19:10 ` Robin Rosenberg
  2007-04-19 19:10 ` [PATCH 3/3] Show patch name in history view Robin Rosenberg
  1 sibling, 0 replies; 4+ messages in thread
From: Robin Rosenberg @ 2007-04-19 19:10 UTC (permalink / raw)
  To: spearce; +Cc: git

When only one item is selected, add a compare action for the previous
version. 

This solution has a wart, such that when two consequent commits are
selected the menu shows only a "Show commit diff".

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---

 .../src/org/spearce/egit/ui/GitHistoryPage.java    |   32 +++++++++++++++++++++++
 .../internal/actions/GitCompareRevisionAction.java |   15 ++++++++++-
 2 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
index bd80324..5655105 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
@@ -16,10 +16,12 @@
  */
 package org.spearce.egit.ui;
 
+import java.io.IOException;
 import java.util.Date;
 
 import org.eclipse.compare.CompareConfiguration;
 import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IResourceChangeEvent;
 import org.eclipse.core.resources.IResourceChangeListener;
@@ -61,8 +63,12 @@ import org.eclipse.team.internal.ui.history.DialogHistoryPageSite;
 import org.eclipse.team.ui.history.HistoryPage;
 import org.eclipse.team.ui.history.IHistoryCompareAdapter;
 import org.eclipse.team.ui.history.IHistoryPageSite;
+import org.spearce.egit.core.GitProvider;
 import org.spearce.egit.core.internal.mapping.GitFileRevision;
+import org.spearce.egit.core.project.RepositoryMapping;
 import org.spearce.egit.ui.internal.actions.GitCompareRevisionAction;
+import org.spearce.jgit.lib.Commit;
+import org.spearce.jgit.lib.ObjectId;
 
 public class GitHistoryPage extends HistoryPage implements IAdaptable,
 		IHistoryCompareAdapter {
@@ -104,6 +110,8 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 
 		final GitCompareRevisionAction compareAction = new GitCompareRevisionAction(
 				"Compare");
+		final GitCompareRevisionAction compareActionPrev = new GitCompareRevisionAction(
+				"Show commit");
 		tree.addSelectionListener(new SelectionAdapter() {
 			public void widgetSelected(SelectionEvent e) {
 				// update the current
@@ -116,14 +124,38 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 				compareAction.setCurrentFileRevision(fileRevisions[0]);
 				compareAction.selectionChanged(new StructuredSelection(
 						selection2));
+				IProject project = ((IResource) getInput()).getProject();
+				GitProvider provider = (GitProvider)RepositoryProvider
+						.getProvider(project);
+				RepositoryMapping repositoryMapping = provider.getData().getRepositoryMapping(project);
+				ObjectId parentId = (ObjectId)((GitFileRevision)selection2[0]).getCommit().getParentIds().get(0);
+				try {
+					if (selection2.length == 1) {
+						Commit parent = repositoryMapping.getRepository().mapCommit(parentId);
+						IFileRevision previous = new GitFileRevision(parent,
+								((GitFileRevision)selection2[0]).getResource(),
+								((GitFileRevision)selection2[0]).getCount()+1);
+//						compareActionPrev.setCurrentFileRevision(selection2[0]);
+						compareActionPrev.setCurrentFileRevision(null);
+						compareActionPrev.selectionChanged(new StructuredSelection(new IFileRevision[] {selection2[0], previous}));
+					} else {
+						compareActionPrev.setCurrentFileRevision(null);
+						compareActionPrev.selectionChanged(new StructuredSelection(new IFileRevision[0]));
+					}
+				} catch (IOException e1) {
+					// TODO Auto-generated catch block
+					e1.printStackTrace();
+				}
 			}
 		});
 		compareAction.setPage(this);
+		compareActionPrev.setPage(this);
 		MenuManager menuMgr = new MenuManager();
 		Menu menu = menuMgr.createContextMenu(tree);
 		menuMgr.addMenuListener(new IMenuListener() {
 			public void menuAboutToShow(IMenuManager menuMgr) {
 				menuMgr.add(compareAction);
+				menuMgr.add(compareActionPrev);
 			}
 		});
 		menuMgr.setRemoveAllWhenShown(true);
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/GitCompareRevisionAction.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/GitCompareRevisionAction.java
index 9487197..d5780a5 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/GitCompareRevisionAction.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/GitCompareRevisionAction.java
@@ -32,8 +32,10 @@ import org.eclipse.ui.IReusableEditor;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.actions.BaseSelectionListenerAction;
 import org.spearce.egit.core.GitWorkspaceFileRevision;
+import org.spearce.egit.core.internal.mapping.GitFileRevision;
 import org.spearce.egit.ui.internal.GitCompareFileRevisionEditorInput;
 import org.spearce.egit.ui.internal.GitResourceNode;
+import org.spearce.jgit.lib.ObjectId;
 
 /**
  * Action to invoke a Git based compare on selected revivsions in the history window.
@@ -188,7 +190,18 @@ public class GitCompareRevisionAction extends BaseSelectionListenerAction {
 			return shouldShow();
 		}
 		else if (selection.size() == 2){
-			this.setText(TeamUIMessages.CompareRevisionAction_CompareWithOther);
+			IFileRevision rev1=(IFileRevision)selection.toArray()[0];
+			IFileRevision rev2=(IFileRevision)selection.toArray()[1];
+			System.out.println("Compare "+rev1.getContentIdentifier()+" with "+rev2.getContentIdentifier());
+			if (rev1 instanceof GitFileRevision && rev2 instanceof GitFileRevision) {
+				ObjectId pid = (ObjectId) ((GitFileRevision)rev1).getCommit().getParentIds().get(0);
+				if (pid.equals(((GitFileRevision)rev2).getCommit().getCommitId())) {
+					this.setText("Show commit diff");
+				} else {
+					this.setText(TeamUIMessages.CompareRevisionAction_CompareWithOther);
+				}
+			} else
+				this.setText(TeamUIMessages.CompareRevisionAction_CompareWithOther);
 			return shouldShow();
 		}
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] Show patch name in history view
  2007-04-19 19:10 [PATCH 1/3] Drop the non-structured compare Robin Rosenberg
  2007-04-19 19:10 ` [PATCH 2/3] Add compare with previous action Robin Rosenberg
@ 2007-04-19 19:10 ` Robin Rosenberg
  2007-04-20  6:28   ` Shawn O. Pearce
  1 sibling, 1 reply; 4+ messages in thread
From: Robin Rosenberg @ 2007-04-19 19:10 UTC (permalink / raw)
  To: spearce; +Cc: git

Substitute commit id for patch name if a commit represents a patch state.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---

 .../src/org/spearce/egit/ui/GitHistoryPage.java    |   20 ++++++++++++
 .../src/org/spearce/jgit/lib/Repository.java       |   38 +++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
index 5655105..c72e1f1 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
@@ -18,6 +18,7 @@ package org.spearce.egit.ui;
 
 import java.io.IOException;
 import java.util.Date;
+import java.util.Map;
 
 import org.eclipse.compare.CompareConfiguration;
 import org.eclipse.compare.structuremergeviewer.ICompareInput;
@@ -69,6 +70,7 @@ import org.spearce.egit.core.project.RepositoryMapping;
 import org.spearce.egit.ui.internal.actions.GitCompareRevisionAction;
 import org.spearce.jgit.lib.Commit;
 import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.Repository.StGitPatch;
 
 public class GitHistoryPage extends HistoryPage implements IAdaptable,
 		IHistoryCompareAdapter {
@@ -198,6 +200,11 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 				String rss = ((IFileRevision) element).getURI().toString();
 				String rs = rss.substring(rss.length()-10);
 				String id = ((IFileRevision) element).getContentIdentifier();
+				if (appliedPatches!=null) {
+					StGitPatch patch = (StGitPatch) appliedPatches.get(new ObjectId(id));
+					if (patch!=null)
+						return patch.getName();
+				}
 				if (id != null)
 					if (id.length() > 9) // make sure "Workspace" is spelled out
 						return id.substring(0, 7) + "..";
@@ -280,6 +287,8 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 		viewer.setInput(getInput());
 	}
 
+	private Map appliedPatches;
+
 	class GitHistoryContentProvider implements ITreeContentProvider,
 			ILazyTreeContentProvider {
 
@@ -288,8 +297,17 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 				return;
 			System.out.println("inputChanged(" + viewer + "," + oldInput + ","
 					+ newInput);
+			IProject project = ((IResource) getInput()).getProject();
 			RepositoryProvider provider = RepositoryProvider
-					.getProvider(((IResource) getInput()).getProject());
+					.getProvider(project);
+			RepositoryMapping repositoryMapping = ((GitProvider)provider).getData().getRepositoryMapping(project);
+			try {
+				appliedPatches = null;
+				appliedPatches = repositoryMapping.getRepository().getAppliedPatches();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
 			IFileHistoryProvider fileHistoryProvider = provider
 					.getFileHistoryProvider();
 			IFileHistory fileHistoryFor = fileHistoryProvider
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index 5c31092..501dcc8 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -27,6 +27,7 @@ import java.lang.ref.Reference;
 import java.lang.ref.SoftReference;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.WeakHashMap;
 
@@ -477,6 +478,43 @@ public class Repository {
 		}
 	}
 
+	public static class StGitPatch {
+		public StGitPatch(String patchName, ObjectId id) {
+			name = patchName;
+			gitId = id;
+		}
+		public ObjectId getGitId() {
+			return gitId;
+		}
+		public String getName() {
+			return name;
+		}
+		private String name;
+		private ObjectId gitId;		
+	}
+
+	/**
+	 * @return applied patches in a map indexed on current commit id
+	 * @throws IOException
+	 */
+	public Map getAppliedPatches() throws IOException {
+		Map ret = new HashMap();
+		if (isStGitMode()) {
+			File patchDir = new File(new File(getDirectory(),"patches"),getBranch());
+			BufferedReader apr = new BufferedReader(new FileReader(new File(patchDir,"applied")));
+			for (String patchName=apr.readLine(); patchName!=null; patchName=apr.readLine()) {
+				File topFile = new File(new File(new File(patchDir,"patches"), patchName), "top");
+				BufferedReader tfr = new BufferedReader(new FileReader(topFile));
+				String objectId = tfr.readLine();
+				ObjectId id = new ObjectId(objectId);
+				ret.put(id, new StGitPatch(patchName, id));
+				tfr.close();
+			}
+			apr.close();
+		}
+		return ret;
+	}
+	
 	private Collection listFilesRecursively(File root, File start) {
 		if (start == null)
 			start = root;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 3/3] Show patch name in history view
  2007-04-19 19:10 ` [PATCH 3/3] Show patch name in history view Robin Rosenberg
@ 2007-04-20  6:28   ` Shawn O. Pearce
  0 siblings, 0 replies; 4+ messages in thread
From: Shawn O. Pearce @ 2007-04-20  6:28 UTC (permalink / raw)
  To: Robin Rosenberg; +Cc: git

Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
> Substitute commit id for patch name if a commit represents a patch state.

Thanks; all 3 are applied and pushed.

-- 
Shawn.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-04-20  6:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-19 19:10 [PATCH 1/3] Drop the non-structured compare Robin Rosenberg
2007-04-19 19:10 ` [PATCH 2/3] Add compare with previous action Robin Rosenberg
2007-04-19 19:10 ` [PATCH 3/3] Show patch name in history view Robin Rosenberg
2007-04-20  6:28   ` Shawn O. Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).