use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method testGetLastRevisionForExistingFile.
@Test(enabled = false)
public void testGetLastRevisionForExistingFile() throws Exception {
final ItemLatestState state = GitHistoryUtils.getLastRevision(myProject, toFilePath(bfile));
assertTrue(state.isItemExists());
final GitRevisionNumber revisionNumber = (GitRevisionNumber) state.getNumber();
assertEquals(revisionNumber.getRev(), myRevisions.get(0).myHash);
assertEquals(revisionNumber.getTimestamp(), myRevisions.get(0).myDate);
}
use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.
the class VcsHistoryProviderBackgroundableProxy method getSessionFromCacheWithLastRevisionCheck.
@Nullable
private VcsAbstractHistorySession getSessionFromCacheWithLastRevisionCheck(final FilePath filePath, final VcsKey vcsKey) {
final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
if (pi != null) {
pi.setText2("Checking last revision");
}
VcsAbstractHistorySession cached = getFullHistoryFromCache(vcsKey, filePath);
if (cached == null)
return null;
final FilePath correctedFilePath = ((VcsCacheableHistorySessionFactory<Serializable, VcsAbstractHistorySession>) myDelegate).getUsedFilePath(cached);
if (VcsType.distributed.equals(myType)) {
final FilePath path = correctedFilePath != null ? correctedFilePath : filePath;
VirtualFile virtualFile = path.getVirtualFile();
if (virtualFile == null) {
virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path.getPath());
}
if (virtualFile != null) {
final VcsRevisionNumber currentRevision = myDiffProvider.getCurrentRevision(virtualFile);
final List<VcsFileRevision> revisionList = cached.getRevisionList();
if (!revisionList.isEmpty() && revisionList.get(0).getRevisionNumber().equals(currentRevision)) {
return cached;
}
}
} else {
final ItemLatestState lastRevision = myDiffProvider.getLastRevision(correctedFilePath != null ? correctedFilePath : filePath);
if (lastRevision != null && !lastRevision.isDefaultHead() && lastRevision.isItemExists()) {
final List<VcsFileRevision> revisionList = cached.getRevisionList();
if (!revisionList.isEmpty() && revisionList.get(0).getRevisionNumber().equals(lastRevision.getNumber())) {
return cached;
}
}
}
return null;
}
use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.
the class CvsDiffProvider method getLastState.
private ItemLatestState getLastState(final VirtualFile parent, final String name) {
final Entry entry = CvsEntriesManager.getInstance().getEntryFor(parent, name);
if (entry == null)
return new ItemLatestState(new CvsRevisionNumber("HEAD"), true, true);
final String stickyHead = new StickyHeadGetter.MyStickyBranchHeadGetter(entry.getRevision(), myProject).getHead(parent, name);
if (stickyHead == null) {
return new ItemLatestState(new CvsRevisionNumber("HEAD"), true, true);
}
return new ItemLatestState(new CvsRevisionNumber(stickyHead), (!entry.isRemoved()), false);
}
use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method testGetLastRevisionForNonExistingFile.
public void testGetLastRevisionForNonExistingFile() throws Exception {
git("remote add origin git://example.com/repo.git");
git("config branch.master.remote origin");
git("config branch.master.merge refs/heads/master");
git("rm " + bfile.getPath());
commit("removed bfile");
String[] hashAndDate = log("--pretty=format:%H#%ct", "-n1").split("#");
// to avoid pushing to this fake origin
git("update-ref refs/remotes/origin/master HEAD");
touch("dir/b.txt", "content");
addCommit("recreated bfile");
refresh();
myRepo.update();
final ItemLatestState state = GitHistoryUtils.getLastRevision(myProject, toFilePath(bfile));
assertTrue(!state.isItemExists());
final GitRevisionNumber revisionNumber = (GitRevisionNumber) state.getNumber();
assertEquals(revisionNumber.getRev(), hashAndDate[0]);
assertEquals(revisionNumber.getTimestamp(), GitTestRevision.gitTimeStampToDate(hashAndDate[1]));
}
use of com.intellij.openapi.vcs.diff.ItemLatestState in project intellij-community by JetBrains.
the class GitHistoryUtils method getLastRevision.
/**
* Get current revision for the file under git
*
* @param project a project
* @param filePath a file path
* @return a revision number or null if the file is unversioned or new
* @throws VcsException if there is problem with running git
*/
@Nullable
public static ItemLatestState getLastRevision(@NotNull Project project, @NotNull FilePath filePath) throws VcsException {
VirtualFile root = GitUtil.getGitRoot(filePath);
GitBranch c = GitBranchUtil.getCurrentBranch(project, root);
GitBranch t = c == null ? null : GitBranchUtil.tracked(project, root, c.getName());
if (t == null) {
return new ItemLatestState(getCurrentRevision(project, filePath, null), true, false);
}
filePath = getLastCommitName(project, filePath);
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, HASH, COMMIT_TIME, PARENTS);
h.setSilent(true);
h.addParameters("-n1", parser.getPretty(), "--name-status", t.getFullName());
h.endOptions();
h.addRelativePaths(filePath);
String result = h.run();
if (result.length() == 0) {
return null;
}
GitLogRecord record = parser.parseOneRecord(result);
if (record == null) {
return null;
}
final List<Change> changes = record.parseChanges(project, root);
boolean exists = changes.isEmpty() || !FileStatus.DELETED.equals(changes.get(0).getFileStatus());
record.setUsedHandler(h);
return new ItemLatestState(new GitRevisionNumber(record.getHash(), record.getDate()), exists, false);
}
Aggregations