use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class SrcFileAnnotator method loadFromVersionControl.
@Nullable
private byte[] loadFromVersionControl(long date, VirtualFile f) {
try {
final AbstractVcs vcs = VcsUtil.getVcsFor(myProject, f);
if (vcs == null)
return null;
final VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
if (historyProvider == null)
return null;
final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(f);
final VcsHistorySession session = historyProvider.createSessionFor(filePath);
if (session == null)
return null;
final List<VcsFileRevision> list = session.getRevisionList();
if (list != null) {
for (VcsFileRevision revision : list) {
final Date revisionDate = revision.getRevisionDate();
if (revisionDate == null) {
return null;
}
if (revisionDate.getTime() < date) {
return revision.loadContent();
}
}
}
} catch (Exception e) {
LOG.info(e);
return null;
}
return null;
}
use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class MergeSourceDetailsAction method enabled.
private boolean enabled(final AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null)
return false;
final VirtualFile revisionVirtualFile = e.getData(VcsDataKeys.VCS_VIRTUAL_FILE);
if (revisionVirtualFile == null)
return false;
final VcsFileRevision revision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
if (revision == null)
return false;
if (!(revision instanceof SvnFileRevision))
return false;
return !((SvnFileRevision) revision).getMergeSources().isEmpty();
}
use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class GitCommittedChangeListProvider method getOneList.
@Override
public Pair<CommittedChangeList, FilePath> getOneList(final VirtualFile file, final VcsRevisionNumber number) throws VcsException {
FilePath filePath = VcsUtil.getFilePath(file);
final List<GitHeavyCommit> gitCommits = GitHistoryUtils.commitsDetails(myProject, filePath, new SymbolicRefs(), Collections.singletonList(number.asString()));
if (gitCommits.size() != 1) {
return null;
}
final GitHeavyCommit gitCommit = gitCommits.get(0);
CommittedChangeList commit = new GitCommittedChangeList(gitCommit.getDescription() + " (" + gitCommit.getShortHash().getString() + ")", gitCommit.getDescription(), gitCommit.getAuthor(), (GitRevisionNumber) number, new Date(gitCommit.getAuthorTime()), gitCommit.getChanges(), assertNotNull(GitVcs.getInstance(myProject)), true);
final Collection<Change> changes = commit.getChanges();
if (changes.size() == 1) {
Change change = changes.iterator().next();
return Pair.create(commit, ChangesUtil.getFilePath(change));
}
for (Change change : changes) {
if (change.getAfterRevision() != null && FileUtil.filesEqual(filePath.getIOFile(), change.getAfterRevision().getFile().getIOFile())) {
return Pair.create(commit, filePath);
}
}
final String afterTime = "--after=" + GitUtil.gitTime(gitCommit.getDate());
final List<VcsFileRevision> history = GitHistoryUtils.history(myProject, filePath, (VirtualFile) null, afterTime);
if (history.isEmpty()) {
return Pair.create(commit, filePath);
}
return Pair.create(commit, ((GitFileRevision) history.get(history.size() - 1)).getPath());
}
use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method testCyclicRename.
// Inspired by IDEA-89347
@Test
public void testCyclicRename() throws Exception {
List<TestCommit> commits = new ArrayList<>();
File source = mkdir("source");
File initialFile = touch("source/PostHighlightingPass.java", "Initial content");
String initMessage = "Created PostHighlightingPass.java in source";
addCommit(initMessage);
String hash = last();
commits.add(new TestCommit(hash, initMessage, initialFile.getPath()));
String filePath = initialFile.getPath();
commits.add(modify(filePath));
TestCommit commit = move(filePath, mkdir("codeInside-impl"), "Moved from source to codeInside-impl");
filePath = commit.myPath;
commits.add(commit);
commits.add(modify(filePath));
commit = move(filePath, mkdir("codeInside"), "Moved from codeInside-impl to codeInside");
filePath = commit.myPath;
commits.add(commit);
commits.add(modify(filePath));
commit = move(filePath, mkdir("lang-impl"), "Moved from codeInside to lang-impl");
filePath = commit.myPath;
commits.add(commit);
commits.add(modify(filePath));
commit = move(filePath, source, "Moved from lang-impl back to source");
filePath = commit.myPath;
commits.add(commit);
commits.add(modify(filePath));
commit = move(filePath, mkdir("java"), "Moved from source to java");
filePath = commit.myPath;
commits.add(commit);
commits.add(modify(filePath));
Collections.reverse(commits);
VirtualFile vFile = VcsUtil.getVirtualFileWithRefresh(new File(filePath));
assertNotNull(vFile);
List<VcsFileRevision> history = GitHistoryUtils.history(myProject, VcsUtil.getFilePath(vFile));
assertEquals("History size doesn't match. Actual history: \n" + toReadable(history), commits.size(), history.size());
assertEquals("History is different.", toReadable(commits), toReadable(history));
}
use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method toReadable.
@NotNull
private String toReadable(@NotNull Collection<VcsFileRevision> history) {
int maxSubjectLength = findMaxLength(history, new Function<VcsFileRevision, String>() {
@Override
public String fun(VcsFileRevision revision) {
return revision.getCommitMessage();
}
});
StringBuilder sb = new StringBuilder();
for (VcsFileRevision revision : history) {
GitFileRevision rev = (GitFileRevision) revision;
String relPath = FileUtil.getRelativePath(new File(myProjectPath), rev.getPath().getIOFile());
sb.append(String.format("%s %-" + maxSubjectLength + "s %s%n", getShortHash(rev.getHash()), rev.getCommitMessage(), relPath));
}
return sb.toString();
}
Aggregations