diff --git a/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/AirContentRevision.java b/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/AirContentRevision.java index e25f3da85c8b..9442cb2d0200 100644 --- a/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/AirContentRevision.java +++ b/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/AirContentRevision.java @@ -25,7 +25,7 @@ import java.nio.charset.Charset; public interface AirContentRevision { boolean isBinary(); - @Nullable + @NotNull String getContentAsString() throws VcsException; byte @Nullable [] getContentAsBytes() throws VcsException; diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/IdeaTextPatchBuilder.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/IdeaTextPatchBuilder.java index 25f942a716f7..5186feb0b34e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/IdeaTextPatchBuilder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/IdeaTextPatchBuilder.java @@ -6,9 +6,11 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.ex.PartialCommitHelper; +import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vcs.impl.PartialChangesUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.BeforeAfter; @@ -171,7 +173,7 @@ public final class IdeaTextPatchBuilder { } @Override - public String getContentAsString() { + public @NotNull String getContentAsString() { throw new IllegalStateException(); } @@ -213,8 +215,15 @@ public final class IdeaTextPatchBuilder { } @Override - public String getContentAsString() throws VcsException { - return myRevision.getContent(); + public @NotNull String getContentAsString() throws VcsException { + String content = myRevision.getContent(); + if (content == null) { + VcsRevisionNumber revisionNumber = myRevision.getRevisionNumber(); + String revisionText = revisionNumber != VcsRevisionNumber.NULL ? revisionNumber.asString() : myRevision.toString(); + throw new VcsException(VcsBundle.message("patch.failed.to.fetch.old.content.for.file.name.in.revision", + myFilePath.getPath(), revisionText)); + } + return content; } @Override @@ -263,7 +272,7 @@ public final class IdeaTextPatchBuilder { } @Override - public String getContentAsString() { + public @NotNull String getContentAsString() { return myContent; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java index b68e05889244..67c0830d03ac 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java @@ -13,7 +13,6 @@ import com.intellij.openapi.util.text.LineTokenizer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.FileStatus; -import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.VcsException; import com.intellij.util.BeforeAfter; import com.intellij.util.containers.ContainerUtil; @@ -102,8 +101,8 @@ public final class TextPatchBuilder { @Nullable private TextFilePatch buildModifiedFile(@NotNull AirContentRevision beforeRevision, @NotNull AirContentRevision afterRevision) throws VcsException { - String beforeContent = getContent(beforeRevision); - String afterContent = getContent(afterRevision); + String beforeContent = beforeRevision.getContentAsString(); + String afterContent = afterRevision.getContentAsString(); TextFilePatch patch = buildPatchHeading(beforeRevision, afterRevision); @@ -291,7 +290,7 @@ public final class TextPatchBuilder { private TextFilePatch buildAddedFile(@NotNull AirContentRevision afterRevision) throws VcsException { TextFilePatch result = buildPatchHeading(afterRevision, afterRevision); result.setFileStatus(FileStatus.ADDED); - String content = getContent(afterRevision); + String content = afterRevision.getContentAsString(); if (!content.isEmpty()) { result.addHunk(createWholeFileHunk(content, true, false)); } @@ -302,7 +301,7 @@ public final class TextPatchBuilder { private TextFilePatch buildDeletedFile(@NotNull AirContentRevision beforeRevision) throws VcsException { TextFilePatch result = buildPatchHeading(beforeRevision, beforeRevision); result.setFileStatus(FileStatus.DELETED); - String content = getContent(beforeRevision); + String content = beforeRevision.getContentAsString(); if (!content.isEmpty()) { result.addHunk(createWholeFileHunk(content, false, false)); } @@ -388,17 +387,6 @@ public final class TextPatchBuilder { return null; } - @NotNull - private static String getContent(@NotNull AirContentRevision revision) throws VcsException { - String beforeContent = revision.getContentAsString(); - if (beforeContent == null) { - throw new VcsException( - VcsBundle.message("patch.failed.to.fetch.old.content.for.file.name.in.revision", revision.getPath().getPath(), - revision.getRevisionNumber())); - } - return beforeContent; - } - @NotNull private static List tokenize(@NotNull String text) { return LineTokenizer.tokenizeIntoList(text, false, true);