EA-1095655 vcs: update an error message on file patch creation failure

GitOrigin-RevId: 9ef9b6f7a33eb3be230e9d458a0b714a869004d0
This commit is contained in:
Aleksey Pivovarov
2024-03-28 15:46:17 +00:00
committed by intellij-monorepo-bot
parent b11445cf23
commit e7eadd0171
3 changed files with 18 additions and 21 deletions
@@ -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;
@@ -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;
}
@@ -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<String> tokenize(@NotNull String text) {
return LineTokenizer.tokenizeIntoList(text, false, true);