Commit 80ca5ed3 authored by Florent Angebault's avatar Florent Angebault

OTRS#2016093010000012 : svn diff before svn summarize + ignore ancestry.

parent f80aa1f0
......@@ -11,10 +11,13 @@
package org.eclipse.team.svn.ui.operation;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Set;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareEditorInput;
......@@ -216,7 +219,10 @@ public class CompareResourcesInternalOperation extends AbstractActionOperation {
SVNEntryRevisionReference refPrev = new SVNEntryRevisionReference(FileUtility.getWorkingCopyPath(CompareResourcesInternalOperation.this.local.getResource()), null, SVNRevision.WORKING);
final SVNEntryRevisionReference refNext = SVNUtility.getEntryRevisionReference(CompareResourcesInternalOperation.this.remote);
proxy.diffStatusTwo(refPrev, refNext, SVNDepth.INFINITY, ISVNConnector.Options.NONE, null, new ISVNDiffStatusCallback() {
// does not work with BASE working copy revision (not implemented yet exception)
final FakeOutputStream diffPathCollector = new FakeOutputStream();
proxy.diffTwo(refPrev, refNext, rootPath.toFile().getAbsolutePath(), diffPathCollector, SVNDepth.INFINITY, ISVNConnector.Options.IGNORE_ANCESTRY, null, ISVNConnector.DiffOptions.IGNORE_WHITESPACE, new SVNProgressMonitor(CompareResourcesInternalOperation.this, monitor, null, false));
proxy.diffStatusTwo(refPrev, refNext, SVNDepth.INFINITY, ISVNConnector.Options.IGNORE_ANCESTRY, null, new ISVNDiffStatusCallback() {
public void next(SVNDiffStatus status) {
IPath tPath = new Path(status.pathPrev);
tPath = tPath.removeFirstSegments(rootPath.segmentCount());
......@@ -224,19 +230,71 @@ public class CompareResourcesInternalOperation extends AbstractActionOperation {
if (resource == null) {
resource = status.nodeKind == SVNEntry.Kind.FILE ? compareRoot.getFile(tPath) : compareRoot.getFolder(tPath);
}
if (IStateFilter.SF_ANY_CHANGE.accept(SVNRemoteStorage.instance().asLocalResource(resource))) {
localChanges.add(status);
}
else {
String pathPrev = CompareResourcesInternalOperation.this.ancestor.getUrl() + status.pathNext.substring(refNext.path.length());
remoteChanges.add(new SVNDiffStatus(pathPrev, status.pathNext, status.nodeKind, status.textStatus, status.propStatus));
ILocalResource local = SVNRemoteStorage.instance().asLocalResource(resource);
if (!IStateFilter.SF_ANY_CHANGE.accept(local) || IStateFilter.SF_NOTEXISTS.accept(local)) {
// it seems the status is calculated relatively to the working copy, so deletion and addition changes should actually be reversed
// TODO could there be a case when relative paths are reported? If so - looks like a bug to me...
String pathPrev = status.pathNext.startsWith(refNext.path) ? status.pathNext.substring(refNext.path.length()) : status.pathNext;
if (!diffPathCollector.contains(pathPrev)) {
System.out.println("ignoring path: " + pathPrev);
} else {
pathPrev = CompareResourcesInternalOperation.this.ancestor.getUrl() + pathPrev;
remoteChanges.add(new SVNDiffStatus(pathPrev, status.pathNext, status.nodeKind, status.textStatus, status.propStatus));
}
}
}
}, new SVNProgressMonitor(CompareResourcesInternalOperation.this, monitor, null, false));
}
}, monitor, 100, 50);
}
/**
* Workaround.
*
* This {@link OutputStream} parses the output of "svn diff" and only catches paths from
* the lines beginning with "Index: ".
*
* @author fangebault
*/
private static class FakeOutputStream extends OutputStream {
boolean lineStart = true;
boolean indexLine = false;
Set<String> paths = new LinkedHashSet<String>();
StringBuilder w = new StringBuilder();
@Override
public void write(int b) throws IOException {
char c = (char) b;
System.out.print(c);
if (c == 'I' && this.lineStart) {
this.indexLine = true;
this.w.append(c);
} else if (c == '\n' || c == '\r') {
if (this.indexLine) {
this.paths.add("/" + this.w.toString().substring("Index: ".length()));
this.w.replace(0, this.w.length(), "");
}
this.lineStart = true;
this.indexLine = false;
} else {
this.lineStart = false;
if (this.indexLine) {
this.w.append(c);
}
}
}
private Set<String> getPaths() {
return this.paths;
}
public boolean contains(String path) {
return this.getPaths().contains(path);
}
}
protected boolean compareResultOK(CompareEditorInput input) {
final Shell shell = UIMonitorUtility.getShell();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment