use of git4idea.GitFileRevision in project intellij-community by JetBrains.
the class GitAnnotationProvider method annotate.
@NotNull
@Override
public FileAnnotation annotate(@NotNull final FilePath path, @NotNull final VcsRevisionNumber revision) throws VcsException {
GitFileRevision fileRevision = new GitFileRevision(myProject, path, (GitRevisionNumber) revision);
VcsVirtualFile file = new VcsVirtualFile(path.getPath(), fileRevision, VcsFileSystem.getInstance());
return annotate(path, revision, file);
}
use of git4idea.GitFileRevision in project intellij-community by JetBrains.
the class GitFileAnnotation method getPreviousFileRevisionProvider.
@Nullable
@Override
public PreviousFileRevisionProvider getPreviousFileRevisionProvider() {
return new PreviousFileRevisionProvider() {
@Nullable
@Override
public VcsFileRevision getPreviousRevision(int lineNumber) {
LineInfo lineInfo = getLineInfo(lineNumber);
if (lineInfo == null)
return null;
VcsFileRevision previousFileRevision = lineInfo.getPreviousFileRevision();
if (previousFileRevision != null)
return previousFileRevision;
GitRevisionNumber revisionNumber = lineInfo.getRevisionNumber();
if (myRevisions != null && myRevisionMap != null && myRevisionMap.contains(revisionNumber)) {
int index = myRevisionMap.get(revisionNumber);
if (index + 1 < myRevisions.size()) {
return myRevisions.get(index + 1);
}
}
return null;
}
@Nullable
@Override
public VcsFileRevision getLastRevision() {
if (myBaseRevision instanceof GitRevisionNumber) {
return new GitFileRevision(myProject, VcsUtil.getFilePath(myFile), (GitRevisionNumber) myBaseRevision);
} else {
return ContainerUtil.getFirstItem(getRevisions());
}
}
};
}
use of git4idea.GitFileRevision in project intellij-community by JetBrains.
the class GitDiffProvider method createFileContent.
/**
* {@inheritDoc}
*/
@Nullable
public ContentRevision createFileContent(VcsRevisionNumber revisionNumber, VirtualFile selectedFile) {
if (selectedFile.isDirectory()) {
return null;
}
final String path = selectedFile.getPath();
if (GitUtil.gitRootOrNull(selectedFile) == null) {
return null;
}
// faster, if there were no renames
FilePath filePath = VcsUtil.getFilePath(path);
try {
final CommittedChangesProvider committedChangesProvider = GitVcs.getInstance(myProject).getCommittedChangesProvider();
final Pair<CommittedChangeList, FilePath> pair = committedChangesProvider.getOneList(selectedFile, revisionNumber);
if (pair != null) {
return GitContentRevision.createRevision(pair.getSecond(), revisionNumber, myProject, selectedFile.getCharset());
}
} catch (VcsException e) {
GitVcs.getInstance(myProject).showErrors(Collections.singletonList(e), GitBundle.message("diff.find.error", path));
}
try {
for (VcsFileRevision f : GitHistoryUtils.history(myProject, filePath)) {
GitFileRevision gitRevision = (GitFileRevision) f;
if (f.getRevisionNumber().equals(revisionNumber)) {
return GitContentRevision.createRevision(gitRevision.getPath(), revisionNumber, myProject, selectedFile.getCharset());
}
}
GitContentRevision candidate = (GitContentRevision) GitContentRevision.createRevision(filePath, revisionNumber, myProject, selectedFile.getCharset());
try {
candidate.getContent();
return candidate;
} catch (VcsException e) {
// file does not exists
}
} catch (VcsException e) {
GitVcs.getInstance(myProject).showErrors(Collections.singletonList(e), GitBundle.message("diff.find.error", path));
}
return null;
}
use of git4idea.GitFileRevision in project intellij-community by JetBrains.
the class GitDiffFromHistoryHandler method showDiffForOne.
@Override
public void showDiffForOne(@NotNull AnActionEvent e, @NotNull Project project, @NotNull FilePath filePath, @NotNull VcsFileRevision previousRevision, @NotNull VcsFileRevision revision) {
GitFileRevision rev = (GitFileRevision) revision;
Collection<String> parents = rev.getParents();
if (parents.size() < 2) {
super.showDiffForOne(e, project, filePath, previousRevision, revision);
} else {
// merge
showDiffForMergeCommit(e, filePath, rev, parents);
}
}
use of git4idea.GitFileRevision in project intellij-community by JetBrains.
the class GitMergeProvider method loadRevisions.
@Override
@NotNull
public MergeData loadRevisions(@NotNull final VirtualFile file) throws VcsException {
final MergeData mergeData = new MergeData();
final VirtualFile root = GitUtil.getGitRoot(file);
final FilePath path = VcsUtil.getFilePath(file.getPath());
VcsRunnable runnable = new VcsRunnable() {
@Override
@SuppressWarnings({ "ConstantConditions" })
public void run() throws VcsException {
GitFileRevision original = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + ORIGINAL_REVISION_NUM));
GitFileRevision current = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + yoursRevision(root)));
GitFileRevision last = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + theirsRevision(root)));
try {
try {
mergeData.ORIGINAL = original.getContent();
} catch (Exception ex) {
/// This could happen in case if rebasing.
try {
mergeData.ORIGINAL = file.contentsToByteArray();
} catch (IOException e) {
LOG.error(e);
mergeData.ORIGINAL = ArrayUtil.EMPTY_BYTE_ARRAY;
}
}
mergeData.CURRENT = loadRevisionCatchingErrors(current);
mergeData.LAST = loadRevisionCatchingErrors(last);
// TODO: can be done once for a root
mergeData.CURRENT_REVISION_NUMBER = findCurrentRevisionNumber(root);
mergeData.LAST_REVISION_NUMBER = findLastRevisionNumber(root);
mergeData.ORIGINAL_REVISION_NUMBER = findOriginalRevisionNumber(root, mergeData.CURRENT_REVISION_NUMBER, mergeData.LAST_REVISION_NUMBER);
Trinity<String, String, String> blobs = getAffectedBlobs(root, file);
mergeData.CURRENT_FILE_PATH = getBlobPathInRevision(root, file, blobs.getFirst(), mergeData.CURRENT_REVISION_NUMBER);
mergeData.ORIGINAL_FILE_PATH = getBlobPathInRevision(root, file, blobs.getSecond(), mergeData.ORIGINAL_REVISION_NUMBER);
mergeData.LAST_FILE_PATH = getBlobPathInRevision(root, file, blobs.getThird(), mergeData.LAST_REVISION_NUMBER);
} catch (IOException e) {
throw new IllegalStateException("Failed to load file content", e);
}
}
};
VcsUtil.runVcsProcessWithProgress(runnable, GitBundle.message("merge.load.files"), false, myProject);
return mergeData;
}
Aggregations