import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.ContentRevision;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.command.HgCatCommand;
+import java.io.UnsupportedEncodingException;
+
public class HgContentRevision implements ContentRevision {
private final Project project;
this.revisionNumber = revisionNumber;
}
+ @Nullable
public String getContent() throws VcsException {
if (StringUtils.isBlank(content)) {
content = new HgCatCommand(project).execute(hgFile, revisionNumber, getFile().getCharset());
return content;
}
+ @Nullable
+ public byte[] getContentAsBytes() throws VcsException {
+ String content = getContent();
+ if (content == null) {
+ return null;
+ }
+ try {
+ VirtualFile vf = VcsUtil.getVirtualFile(hgFile.getFile());
+ if (vf == null) {
+ return null;
+ }
+ return content.getBytes(vf.getCharset().name());
+ } catch (UnsupportedEncodingException e) {
+ throw new VcsException("Couldn't retrieve file content due to a UnsupportedEncodingException", e);
+ }
+ }
+
@NotNull
public FilePath getFile() {
if (filePath == null) {