{"thread":{"id":"15297","subject":"[EGIT PATCH] Select all changes in repository for commit by default","startedAt":"2008-08-31T09:38:42Z","lastAt":"2008-09-02T19:00:46Z","messageCount":6,"participants":["Robin Rosenberg","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"89301","messageId":"1220175524-1523-1-git-send-email-robin.rosenberg@dewire.com","threadId":"15297","inReplyTo":null,"subject":"[EGIT PATCH] Select all changes in repository for commit by default","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-08-31T09:38:42Z","receivedAt":"2008-08-31T09:38:42Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"This is an old patch series, previously send under the subject [EGIT RFC] Commit behaviour\nnow squash and it seems to work with Eclipse 3.4 too.\n\n>This tentative feature allows me to hit the commit button\n>when any resource is selected and figure out which resources have been\n>modified. This makes it much easier to commit. Only the toolbar commit\n>is affected for now.\n\n-- robin\n"},{"id":"89302","messageId":"1220175524-1523-2-git-send-email-robin.rosenberg@dewire.com","threadId":"15297","inReplyTo":"1220175524-1523-1-git-send-email-robin.rosenberg@dewire.com","subject":"[EGIT PATCH 1/2] Add utilities for figuring out repositories for selected resources","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-08-31T09:38:43Z","receivedAt":"2008-08-31T09:38:43Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"We want to go from selected resources to repositories and back\nto any resource in those repositories\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../egit/ui/internal/actions/RepositoryAction.java |   50 ++++++++++++++++++++\n 1 files changed, 50 insertions(+), 0 deletions(-)\n\ndiff --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\nindex c4e3256..8c250ca 100644\n--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/RepositoryAction.java\n+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/RepositoryAction.java\n@@ -13,6 +13,8 @@\n import java.util.Set;\n \n import org.eclipse.core.resources.IProject;\n+import org.eclipse.core.resources.IResource;\n+import org.eclipse.core.resources.ResourcesPlugin;\n import org.eclipse.jface.action.IAction;\n import org.eclipse.jface.dialogs.MessageDialog;\n import org.eclipse.team.internal.ui.actions.TeamAction;\n@@ -36,6 +38,54 @@ public void execute(IAction action) {\n \t}\n \n \t/**\n+\t * @return the projects hosting the selected resources\n+\t */\n+\tprotected IProject[] getProjectsForSelectedResources() {\n+\t\tSet<IProject> ret = new HashSet<IProject>();\n+\t\tfor (IResource resource : (IResource[])getSelectedAdaptables(getSelection(), IResource.class))\n+\t\t\tret.add(resource.getProject());\n+\t\treturn ret.toArray(new IProject[ret.size()]);\n+\t}\n+\n+\t/**\n+\t * @param projects\n+\t *            a list of projects\n+\t * @return the repositories that projects map to iff all projects are mapped\n+\t */ \n+\tprotected Repository[] getRepositoriesFor(final IProject[] projects) {\n+\t\tSet<Repository> ret = new HashSet<Repository>();\n+\t\tfor (IProject project : projects) {\n+\t\t\tRepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);\n+\t\t\tif (repositoryMapping == null)\n+\t\t\t\treturn new Repository[0];\n+\t\t\tret.add(repositoryMapping.getRepository());\n+\t\t}\n+\t\treturn ret.toArray(new Repository[ret.size()]);\n+\t}\n+\t\n+\t/**\n+\t * List the projects with selected resources, if all projects are connected\n+\t * to a Git repository.\n+\t * \n+\t * @return the tracked projects affected by the current resource selection\n+\t */\n+\tpublic IProject[] getProjectsInRepositoryOfSelectedResources() {\n+\t\tSet<IProject> ret = new HashSet<IProject>();\n+\t\tRepository[] repositories = getRepositoriesFor(getProjectsForSelectedResources());\n+\t\tfinal IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();\n+\t\tfor (IProject project : projects) {\n+\t\t\tRepositoryMapping mapping = RepositoryMapping.getMapping(project);\n+\t\t\tfor (Repository repository : repositories) {\n+\t\t\t\tif (mapping != null && mapping.getRepository() == repository) {\n+\t\t\t\t\tret.add(project);\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t\treturn ret.toArray(new IProject[ret.size()]);\n+\t}\n+\n+\t/**\n \t * Figure out which repository to use. All selected\n \t * resources must map to the same Git repository.\n \t *\n-- \n1.6.0.rc2.35.g04c6e9\n"},{"id":"89303","messageId":"1220175524-1523-3-git-send-email-robin.rosenberg@dewire.com","threadId":"15297","inReplyTo":"1220175524-1523-2-git-send-email-robin.rosenberg@dewire.com","subject":"[EGIT PATCH 2/2] Enable commit for any resource in a Git-shared project","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-08-31T09:38:44Z","receivedAt":"2008-08-31T09:38:44Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"By default the commit dialog will be populated with all changed resources\nin the projects that contain the selected resources, provided the projects\nare associated with a Git respository.\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../egit/ui/internal/actions/CommitAction.java     |   33 +++++++++----------\n 1 files changed, 16 insertions(+), 17 deletions(-)\n\ndiff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CommitAction.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CommitAction.java\nindex 8db701c..d703048 100644\n--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CommitAction.java\n+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CommitAction.java\n@@ -68,7 +68,7 @@ public void run(IAction act) {\n \t\t\treturn;\n \t\t}\n \n-\t\tRepository[] repos = getRepositories();\n+\t\tRepository[] repos = getRepositoriesFor(getProjectsForSelectedResources());\n \t\tamendAllowed = repos.length == 1;\n \t\tfor (Repository repo : repos) {\n \t\t\tif (!repo.getRepositoryState().canCommit()) {\n@@ -124,7 +124,7 @@ private void resetState() {\n \t}\n \n \tprivate void loadPreviousCommit() {\n-\t\tIProject project = getSelectedProjects()[0];\n+\t\tIProject project = getProjectsForSelectedResources()[0];\n \n \t\tRepository repo = RepositoryMapping.getMapping(project).getRepository();\n \t\ttry {\n@@ -313,21 +313,20 @@ private void writeTreeWithSubTrees(Tree tree) throws TeamException {\n \t}\n \n \tprivate void buildIndexHeadDiffList() throws IOException {\n-\t\tfor (IProject project : getSelectedProjects()) {\n+\t\tfor (IProject project : getProjectsInRepositoryOfSelectedResources()) {\n \t\t\tRepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);\n-\t\t\tif (repositoryMapping != null) {\n-\t\t\t\tRepository repository = repositoryMapping.getRepository();\n-\t\t\t\tTree head = repository.mapTree(\"HEAD\");\n-\t\t\t\tGitIndex index = repository.getIndex();\n-\t\t\t\tIndexDiff indexDiff = new IndexDiff(head, index);\n-\t\t\t\tindexDiff.diff();\n-\n-\t\t\t\tincludeList(project, indexDiff.getAdded(), indexChanges);\n-\t\t\t\tincludeList(project, indexDiff.getChanged(), indexChanges);\n-\t\t\t\tincludeList(project, indexDiff.getRemoved(), indexChanges);\n-\t\t\t\tincludeList(project, indexDiff.getMissing(), notIndexed);\n-\t\t\t\tincludeList(project, indexDiff.getModified(), notIndexed);\n-\t\t\t}\n+\t\t\tassert repositoryMapping != null;\n+\t\t\tRepository repository = repositoryMapping.getRepository();\n+\t\t\tTree head = repository.mapTree(\"HEAD\");\n+\t\t\tGitIndex index = repository.getIndex();\n+\t\t\tIndexDiff indexDiff = new IndexDiff(head, index);\n+\t\t\tindexDiff.diff();\n+\n+\t\t\tincludeList(project, indexDiff.getAdded(), indexChanges);\n+\t\t\tincludeList(project, indexDiff.getChanged(), indexChanges);\n+\t\t\tincludeList(project, indexDiff.getRemoved(), indexChanges);\n+\t\t\tincludeList(project, indexDiff.getMissing(), notIndexed);\n+\t\t\tincludeList(project, indexDiff.getModified(), notIndexed);\n \t\t}\n \t}\n \n@@ -395,7 +394,7 @@ private boolean isChanged(RepositoryMapping map, IFile resource) {\n \n \t@Override\n \tpublic boolean isEnabled() {\n-\t\treturn getRepositories().length > 0;\n+\t\treturn getProjectsInRepositoryOfSelectedResources().length > 0;\n \t}\n \n }\n-- \n1.6.0.rc2.35.g04c6e9\n"},{"id":"89510","messageId":"20080902150323.GC28704@spearce.org","threadId":"15297","inReplyTo":"1220175524-1523-2-git-send-email-robin.rosenberg@dewire.com","subject":"Re: [EGIT PATCH 1/2] Add utilities for figuring out repositories for selected resources","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-02T15:03:23Z","receivedAt":"2008-09-02T15:03:23Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Robin Rosenberg <robin.rosenberg@dewire.com> wrote:\n> We want to go from selected resources to repositories and back\n> to any resource in those repositories\n...\n> +\tprotected Repository[] getRepositoriesFor(final IProject[] projects) {\n> +\t\tSet<Repository> ret = new HashSet<Repository>();\n> +\t\tfor (IProject project : projects) {\n> +\t\t\tRepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);\n> +\t\t\tif (repositoryMapping == null)\n> +\t\t\t\treturn new Repository[0];\n> +\t\t\tret.add(repositoryMapping.getRepository());\n> +\t\t}\n\nHmm.  So if any one of the selected projects doesn't have a Git\nrepository at its top level we just plain fail and pretend none of\nthem have a Git repository?  That doesn't seem right to me.  We\nshould just skip that project and move to another project.\n\nBut I also wonder if that really makes sense when a project could\nhave a linked resource under it that points to the repository's\nworking directory.  In such cases we want operations on that project\nto potentially impact the inner repository as maybe the project\nrepository does not have a repository itself.  IOW I'm questioning\nthe idea of getRepositoriesFor(getProjectsForSelectedResources()).\n\n-- \nShawn.\n"},{"id":"89523","messageId":"200809022053.35419.robin.rosenberg.lists@dewire.com","threadId":"15297","inReplyTo":"20080902150323.GC28704@spearce.org","subject":"Re: [EGIT PATCH 1/2] Add utilities for figuring out repositories for selected resources","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-09-02T18:53:35Z","receivedAt":"2008-09-02T18:53:35Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"tisdagen den 2 september 2008 17.03.23 skrev Shawn O. Pearce:\n> Robin Rosenberg <robin.rosenberg@dewire.com> wrote:\n> > We want to go from selected resources to repositories and back\n> > to any resource in those repositories\n> ...\n> > +\tprotected Repository[] getRepositoriesFor(final IProject[] projects) {\n> > +\t\tSet<Repository> ret = new HashSet<Repository>();\n> > +\t\tfor (IProject project : projects) {\n> > +\t\t\tRepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);\n> > +\t\t\tif (repositoryMapping == null)\n> > +\t\t\t\treturn new Repository[0];\n> > +\t\t\tret.add(repositoryMapping.getRepository());\n> > +\t\t}\n> \n> Hmm.  So if any one of the selected projects doesn't have a Git\n> repository at its top level we just plain fail and pretend none of\n> them have a Git repository?  That doesn't seem right to me.  We\n> should just skip that project and move to another project.\n\nThat is the way everything in Eclipse work. For an operation to be applicable\nto a selection, it must be applicable to eache element. Yes, I get annoyed\nat that sometimes myself, but that doesn't convince me we should be\nthe one plugin that breaks the pattern.\n\nActually what happens is that the whole action gets disabled if all projects\ndo not satisfy the criteria.\n\n> But I also wonder if that really makes sense when a project could\n> have a linked resource under it that points to the repository's\n> working directory.  In such cases we want operations on that project\n> to potentially impact the inner repository as maybe the project\n> repository does not have a repository itself.  IOW I'm questioning\n> the idea of getRepositoriesFor(getProjectsForSelectedResources()).\n\nOuch for linked resources. I really think we should ignore the link as much\nas we can. It's a trap! I any way it needs more fixing that this and not\nonly here. A patch does not have to solve all problems in the world :)\n\nI have no experience with linked resources, other that I found them enough\nawkward to use to prevent from doing that. How useful and portable is\na C:\\foo on my system? I don't mind anyone solving the problem, but it is\nvery low on my personal agenda.\n\n-- robin\n"},{"id":"89524","messageId":"20080902190046.GE28704@spearce.org","threadId":"15297","inReplyTo":"200809022053.35419.robin.rosenberg.lists@dewire.com","subject":"Re: [EGIT PATCH 1/2] Add utilities for figuring out repositories for selected resources","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-02T19:00:46Z","receivedAt":"2008-09-02T19:00:46Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Robin Rosenberg <robin.rosenberg.lists@dewire.com> wrote:\n> tisdagen den 2 september 2008 17.03.23 skrev Shawn O. Pearce:\n> > \n> > Hmm.  So if any one of the selected projects doesn't have a Git\n> > repository at its top level we just plain fail and pretend none of\n> > them have a Git repository?\n> \n> That is the way everything in Eclipse work. For an operation to be applicable\n> to a selection, it must be applicable to eache element.\n\nOK.  Good reason then.\n \n> > But I also wonder if that really makes sense when a project could\n> > have a linked resource under it that points to the repository's\n> > working directory.  In such cases we want operations on that project\n> > to potentially impact the inner repository as maybe the project\n> > repository does not have a repository itself.  IOW I'm questioning\n> > the idea of getRepositoriesFor(getProjectsForSelectedResources()).\n> \n> Ouch for linked resources. I really think we should ignore the link as much\n> as we can. It's a trap! I any way it needs more fixing that this and not\n> only here. A patch does not have to solve all problems in the world :)\n> \n> I have no experience with linked resources, other that I found them enough\n> awkward to use to prevent from doing that. How useful and portable is\n> a C:\\foo on my system? I don't mind anyone solving the problem, but it is\n> very low on my personal agenda.\n\nLinked resources are useful (sometimes), especially if the project files\nare automatically generated for you from your build system.  My prior\nday-job had a really nice build system that did this.  My current day-job\nalso has a build system that can generate Eclipse project files for you.\n\nIn both cases the project files aren't considered part of the source as\nthey can be rebuilt at any time and they both used linked resources to\npoint to the actual place where the source was stored, which typically\nwas outside of your workspace directory, while the project was within\nthe workspace directory.\n\nAnyway, I wasn't trying to suggest solving the worlds problems.\nBut RepositoryMapping is smarter now and can (mostly) handle a\nlinked resource just fine.  Its the higher level GUI actions that\nrun into trouble.\n\nI guess we should stick this series in as-is then.\n\n-- \nShawn.\n"}]}