aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2012-02-20 05:50:34 (EST)
committerTomasz Zarna2012-02-20 05:50:34 (EST)
commit7be7dd9034c0d5b4e68c135c7517ef6d2260b05e (patch)
tree880ece31bded45f060fc5330023d5c5793e699b0
parent7d7806cf9f8cfd5c3d51b3981e795bc9c532c1b7 (diff)
downloadegit-7be7dd9034c0d5b4e68c135c7517ef6d2260b05e.zip
egit-7be7dd9034c0d5b4e68c135c7517ef6d2260b05e.tar.gz
egit-7be7dd9034c0d5b4e68c135c7517ef6d2260b05e.tar.bz2
Team > Create Patch... doesn't observe selectionrefs/changes/64/5064/2
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/CreatePatchOperation.java17
-rw-r--r--org.eclipse.egit.ui/plugin.xml1
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CreatePatchActionHandler.java14
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java38
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java23
5 files changed, 79 insertions, 14 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CreatePatchOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CreatePatchOperation.java
index de1b278..09ffb84 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CreatePatchOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CreatePatchOperation.java
@@ -9,6 +9,7 @@
* Contributors:
* Stefan Lay (SAP AG) - initial implementation
* Benjamin Muskalla (Tasktop Technologies) - extract into operation
+ * Tomasz Zarna (IBM Corporation) - bug 370332
*******************************************************************************/
package org.eclipse.egit.core.op;
@@ -35,6 +36,7 @@ import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.FileTreeIterator;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
/**
* Creates a patch for a specific commit
@@ -111,12 +113,13 @@ public class CreatePatchOperation implements IEGitOperation {
private DiffHeaderFormat headerFormat = DiffHeaderFormat.EMAIL;
// the encoding for the currently processed file
- private String currentEncoding = null;
+ private String currentEncoding = null;
private String patchContent;
private int contextLines = DEFAULT_CONTEXT_LINES;
+ private TreeFilter pathFilter = null;
/**
* Creates the new operation.
*
@@ -164,6 +167,7 @@ public class CreatePatchOperation implements IEGitOperation {
writeGitPatchHeader(sb);
diffFmt.setRepository(repository);
+ diffFmt.setPathFilter(pathFilter);
try {
if (commit != null) {
@@ -185,11 +189,10 @@ public class CreatePatchOperation implements IEGitOperation {
currentEncoding = CompareCoreUtils.getResourceEncoding(repository, path);
diffFmt.format(ent);
}
- } else {
+ } else
diffFmt.format(
new DirCacheIterator(repository.readDirCache()),
new FileTreeIterator(repository));
- }
} catch (IOException e) {
Activator.logError(CoreText.CreatePatchOperation_patchFileCouldNotBeWritten, e);
}
@@ -315,4 +318,12 @@ public class CreatePatchOperation implements IEGitOperation {
return null;
}
+ /**
+ * Set the filter to produce patch for specified paths only.
+ *
+ * @param pathFilter the filter
+ */
+ public void setPathFilter(TreeFilter pathFilter) {
+ this.pathFilter = pathFilter;
+ }
}
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index c102596..05d269b 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -216,7 +216,6 @@
</action>
<action
class="org.eclipse.egit.ui.internal.actions.CreatePatchAction"
- enablesFor="1"
id="org.eclipse.egit.ui.internal.actions.CreatePatchAction"
label="%CreatePatchAction.label"
menubarPath="team.main/group6"
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CreatePatchActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CreatePatchActionHandler.java
index dcee905..bdaa4eb 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CreatePatchActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CreatePatchActionHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2011, Tomasz Zarna <Tomasz.Zarna@pl.ibm.com>
+ * Copyright (C) 2011-2012, Tomasz Zarna <Tomasz.Zarna@pl.ibm.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,9 +8,13 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.actions;
+import java.util.Arrays;
+
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IResource;
import org.eclipse.egit.ui.internal.patch.PatchOperationUI;
+import org.eclipse.jgit.lib.Repository;
/**
* The "Create Patch" action.
@@ -18,7 +22,13 @@ import org.eclipse.egit.ui.internal.patch.PatchOperationUI;
public class CreatePatchActionHandler extends RepositoryActionHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
- PatchOperationUI.createPatch(getPart(event), getRepository()).start();
+ final Repository repository = getRepository(true, event);
+ // assert all resources map to the same repository
+ if (repository == null)
+ return null;
+ IResource[] resources = getSelectedResources();
+ PatchOperationUI.createPatch(getPart(event), getRepository(),
+ Arrays.asList(resources)).start();
return null;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java
index 10edd0b..7b47f51 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java
@@ -10,6 +10,7 @@
* Stefan Lay (SAP AG) - initial implementation
* Daniel Megert <daniel_megert@ch.ibm.com> - Create Patch... dialog should not set file location - http://bugs.eclipse.org/361405
* Tomasz Zarna <Tomasz.Zarna@pl.ibm.com> - Allow to save patches in Workspace
+ * Tomasz Zarna <Tomasz.Zarna@pl.ibm.com> - Team > Create Patch... doesn't observe selection, bug 370332
*******************************************************************************/
package org.eclipse.egit.ui.internal.history;
@@ -19,11 +20,16 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.egit.core.op.CreatePatchOperation;
import org.eclipse.egit.core.op.CreatePatchOperation.DiffHeaderFormat;
+import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIIcons;
import org.eclipse.egit.ui.UIText;
@@ -46,6 +52,9 @@ import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
@@ -68,6 +77,8 @@ public class GitCreatePatchWizard extends Wizard {
private Repository db;
+ private Collection<? extends IResource> resources;
+
private LocationPage locationPage;
private OptionsPage optionsPage;
@@ -82,11 +93,12 @@ public class GitCreatePatchWizard extends Wizard {
* @param shell
* @param commit
* @param db
+ * @param resources
*/
public static void run(Shell shell, final RevCommit commit,
- Repository db) {
+ Repository db, Collection<? extends IResource> resources) {
final String title = UIText.GitCreatePatchWizard_CreatePatchTitle;
- final GitCreatePatchWizard wizard = new GitCreatePatchWizard(commit, db);
+ final GitCreatePatchWizard wizard = new GitCreatePatchWizard(commit, db, resources);
wizard.setWindowTitle(title);
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.setMinimumPageSize(INITIAL_WIDTH, INITIAL_HEIGHT);
@@ -100,10 +112,12 @@ public class GitCreatePatchWizard extends Wizard {
*
* @param commit
* @param db
+ * @param resources
*/
- public GitCreatePatchWizard(RevCommit commit, Repository db) {
+ public GitCreatePatchWizard(RevCommit commit, Repository db, Collection<? extends IResource> resources) {
this.commit = commit;
this.db = db;
+ this.resources = resources;
setDialogSettings(getOrCreateSection(Activator.getDefault().getDialogSettings(), "GitCreatePatchWizard")); //$NON-NLS-1$
}
@@ -142,6 +156,7 @@ public class GitCreatePatchWizard extends Wizard {
commit);
operation.setHeaderFormat(optionsPage.getSelectedHeaderFormat());
operation.setContextLines(Integer.parseInt(optionsPage.contextLines.getText()));
+ operation.setPathFilter(createPathFilter(resources));
final File file = !locationPage.fsRadio.getSelection() ? locationPage
.getFile() : null;
@@ -193,6 +208,23 @@ public class GitCreatePatchWizard extends Wizard {
});
}
+ private TreeFilter createPathFilter(final Collection<? extends IResource> rs) {
+ if (rs == null || rs.isEmpty())
+ return null;
+ final List<PathFilter> filters = new ArrayList<PathFilter>();
+ for (IResource r : rs) {
+ RepositoryMapping rm = RepositoryMapping.getMapping(r);
+ String repoRelativePath = rm.getRepoRelativePath(r);
+ if (repoRelativePath != null)
+ filters.add(PathFilter.create(repoRelativePath));
+ }
+ if (filters.size() == 0)
+ return null;
+ if (filters.size() == 1)
+ return filters.get(0);
+ return PathFilterGroup.create(filters);
+ }
+
private void writeToFile(final File file, String content)
throws IOException {
Writer output = new BufferedWriter(new FileWriter(file));
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java
index cda897b..8f9c999 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2011, Tomasz Zarna <Tomasz.Zarna@pl.ibm.com>
+ * Copyright (C) 2011-2012, Tomasz Zarna <Tomasz.Zarna@pl.ibm.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,9 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.patch;
+import java.util.Collection;
+
+import org.eclipse.core.resources.IResource;
import org.eclipse.egit.core.op.CreatePatchOperation;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.history.GitCreatePatchWizard;
@@ -30,6 +33,8 @@ public class PatchOperationUI {
private RevCommit commit;
+ private Collection<? extends IResource> resources;
+
private PatchOperationUI(IWorkbenchPart part, Repository repo) {
this.part = part;
this.repository = repo;
@@ -41,6 +46,12 @@ public class PatchOperationUI {
this.commit = commit;
}
+ private PatchOperationUI(IWorkbenchPart part, Repository repo,
+ Collection<? extends IResource> resources) {
+ this(part, repo);
+ this.resources = resources;
+ }
+
/**
* Create an operation for creating a patch for a specific commit.
*
@@ -65,11 +76,13 @@ public class PatchOperationUI {
* the part
* @param repo
* the repository
+ * @param resources
+ * collection of {@link IResource}s
* @return the {@link PatchOperationUI}
*/
public static PatchOperationUI createPatch(IWorkbenchPart part,
- Repository repo) {
- return new PatchOperationUI(null, repo);
+ Repository repo, Collection<? extends IResource> resources) {
+ return new PatchOperationUI(null, repo, resources);
}
/**
@@ -77,7 +90,7 @@ public class PatchOperationUI {
*/
public void start() {
if (commit != null) {
- GitCreatePatchWizard.run(getShell(), commit, repository);
+ GitCreatePatchWizard.run(getShell(), commit, repository, null);
return;
} else
@@ -87,7 +100,7 @@ public class PatchOperationUI {
UIText.GitCreatePatchAction_workingTreeClean);
return;
}
- GitCreatePatchWizard.run(getShell(), null, repository);
+ GitCreatePatchWizard.run(getShell(), null, repository, resources);
}
private boolean isWorkingTreeClean() {