apply patch debug logging

This commit is contained in:
irengrig
2011-11-17 18:06:39 +04:00
parent dd80e5dffe
commit d368e5980a
2 changed files with 38 additions and 0 deletions
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.diff.impl.patch.apply;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.impl.patch.ApplyPatchContext;
import com.intellij.openapi.diff.impl.patch.FilePatch;
import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl;
@@ -30,6 +31,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
public abstract class ApplyFilePatchBase<T extends FilePatch> implements ApplyFilePatch {
private final static Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.patch.apply.ApplyFilePatchBase");
protected final T myPatch;
public ApplyFilePatchBase(T patch) {
@@ -52,6 +54,9 @@ public abstract class ApplyFilePatchBase<T extends FilePatch> implements ApplyFi
final Project project,
FilePath pathBeforeRename,
Getter<CharSequence> baseContents, CommitContext commitContext) throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("apply patch called for : " + fileToPatch.getPath());
}
context.addAffectedFile(getTarget(fileToPatch));
if (myPatch.isNewFile()) {
applyCreate(fileToPatch, commitContext);
@@ -15,12 +15,14 @@
*/
package com.intellij.openapi.diff.impl.patch.apply;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.impl.patch.ApplyPatchStatus;
import com.intellij.openapi.diff.impl.patch.PatchHunk;
import com.intellij.openapi.diff.impl.patch.PatchLine;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.LineTokenizer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.BeforeAfter;
import com.intellij.util.Consumer;
import com.intellij.util.containers.CompositeIterator;
@@ -35,6 +37,7 @@ import java.util.*;
* Time: 3:59 PM
*/
public class GenericPatchApplier {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier");
private final static int ourMaxWalk = 1000;
private final TreeMap<TextRange, MyAppliedData> myTransformations;
@@ -45,8 +48,15 @@ public class GenericPatchApplier {
private final ArrayList<SplitHunk> myNotBound;
private final ArrayList<SplitHunk> myNotExact;
private boolean mySuppressNewLineInEnd;
private void debug(final String s) {
if (LOG.isDebugEnabled()) {
LOG.debug(s);
}
}
public GenericPatchApplier(final CharSequence text, List<PatchHunk> hunks) {
debug("GenericPatchApplier created, hunks: " + hunks.size());
myLines = new ArrayList<String>();
Collections.addAll(myLines, LineTokenizer.tokenize(text, false));
myHunks = hunks;
@@ -80,7 +90,27 @@ public class GenericPatchApplier {
}
}
private void printTransformations(final String comment) {
if (LOG.isDebugEnabled()) {
LOG.debug(comment + " GenericPatchApplier.printTransformations ---->");
int cnt = 0;
for (Map.Entry<TextRange, MyAppliedData> entry : myTransformations.entrySet()) {
final TextRange key = entry.getKey();
final MyAppliedData value = entry.getValue();
LOG.info(String.valueOf(cnt) +
" lines " +
key.getStartOffset() +
":" +
key.getEndOffset() +
" will replace into: " +
StringUtil.join(value.getList(), "\n"));
}
LOG.debug("<------ GenericPatchApplier.printTransformations");
}
}
public boolean execute() {
debug("GenericPatchApplier execute started");
if (! myHunks.isEmpty()) {
mySuppressNewLineInEnd = myHunks.get(myHunks.size() - 1).isNoNewLineAtEnd();
}
@@ -94,6 +124,7 @@ public class GenericPatchApplier {
iterator.remove();
}
}
printTransformations("after exact match");
/*for (SplitHunk hunk : myNotExact) {
complementInsertAndDelete(hunk);
}*/
@@ -106,6 +137,7 @@ public class GenericPatchApplier {
iterator.remove();
}
}
printTransformations("after exact but without context");
for (SplitHunk hunk : myNotExact) {
complementInsertAndDelete(hunk);
}
@@ -116,6 +148,7 @@ public class GenericPatchApplier {
iterator.remove();
}
}
printTransformations("after variable place match");
return myNotExact.isEmpty();
}