{"thread":{"id":"13923","subject":"[EGIT RFC] Commit behaviour","startedAt":"2008-06-12T23:39:55Z","lastAt":"2008-06-16T02:11:58Z","messageCount":11,"participants":["Robin Rosenberg","Marek Zawirski","Shawn O. Pearce"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"79654","messageId":"1213313997-1520-1-git-send-email-robin.rosenberg@dewire.com","threadId":"13923","inReplyTo":null,"subject":"[EGIT RFC] Commit behaviour","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-12T23:39:55Z","receivedAt":"2008-06-12T23:39:55Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"\nI got annoyed about having change my selection to a project to be able\nto commit. This tentative feature allows me to hit the commit button\nwhen any resource is selected and figure out which resources have been\nmodified. This makes it much easier to commit. Only the toolbar commit\nis affected for now.\n\nAnother twist would be to list all changed resources, but only enable\nthe selected ones, or only the ones in in the same projects as the selected\nresources. Comments?\n\nCode is not efficient either. This is question about the user interface.\n\nThen we could ask ourselved, should we do something similar for Checkout\nand reset too? I think that is not as important as those operations are\nmuch less frequent.\n\n-- robin\n"},{"id":"79656","messageId":"1213313997-1520-2-git-send-email-robin.rosenberg@dewire.com","threadId":"13923","inReplyTo":"1213313997-1520-1-git-send-email-robin.rosenberg@dewire.com","subject":"[EGIT RFC] Add utilities for figuring out repositories for selected resources","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-12T23:39:56Z","receivedAt":"2008-06-12T23:39:56Z","isPatch":false,"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---\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 @@ import java.util.HashSet;\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 abstract class RepositoryAction extends TeamAction {\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.5.5.1.178.g1f811\n"},{"id":"79655","messageId":"1213313997-1520-3-git-send-email-robin.rosenberg@dewire.com","threadId":"13923","inReplyTo":"1213313997-1520-2-git-send-email-robin.rosenberg@dewire.com","subject":"[EGIT RFC] Enable commit for any resource in a Git-shared project","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-12T23:39:57Z","receivedAt":"2008-06-12T23:39:57Z","isPatch":false,"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---\n .../egit/ui/internal/actions/CommitAction.java     |   31 +++++++++----------\n 1 files changed, 15 insertions(+), 16 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 db38c10..da32ea5 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 class CommitAction extends RepositoryAction {\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@@ -313,21 +313,20 @@ public class CommitAction extends RepositoryAction {\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 @@ public class CommitAction extends RepositoryAction {\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.5.5.1.178.g1f811\n"},{"id":"79786","messageId":"4852EFBF.6000406@gmail.com","threadId":"13923","inReplyTo":"1213313997-1520-1-git-send-email-robin.rosenberg@dewire.com","subject":"Re: [EGIT RFC] Commit behaviour","fromName":"Marek Zawirski","fromEmail":"marek.zawirski@gmail.com","sentAt":"2008-06-13T22:07:59Z","receivedAt":"2008-06-13T22:07:59Z","isPatch":false,"sender":{"key":"marek.zawirski@gmail.com","avatar":null},"body":"Robin Rosenberg wrote:\n> I got annoyed about having change my selection to a project to be able\n> to commit. 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\nThat's a nice idea! I also thought about that one day, as such feature \nalready exists in (e.g.) Subclipse that I was used to.\n\n> \n> Another twist would be to list all changed resources, but only enable\n> the selected ones, or only the ones in in the same projects as the selected\n> resources. Comments?\n\nI think that only selected && changed ones should be listed. When user \nselects explicitly some resources, he/she is probably interested only in \nthese ones. And he/she probably did it for easier selection than from \nlist of all changed resources, isn't it?\n\n> Code is not efficient either. This is question about the user interface.\n\nTheses patches don't work for me however :/ When I introduce some change \nto a resource/file, even add it to index and click commit (toolbar or \nmenu), commit action does nothing. It is - nothing happens. Can you \nreproduce this problem, or should I debug it on my instance? Or do I use \nit in some wrong way?\n\n\n> Then we could ask ourselved, should we do something similar for Checkout\n> and reset too? I think that is not as important as those operations are\n> much less frequent.\n> \n> -- robin\n\nWell, I think that checkout (maybe reset too) would be useful too - to \nrevert some file quickly.\n\n-- \nMarek Zawirski [zawir]\nmarek.zawirski@gmail.com\n"},{"id":"79789","messageId":"4852F79D.4080100@gmail.com","threadId":"13923","inReplyTo":"4852EFBF.6000406@gmail.com","subject":"Re: [EGIT RFC] Commit behaviour","fromName":"Marek Zawirski","fromEmail":"marek.zawirski@gmail.com","sentAt":"2008-06-13T22:41:33Z","receivedAt":"2008-06-13T22:41:33Z","isPatch":false,"sender":{"key":"marek.zawirski@gmail.com","avatar":null},"body":"> Robin Rosenberg wrote:\n>> Then we could ask ourselved, should we do something similar for Checkout\n>> and reset too? I think that is not as important as those operations are\n>> much less frequent.\n\nHey, by the way - do we already have some action for checkout? Did I \nmissed something?\n\n-- \nMarek Zawirski [zawir]\nmarek.zawirski@gmail.com\n"},{"id":"79830","messageId":"200806141040.02819.robin.rosenberg@dewire.com","threadId":"13923","inReplyTo":"4852F79D.4080100@gmail.com","subject":"Re: [EGIT RFC] Commit behaviour","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-14T08:40:02Z","receivedAt":"2008-06-14T08:40:02Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"lördagen den 14 juni 2008 00.41.33 skrev Marek Zawirski:\n> > Robin Rosenberg wrote:\n> >> Then we could ask ourselved, should we do something similar for Checkout\n> >> and reset too? I think that is not as important as those operations are\n> >> much less frequent.\n> \n> Hey, by the way - do we already have some action for checkout? Did I \n> missed something?\n\nYou missed it. \n\nIt's been there for a while (thanks to Roger Soares), but it is currently only available when a project is selected. It's in the team menu or, if you enable Git in Window/Customize Perspective, in the toolbar and menu bar. \n\n-- robin\n"},{"id":"79835","messageId":"200806141108.17854.robin.rosenberg@dewire.com","threadId":"13923","inReplyTo":"4852EFBF.6000406@gmail.com","subject":"Re: [EGIT RFC] Commit behaviour","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-14T09:08:17Z","receivedAt":"2008-06-14T09:08:17Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"lördagen den 14 juni 2008 00.07.59 skrev Marek Zawirski:\n> Robin Rosenberg wrote:\n> > I got annoyed about having change my selection to a project to be able\n> > to commit. 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> That's a nice idea! I also thought about that one day, as such feature \n> already exists in (e.g.) Subclipse that I was used to.\n> \n> > \n> > Another twist would be to list all changed resources, but only enable\n> > the selected ones, or only the ones in in the same projects as the selected\n> > resources. Comments?\n> \n> I think that only selected && changed ones should be listed. When user \n> selects explicitly some resources, he/she is probably interested only in \n> these ones. And he/she probably did it for easier selection than from \n> list of all changed resources, isn't it?\n\nSelection is often implicit, i.e. if you link editor and selection, which I do, the selection\nchange every time you switch editor. \n\n> > Code is not efficient either. This is question about the user interface.\n> \n> Theses patches don't work for me however :/ When I introduce some change \n> to a resource/file, even add it to index and click commit (toolbar or \n> menu), commit action does nothing. It is - nothing happens. Can you \n> reproduce this problem, or should I debug it on my instance? Or do I use \n> it in some wrong way?\nIt it's too hard to use properly it's wrong. Anyway I could reproduce it. Not sure\nwhy it works sometimes though. I found this in the workspace log. Please \ncheck if you see it too, so I know we're chasing the same bug.\n\njava.lang.ArrayIndexOutOfBoundsException: 0\n        at org.spearce.egit.ui.internal.actions.CommitAction.loadPreviousCommit(CommitAction.java:127)\n\n\n> > Then we could ask ourselved, should we do something similar for Checkout\n> > and reset too? I think that is not as important as those operations are\n> > much less frequent.\n> > \n> > -- robin\n> \n> Well, I think that checkout (maybe reset too) would be useful too - to \n> revert some file quickly.\n\nWe do not have a per-file checout/reset yet. What we have checks out all files in the repository.\n\n-- robin\n"},{"id":"79846","messageId":"200806141205.39516.robin.rosenberg.lists@dewire.com","threadId":"13923","inReplyTo":"200806141040.02819.robin.rosenberg@dewire.com","subject":"Re: [EGIT RFC] Commit behaviour","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-14T10:05:39Z","receivedAt":"2008-06-14T10:05:39Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"lördagen den 14 juni 2008 10.40.02 skrev Robin Rosenberg:\n> lördagen den 14 juni 2008 00.41.33 skrev Marek Zawirski:\n> > > Robin Rosenberg wrote:\n> > >> Then we could ask ourselved, should we do something similar for Checkout\n> > >> and reset too? I think that is not as important as those operations are\n> > >> much less frequent.\n> > \n> > Hey, by the way - do we already have some action for checkout? Did I \n> > missed something?\n> \n> You missed it. \n> \n> It's been there for a while (thanks to Roger Soares), but it is currently only available when a project is selected. It's in the team menu or, if you enable Git in Window/Customize Perspective, in the toolbar and menu bar. \n\nSorry about that. It's the Branch action. I think the original thought was to\nmake the dialog do more, like create branches. We should rename it regardless.\n\n-- robin\n"},{"id":"79849","messageId":"200806141223.11134.robin.rosenberg@dewire.com","threadId":"13923","inReplyTo":"4852EFBF.6000406@gmail.com","subject":"Re: [EGIT RFC] Commit behaviour","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-14T10:23:10Z","receivedAt":"2008-06-14T10:23:10Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"lördagen den 14 juni 2008 00.07.59 skrev Marek Zawirski:\n> Theses patches don't work for me however :/ When I introduce some change \n> to a resource/file, even add it to index and click commit (toolbar or \n> menu), commit action does nothing. It is - nothing happens. Can you \n> reproduce this problem, or should I debug it on my instance? Or do I use \n> it in some wrong way?\n\nFound it. Obviously this won't work for commits to multiple repositories which is supposed\nto work really, but I think that was broken earlier by yours truly. This fix should make it\npossible to test the idea though this thread is about, and see if we have more selection\nproblems. \n\n-- robin\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 da32ea5..922649b 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@@ -124,7 +124,7 @@ public class CommitAction extends RepositoryAction {\n        }\n\n        private void loadPreviousCommit() {\n-               IProject project = getSelectedProjects()[0];\n+               IProject project = getProjectsForSelectedResources()[0];\n\n                Repository repo = RepositoryMapping.getMapping(project).getRepository();\n                try {\n"},{"id":"79899","messageId":"485477D5.3090502@gmail.com","threadId":"13923","inReplyTo":"200806141223.11134.robin.rosenberg@dewire.com","subject":"Re: [EGIT RFC] Commit behaviour","fromName":"Marek Zawirski","fromEmail":"marek.zawirski@gmail.com","sentAt":"2008-06-15T02:00:53Z","receivedAt":"2008-06-15T02:00:53Z","isPatch":false,"sender":{"key":"marek.zawirski@gmail.com","avatar":null},"body":"Robin Rosenberg wrote:\n> Found it. Obviously this won't work for commits to multiple repositories which is supposed\n> to work really, but I think that was broken earlier by yours truly. This fix should make it\n> possible to test the idea though this thread is about, and see if we have more selection\n> problems. \n> \n> -- robin\n> \n> diff --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\n> index da32ea5..922649b 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> @@ -124,7 +124,7 @@ public class CommitAction extends RepositoryAction {\n>         }\n> \n>         private void loadPreviousCommit() {\n> -               IProject project = getSelectedProjects()[0];\n> +               IProject project = getProjectsForSelectedResources()[0];\n> \n>                 Repository repo = RepositoryMapping.getMapping(project).getRepository();\n>                 try {\n> \n\nYeah, it works for me now, with this patch applied.\n\nAnd yes, without this patch, I found mentioned exception in log:\njava.lang.ArrayIndexOutOfBoundsException: 0\n  at \norg.spearce.egit.ui.internal.actions.CommitAction.loadPreviousCommit(CommitAction.java:127)\n\n-- \nMarek Zawirski [zawir]\nmarek.zawirski@gmail.com\n"},{"id":"79997","messageId":"20080616021158.GQ11793@spearce.org","threadId":"13923","inReplyTo":"1213313997-1520-1-git-send-email-robin.rosenberg@dewire.com","subject":"Re: [EGIT RFC] Commit behaviour","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-06-16T02:11:58Z","receivedAt":"2008-06-16T02:11:58Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Robin Rosenberg <robin.rosenberg@dewire.com> wrote:\n> I got annoyed about having change my selection to a project to be able\n> to commit. 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> Another twist would be to list all changed resources, but only enable\n> the selected ones, or only the ones in in the same projects as the selected\n> resources. Comments?\n\nI think this is a good idea.  You really do want to make commits\nthat cover the entire repository, rather than a subsection of it.\nI think that covering the whole repository is much more common.\n\n> Then we could ask ourselved, should we do something similar for Checkout\n> and reset too? I think that is not as important as those operations are\n> much less frequent.\n\nYes, we do want to.  If you are doing a reset you probably need\nto whack everything that is dirty and restore the state, likewise\nif you are doing a checkout you are likely switching branches and\nwould expect the entire repository to switch at once.\n\n-- \nShawn.\n"}]}