From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: "Shawn O. Pearce" <spearce@spearce.org>, git@vger.kernel.org
Cc: Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT RFC] Add utilities for figuring out repositories for selected resources
Date: Fri, 13 Jun 2008 01:39:56 +0200 [thread overview]
Message-ID: <1213313997-1520-2-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1213313997-1520-1-git-send-email-robin.rosenberg@dewire.com>
We want to go from selected resources to repositories and back
to any resource in those repositories
---
.../egit/ui/internal/actions/RepositoryAction.java | 50 ++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/RepositoryAction.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/RepositoryAction.java
index c4e3256..8c250ca 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/RepositoryAction.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/RepositoryAction.java
@@ -13,6 +13,8 @@ import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.team.internal.ui.actions.TeamAction;
@@ -36,6 +38,54 @@ public abstract class RepositoryAction extends TeamAction {
}
/**
+ * @return the projects hosting the selected resources
+ */
+ protected IProject[] getProjectsForSelectedResources() {
+ Set<IProject> ret = new HashSet<IProject>();
+ for (IResource resource : (IResource[])getSelectedAdaptables(getSelection(), IResource.class))
+ ret.add(resource.getProject());
+ return ret.toArray(new IProject[ret.size()]);
+ }
+
+ /**
+ * @param projects
+ * a list of projects
+ * @return the repositories that projects map to iff all projects are mapped
+ */
+ protected Repository[] getRepositoriesFor(final IProject[] projects) {
+ Set<Repository> ret = new HashSet<Repository>();
+ for (IProject project : projects) {
+ RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
+ if (repositoryMapping == null)
+ return new Repository[0];
+ ret.add(repositoryMapping.getRepository());
+ }
+ return ret.toArray(new Repository[ret.size()]);
+ }
+
+ /**
+ * List the projects with selected resources, if all projects are connected
+ * to a Git repository.
+ *
+ * @return the tracked projects affected by the current resource selection
+ */
+ public IProject[] getProjectsInRepositoryOfSelectedResources() {
+ Set<IProject> ret = new HashSet<IProject>();
+ Repository[] repositories = getRepositoriesFor(getProjectsForSelectedResources());
+ final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (IProject project : projects) {
+ RepositoryMapping mapping = RepositoryMapping.getMapping(project);
+ for (Repository repository : repositories) {
+ if (mapping != null && mapping.getRepository() == repository) {
+ ret.add(project);
+ break;
+ }
+ }
+ }
+ return ret.toArray(new IProject[ret.size()]);
+ }
+
+ /**
* Figure out which repository to use. All selected
* resources must map to the same Git repository.
*
--
1.5.5.1.178.g1f811
next prev parent reply other threads:[~2008-06-12 23:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-12 23:39 [EGIT RFC] Commit behaviour Robin Rosenberg
2008-06-12 23:39 ` Robin Rosenberg [this message]
2008-06-12 23:39 ` [EGIT RFC] Enable commit for any resource in a Git-shared project Robin Rosenberg
2008-06-13 22:07 ` [EGIT RFC] Commit behaviour Marek Zawirski
2008-06-13 22:41 ` Marek Zawirski
2008-06-14 8:40 ` Robin Rosenberg
2008-06-14 10:05 ` Robin Rosenberg
2008-06-14 9:08 ` Robin Rosenberg
2008-06-14 10:23 ` Robin Rosenberg
2008-06-15 2:00 ` Marek Zawirski
2008-06-16 2:11 ` Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1213313997-1520-2-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).