use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class DiffActionExecutor method createRemote.
@Nullable
protected DiffContent createRemote(final VcsRevisionNumber revisionNumber) throws IOException, VcsException {
final ContentRevision fileRevision = myDiffProvider.createFileContent(revisionNumber, mySelectedFile);
if (fileRevision == null)
return null;
DiffContentFactoryEx contentFactory = DiffContentFactoryEx.getInstanceEx();
DiffContent diffContent;
if (fileRevision instanceof BinaryContentRevision) {
FilePath filePath = fileRevision.getFile();
final byte[] content = ((BinaryContentRevision) fileRevision).getBinaryContent();
if (content == null)
return null;
diffContent = contentFactory.createBinary(myProject, content, filePath.getFileType(), filePath.getName());
} else if (fileRevision instanceof ByteBackedContentRevision) {
byte[] content = ((ByteBackedContentRevision) fileRevision).getContentAsBytes();
if (content == null)
throw new VcsException("Failed to load content");
diffContent = contentFactory.createFromBytes(myProject, content, fileRevision.getFile());
} else {
String content = fileRevision.getContent();
if (content == null)
throw new VcsException("Failed to load content");
diffContent = contentFactory.create(myProject, content, fileRevision.getFile());
}
diffContent.putUserData(DiffUserDataKeysEx.REVISION_INFO, Pair.create(fileRevision.getFile(), fileRevision.getRevisionNumber()));
return diffContent;
}
use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class TabbedShowHistoryForRevisionAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
Project project = event.getRequiredData(CommonDataKeys.PROJECT);
AbstractVcs vcs = assertNotNull(getVcs(project, event.getData(VcsDataKeys.VCS)));
VcsHistoryProviderEx vcsHistoryProvider = assertNotNull((VcsHistoryProviderEx) vcs.getVcsHistoryProvider());
Change change = event.getRequiredData(VcsDataKeys.SELECTED_CHANGES)[0];
ContentRevision revision = assertNotNull(getContentRevision(change));
AbstractVcsHelperImpl helper = assertNotNull(getVcsHelper(project));
helper.showFileHistory(vcsHistoryProvider, revision.getFile(), vcs, revision.getRevisionNumber());
}
use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class CommitCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile file = parameters.getOriginalFile();
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if (document == null)
return;
CommitMessage commitMessage = document.getUserData(CommitMessage.DATA_KEY);
if (commitMessage == null)
return;
result.stopHere();
if (parameters.getInvocationCount() <= 0)
return;
List<ChangeList> lists = commitMessage.getChangeLists();
if (lists.isEmpty())
return;
String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters);
CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix));
for (ChangeList list : lists) {
for (Change change : list.getChanges()) {
ContentRevision revision = change.getAfterRevision() == null ? change.getBeforeRevision() : change.getAfterRevision();
if (revision != null) {
FilePath filePath = revision.getFile();
LookupElementBuilder element = LookupElementBuilder.create(filePath.getName()).withIcon(filePath.getFileType().getIcon());
insensitive.addElement(element);
}
}
}
}
use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class LocalChangesUnderRootsTest method createChangeForPath.
private Change createChangeForPath(String path) {
VirtualFile file = VfsTestUtil.createFile(myBaseDir, path);
FilePath filePath = VcsUtil.getFilePath(file);
ContentRevision beforeRevision = new MockContentRevision(filePath, new VcsRevisionNumber.Int(1));
ContentRevision afterRevision = new MockContentRevision(filePath, new VcsRevisionNumber.Int(2));
return new Change(beforeRevision, afterRevision);
}
use of com.intellij.openapi.vcs.changes.ContentRevision in project intellij-community by JetBrains.
the class BlobIndexUtil method getBeforeAfterSha1.
@NotNull
public static Couple<String> getBeforeAfterSha1(@NotNull Change change) throws VcsException {
ContentRevision beforeRevision = change.getBeforeRevision();
ContentRevision afterRevision = change.getAfterRevision();
//noinspection ConstantConditions
Charset detectCharset = ObjectUtils.chooseNotNull(afterRevision, beforeRevision).getFile().getCharset();
String before = beforeRevision == null ? NOT_COMMITTED_HASH : getSha1(getContentBytes(beforeRevision, detectCharset));
String after = afterRevision == null ? NOT_COMMITTED_HASH : getSha1(getContentBytes(afterRevision, detectCharset));
return new Couple<>(before, after);
}
Aggregations